Exemplo n.º 1
0
//用户 角色分配修改
func UserRoleEdit(r render.Render, req *http.Request) {
	req.ParseForm()
	values := req.Form
	var err error
	data := make(map[string]interface{})
	data["ret"] = 1
	userIdStr := values.Get("user_id")
	roleIdStr := values.Get("role_id")
	if userIdStr == "" || roleIdStr == "" {
		service.Logs.Error("args err")
		r.JSON(200, data)
		return
	}
	userIdInt, err := strconv.ParseInt(userIdStr, 10, 64)
	if err != nil {
		service.Logs.Error("strconv.ParseInt err(%v)", err)
		r.JSON(200, data)
		return
	}
	roleIdInt, err := strconv.ParseInt(roleIdStr, 10, 64)
	if err != nil {
		service.Logs.Error("strconv.ParseInt err(%v)", err)
		r.JSON(200, data)
		return
	}
	err = service.EditUserRole(userIdInt, roleIdInt)
	if err != nil {
		data["ret"] = 1
		r.JSON(200, data)
		return
	}
	data["ret"] = 0
	r.JSON(200, data)
	return
}
Exemplo n.º 2
0
//管理后台修改用户
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
}