Пример #1
0
func (c *User) Delete() {
	id := c.GetInput("id")
	muser := models.NewUserModel()
	affect, err := muser.Wherep(id).Delete()
	if err != nil {
		c.Json(-1, "操作失败", nil)
		return
	}
	c.Json(0, "操作成功", affect)
}
Пример #2
0
func (c *User) Add_post() {
	values := c.GetPosts([]string{"username", "email", "password", "r_password", "groupid"})
	remoteAddr := strings.Split(c.GetRequest().RemoteAddr, ":")
	values["registerip"] = remoteAddr[0]

	result, _ := models.NewUserModel().Where("username = ?", values["username"]).Get()
	if result["username"] != nil {
		c.Json(-1, "用户已经存在.", nil)
		return
	}

	user := models.NewUserModel()
	if code, msg := user.Valid(&values); code != 0 {
		c.Json(-1, msg, nil)
		return
	}
	user.Insert(values)
	c.Json(0, "操作成功", nil)
}
Пример #3
0
func (c *AdminBase) CheckLogin() {
	user := models.NewUserModel()
	cookieStr := c.GetCookie("Admin_User")
	dogo.Register.Set("Admin_User_Cookie", cookieStr)

	flag, info := user.IsLogin()
	if !flag {
		c.Redirect("/admin/login/index", nil)
	}
	c.UserInfo = info
	c.Assign("UserInfo", info)
}
Пример #4
0
func (c *User) Edit_post() {
	id := c.GetInput("id")
	values := c.GetPosts([]string{"email", "password", "r_password", "groupid"})
	user := models.NewUserModel()

	if code, msg := user.Valid(&values); code != 0 {
		c.Json(-1, msg, nil)
		return
	}
	user.Where("uid = ?", id).Update(values)
	c.Json(0, "操作成功", nil)
}
Пример #5
0
func (c *User) Edit() {
	id := c.GetInput("id")
	user := models.NewUserModel()

	auser, err := user.Wherep(id).Get()
	if err == nil {
		c.Assign("auser", auser)
	}
	//group list
	mgroup := models.NewGroupModel()
	groups, err := mgroup.Gets()
	if err == nil {
		c.Assign("groups", groups)
	}
}
Пример #6
0
func (c *User) Index() {
	user := models.NewUserModel()
	users, err := user.Gets()
	if err == nil {
		for _, user := range users {
			user["registertime"] = time.Unix(utils.ItoInt(user["registertime"]), 0).String()
			if utils.ItoInt(user["groupid"]) == 0 {
				user["groupname"] = "超级管理员"
			} else {
				user["groupname"] = c.getGroupName(utils.ItoByte(user["groupid"]))
			}
		}
		c.Assign("users", users)
	}

}
Пример #7
0
func (c *Login) Login() {
	values := c.GetInputs([]string{"username", "password"})

	user := models.NewUserModel()

	if code, _ := user.LoginValid(values); code != 0 {
		c.Redirect(fmt.Sprintf("/admin/errors/index?code=%d", code), nil)
	}

	// models.User.Login()
	code, msg := user.Login(values)

	if code != 0 {
		c.Redirect(fmt.Sprintf("/admin/errors/index?code=%d", code), nil)
	}
	c.SetCookie("Admin_User", msg, 60*60*24)
	c.Redirect("/admin/index/index", nil)
}
Пример #8
0
func (c *User) Passwd_post() {
	values := c.GetInputs([]string{"current_password", "password", "r_password"})

	user := models.NewUserModel()
	flag, msg := user.CheckPasswd(values["current_password"])
	if !flag {
		c.Json(-1, msg, nil)
		return
	}
	flag, password := user.Password(values["password"], utils.ItoString(c.UserInfo["hash"]))
	if !flag {
		c.Json(-1, "修改失败.", nil)
		return
	}
	data := map[string]string{"password": password}
	user.Wherep(c.UserInfo["uid"]).Update(data)
	c.Json(0, "修改成功.", nil)
}