Exemplo n.º 1
0
func NewRoleHandler(rw http.ResponseWriter, req *http.Request) {
	var data = make(map[string]interface{})

	if req.PostFormValue("submit") == "1" {
		user, _ := filter.CurrentUser(req)
		username := user["username"].(string)

		errMsg, err := service.SaveRole(req.PostForm, username)
		if err != nil {
			data["ok"] = 0
			data["error"] = errMsg
		} else {
			data["ok"] = 1
			data["msg"] = "添加成功"
		}
	} else {

		menu1, menu2 := service.GetMenus()
		menu3 := service.GeneralAuthorities()

		// 设置内容模板
		req.Form.Set(filter.CONTENT_TPL_KEY, "/template/admin/role/new.html")

		data["allmenu1"] = menu1
		data["allmenu2"] = menu2
		data["allmenu3"] = menu3
	}

	filter.SetData(req, data)
}
Exemplo n.º 2
0
func ModifyRoleHandler(rw http.ResponseWriter, req *http.Request) {
	var data = make(map[string]interface{})

	if req.PostFormValue("submit") == "1" {
		user, _ := filter.CurrentUser(req)
		username := user["username"].(string)

		errMsg, err := service.SaveRole(req.PostForm, username)
		if err != nil {
			data["ok"] = 0
			data["error"] = errMsg
		} else {
			data["ok"] = 1
			data["msg"] = "修改成功"
		}
	} else {
		role := service.FindRole(req.FormValue("roleid"))

		if role == nil || role.Roleid == 0 {
			rw.WriteHeader(http.StatusInternalServerError)
			return
		}

		menu1, menu2 := service.GetMenus()
		menu3 := service.GeneralAuthorities()

		// 设置内容模板
		req.Form.Set(filter.CONTENT_TPL_KEY, "/template/admin/role/modify.html")

		data["allmenu1"] = menu1
		data["allmenu2"] = menu2
		data["allmenu3"] = menu3
		data["role"] = role
		data["role_auth"] = service.RoleAuthorities[role.Roleid]
	}

	filter.SetData(req, data)
}