示例#1
0
文件: api.go 项目: go-galaxy/galaxy
func EditUser(id int64, name, info string, status int, pass string) (err error) {
	m, err := dao.GetUserById(id)
	if err != nil {
		Logs.Error("dao.GetUserById err(%v)", err)
		return
	}
	m.Name = name
	m.Info = info
	m.Status = status
	err = dao.UpdateUserById(m)
	return
}
示例#2
0
文件: admin.go 项目: go-galaxy/galaxy
//管理后台修改用户
func UserEdit(r render.Render, req *http.Request) {
	req.ParseForm()
	values := req.Form
	id := values.Get("id")
	var idInt64 int64
	var err error
	m := &model.User{}
	data := make(map[string]interface{})
	l, err := dao.GetAllRole()
	if err != nil {
		service.Logs.Error("dao.GetAllRole() err(%v)", err)
		return
	}
	data["l"] = l

	if id == "" {
		service.Logs.Error("id==null)")
		return
	}

	idInt64, err = strconv.ParseInt(id, 10, 64)
	if err != nil {
		service.Logs.Error("strconv.ParseInt err(%v)", err)
		return
	}

	rs, err := dao.GetAllRole()
	if err != nil {
		service.Logs.Error("dao.GetAllUser() err(%v)", err)
		return
	}
	data["roleList"] = rs

	if req.Method == "GET" {
		m, err = dao.GetUserById(idInt64)
		if err != nil {
			service.Logs.Error("dao.GetRoleById err(%v)", err)
			return
		}
		data["m"] = m
		r.HTML(200, "user_edit", data)
		return
	}
	m.Account = values.Get("account")
	m.Info = values.Get("info")
	m.Name = values.Get("name")
	m.Id = idInt64
	status, _ := strconv.Atoi(values.Get("status"))
	m.Status = status
	roleId := values.Get("role_id")
	roleIdInt, _ := strconv.Atoi(roleId)

	//更新用户角色
	err = service.EditUserRole(m.Id, int64(roleIdInt))
	if err != nil {
		service.Logs.Error("service.EditUserRole err(%v)", err)
		return
	}

	//更新用户
	err = dao.UpdateUserById(m)
	if err != nil {
		service.Logs.Error("dao.UpdateUserById err(%v)", err)
		return
	}
	data["m"] = m
	r.HTML(200, "user_edit", data)
	return
}