12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- /**********************************************
- ** @Des: 用户
- ** @Author: haodaquan
- ** @Date: 2017-09-16 14:17:37
- ** @Last Modified by: haodaquan
- ** @Last Modified time: 2017-09-17 11:14:07
- ***********************************************/
- package backgroundc
- import (
- "strings"
- "time"
- "wuyebaoxiuapi/utils"
- "strconv"
- "wuyebaoxiuapi/libs"
- "wuyebaoxiuapi/models/backgroundm"
- cache "github.com/patrickmn/go-cache"
- )
- type UserController struct {
- BaseController
- }
- func (self *UserController) Edit() {
- self.Data["pageTitle"] = "资料修改"
- id := self.userId
- Admin, _ := backgroundm.AdminGetById(id)
- row := make(map[string]interface{})
- row["id"] = Admin.Id
- row["login_name"] = Admin.LoginName
- row["real_name"] = Admin.RealName
- row["phone"] = Admin.Phone
- row["email"] = Admin.Email
- self.Data["admin"] = row
- utils.Che.Set("uid"+strconv.Itoa(self.user.Id), nil, cache.DefaultExpiration)
- self.display()
- }
- func (self *UserController) AjaxSave() {
- Admin_id, _ := self.GetInt("id")
- Admin, _ := backgroundm.AdminGetById(Admin_id)
- //修改
- Admin.Id = Admin_id
- Admin.UpdateTime = time.Now().Unix()
- Admin.UpdateId = self.userId
- Admin.LoginName = strings.TrimSpace(self.GetString("login_name"))
- Admin.RealName = strings.TrimSpace(self.GetString("real_name"))
- Admin.Phone = strings.TrimSpace(self.GetString("phone"))
- Admin.Email = strings.TrimSpace(self.GetString("email"))
- resetPwd := self.GetString("reset_pwd")
- if resetPwd == "1" {
- pwdOld := strings.TrimSpace(self.GetString("password_old"))
- pwdOldMd5 := libs.Md5([]byte(pwdOld + Admin.Salt))
- if Admin.Password != pwdOldMd5 {
- self.ajaxMsg("旧密码错误", MSG_ERR)
- }
- pwdNew1 := strings.TrimSpace(self.GetString("password_new1"))
- pwdNew2 := strings.TrimSpace(self.GetString("password_new2"))
- if pwdNew1 != pwdNew2 {
- self.ajaxMsg("两次密码不一致", MSG_ERR)
- }
- pwd, salt := libs.Password(4, pwdNew1)
- Admin.Password = pwd
- Admin.Salt = salt
- }
- Admin.UpdateTime = time.Now().Unix()
- Admin.UpdateId = self.userId
- Admin.Status = 1
- if err := Admin.Update(); err != nil {
- self.ajaxMsg(err.Error(), MSG_ERR)
- }
- self.ajaxMsg("", MSG_OK)
- }
|