user.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**********************************************
  2. ** @Des: 用户
  3. ** @Author: haodaquan
  4. ** @Date: 2017-09-16 14:17:37
  5. ** @Last Modified by: haodaquan
  6. ** @Last Modified time: 2017-09-17 11:14:07
  7. ***********************************************/
  8. package backgroundc
  9. import (
  10. "strings"
  11. "time"
  12. "wuyebaoxiuapi/utils"
  13. "strconv"
  14. "wuyebaoxiuapi/libs"
  15. "wuyebaoxiuapi/models/backgroundm"
  16. cache "github.com/patrickmn/go-cache"
  17. )
  18. type UserController struct {
  19. BaseController
  20. }
  21. func (self *UserController) Edit() {
  22. self.Data["pageTitle"] = "资料修改"
  23. id := self.userId
  24. Admin, _ := backgroundm.AdminGetById(id)
  25. row := make(map[string]interface{})
  26. row["id"] = Admin.Id
  27. row["login_name"] = Admin.LoginName
  28. row["real_name"] = Admin.RealName
  29. row["phone"] = Admin.Phone
  30. row["email"] = Admin.Email
  31. self.Data["admin"] = row
  32. utils.Che.Set("uid"+strconv.Itoa(self.user.Id), nil, cache.DefaultExpiration)
  33. self.display()
  34. }
  35. func (self *UserController) AjaxSave() {
  36. Admin_id, _ := self.GetInt("id")
  37. Admin, _ := backgroundm.AdminGetById(Admin_id)
  38. //修改
  39. Admin.Id = Admin_id
  40. Admin.UpdateTime = time.Now().Unix()
  41. Admin.UpdateId = self.userId
  42. Admin.LoginName = strings.TrimSpace(self.GetString("login_name"))
  43. Admin.RealName = strings.TrimSpace(self.GetString("real_name"))
  44. Admin.Phone = strings.TrimSpace(self.GetString("phone"))
  45. Admin.Email = strings.TrimSpace(self.GetString("email"))
  46. resetPwd := self.GetString("reset_pwd")
  47. if resetPwd == "1" {
  48. pwdOld := strings.TrimSpace(self.GetString("password_old"))
  49. pwdOldMd5 := libs.Md5([]byte(pwdOld + Admin.Salt))
  50. if Admin.Password != pwdOldMd5 {
  51. self.ajaxMsg("旧密码错误", MSG_ERR)
  52. }
  53. pwdNew1 := strings.TrimSpace(self.GetString("password_new1"))
  54. pwdNew2 := strings.TrimSpace(self.GetString("password_new2"))
  55. if pwdNew1 != pwdNew2 {
  56. self.ajaxMsg("两次密码不一致", MSG_ERR)
  57. }
  58. pwd, salt := libs.Password(4, pwdNew1)
  59. Admin.Password = pwd
  60. Admin.Salt = salt
  61. }
  62. Admin.UpdateTime = time.Now().Unix()
  63. Admin.UpdateId = self.userId
  64. Admin.Status = 1
  65. if err := Admin.Update(); err != nil {
  66. self.ajaxMsg(err.Error(), MSG_ERR)
  67. }
  68. self.ajaxMsg("", MSG_OK)
  69. }