// 给用户分配角色
func (this *UserController) AllocationRole() {
	Id, _ := this.GetInt64("Id")
	fmt.Printf("给用户分配角色 Id is %d\n", Id)
	err, user := m.IsExitUser(Id)
	roleByUser := m.GetRoleByUserId(Id)

	roles, _ := m.GetAllRole()
	if err != nil {
		this.Rsp(false, "不存在这个用户")
	} else {
		this.Data["User"] = &user
		roleList := make([]m.Role, len(roles))
		for k, role := range roles {
			roleList[k].Id = role["Id"].(int64)
			roleList[k].Name = role["Name"].(string)
			roleList[k].Key = role["Key"].(string)
			roleList[k].Description = role["Description"].(string)
			roleList[k].Status = role["Status"].(int64)
			if roleList[k].Status == 2 {
				roleList[k].Isnormal = true
			} else {
				roleList[k].Isnormal = false
			}

		}
		this.Data["RoleList"] = &roleList
		this.Data["UserRole"] = roleByUser.Name
		this.TplNames = "user/userRole.html"
	}
}
Ejemplo n.º 2
0
func (this *MainController) Left() {
	userInfo := this.GetSession("userinfo")
	if userInfo == nil {
		this.Ctx.Redirect(302, beego.AppConfig.String("auth_gateway"))
	} else {
		role := m.GetRoleByUserId(userInfo.(m.User).Id)
		tree := this.GetResList(userInfo.(m.User).Uname, role.Id)

		this.Data["tree"] = &tree
		this.Data["ActionUrl"] = beego.AppConfig.String("ActionUrl")
	}
	this.TplNames = "background/left.html"
}
Ejemplo n.º 3
0
func (this *MainController) Top() {
	userInfo := this.GetSession("userinfo")

	if userInfo == nil {
		this.Ctx.Redirect(302, beego.AppConfig.String("auth_gateway"))
	} else {
		role := m.GetRoleByUserId(userInfo.(m.User).Id)
		roleName := role.Name
		this.Data["userinfo"] = userInfo
		this.Data["roleName"] = roleName
	}
	this.TplNames = "background/top.html"
}
func (this *UserController) List() {
	// iLength - iStart  + 1
	if this.IsAjax() {
		fmt.Println("ajax is true")
		sEcho := this.GetString("sEcho")
		iDisplayStart := this.GetString("iDisplayStart")
		iDisplayLength := this.GetString("iDisplayLength")
		iStart, _ := strconv.Atoi(iDisplayStart)
		iLength, _ := strconv.Atoi(iDisplayLength)
		page := iStart / iLength
		count, _ := m.Users()
		users, _ := m.GetUserList(int64(page+1), int64(iLength), "Id")
		for _, user := range users {
			switch user["Status"] {
			case int64(2):
				user["Statusname"] = "正常"
			case int64(1):
				user["Statusname"] = "禁止"
			default:
				user["Statusname"] = "不正常"
			}

			role := m.GetRoleByUserId(user["Id"].(int64))
			user["Rolename"] = role.Name
		}

		data := make(map[string]interface{})
		data["aaData"] = users
		data["iTotalDisplayRecords"] = count
		data["iTotalRecords"] = iLength
		data["sEcho"] = sEcho
		this.Data["json"] = &data
		this.ServeJson()

	} else {
		this.Data["ActionUrl"] = "localhost:8080"
		this.TplNames = "user/index.html"
	}
}