user.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package frontc
  2. import (
  3. "wuyebaoxiuapi/libs"
  4. "wuyebaoxiuapi/models/backgroundm"
  5. )
  6. type UserController struct {
  7. BaseController
  8. }
  9. // 用户信息
  10. func (this *UserController)Info() {
  11. this.Prepare()
  12. this.Data["json"] = map[string]interface{}{"code": 1, "message": "","data":this.userInfo}
  13. }
  14. // 修改密码
  15. func (this *UserController)UpdatePassword() {
  16. this.Prepare()
  17. user := new(backgroundm.Admin)
  18. userInfo := this.userInfo
  19. oldPassword := this.GetString("old_password") // 原密码
  20. newPassword := this.GetString("new_password") // 新密码
  21. confirmPassword := this.GetString("confirm_password") // 确认密码
  22. if oldPassword == "" {
  23. this.ajaxMsg(MSG_ERR,"请输入原密码",nil)
  24. }
  25. md5Password := libs.Md5([]byte(oldPassword+userInfo.Salt))
  26. if md5Password != userInfo.Password{
  27. this.ajaxMsg(MSG_ERR,"原密码输入错误",nil)
  28. }
  29. if newPassword == "" {
  30. this.ajaxMsg(MSG_ERR,"请输入新密码",nil)
  31. }
  32. if oldPassword == newPassword {
  33. this.ajaxMsg(MSG_ERR,"原密码与新密码不能一致",nil)
  34. }
  35. if confirmPassword == "" {
  36. this.ajaxMsg(MSG_ERR,"请输入确认密码",nil)
  37. }
  38. if newPassword != confirmPassword{
  39. this.ajaxMsg(MSG_ERR,"两次输入的密码,不一致",nil)
  40. }
  41. user.Id = userInfo.Id
  42. user.Salt = libs.GetRandomString(4)
  43. user.Password = libs.Md5([]byte(newPassword+user.Salt))
  44. if err := user.UpdatePassword(); err != nil {
  45. this.ajaxMsg(MSG_ERR,"系统繁忙,请稍后再试",nil)
  46. }
  47. this.ajaxMsg(MSG_OK,"密码修改成功",nil)
  48. }
  49. // 修改头像
  50. func (this *UserController)UpdateAvatarUrl() {
  51. this.Prepare()
  52. user := new(backgroundm.Admin)
  53. avatarUrl := this.GetString("avatar_url")
  54. user.Id = this.userInfo.Id
  55. user.AvatarUrl = avatarUrl
  56. if user.AvatarUrl == "" {
  57. this.ajaxMsg(MSG_ERR,"请上传头像",nil)
  58. }
  59. if err := user.Update(); err != nil {
  60. this.ajaxMsg(MSG_ERR,"系统繁忙,请稍后再试",nil)
  61. }
  62. data := make(map[string]interface{})
  63. data["image"] = avatarUrl
  64. data["types"] = 1
  65. this.addPicture(data)
  66. this.ajaxMsg(MSG_OK,"头像修改成功",nil)
  67. }
  68. // 修改学校
  69. func (this *UserController)UpdateSchool() {
  70. this.Prepare()
  71. user := new(backgroundm.Admin)
  72. school := this.GetString("school")
  73. user.Id = this.userInfo.Id
  74. user.School = school
  75. if user.School == "" {
  76. this.ajaxMsg(MSG_ERR,"请填写学校",nil)
  77. }
  78. if err := user.Update(); err != nil {
  79. this.ajaxMsg(MSG_ERR,"系统繁忙,请稍后再试",nil)
  80. }
  81. this.ajaxMsg(MSG_OK,"学校修改成功",nil)
  82. }
  83. // 修改日常地址
  84. func (this *UserController)UpdateDailyAddress() {
  85. this.Prepare()
  86. user := new(backgroundm.Admin)
  87. dailyAddress := this.GetString("daily_address")
  88. user.Id = this.userInfo.Id
  89. user.DailyAddress = dailyAddress
  90. if user.DailyAddress == "" {
  91. this.ajaxMsg(MSG_ERR,"请填写日常地址",nil)
  92. }
  93. if err := user.Update(); err != nil {
  94. this.ajaxMsg(MSG_ERR,"系统繁忙,请稍后再试",nil)
  95. }
  96. this.ajaxMsg(MSG_OK,"日常地址修改成功",nil)
  97. }
  98. // 修改手机号码
  99. func (this *UserController)UpdatepPhone() {
  100. this.Prepare()
  101. user := new(backgroundm.Admin)
  102. phone := this.GetString("phone")
  103. //if false == libs.Validate().IsPhone(phone){
  104. // this.ajaxMsg(MSG_ERR,"请输入正确的手机号码",nil)
  105. //}
  106. user.Id = this.userInfo.Id
  107. user.Phone = phone
  108. if err := user.Update(); err != nil {
  109. this.ajaxMsg(MSG_ERR,"系统繁忙,请稍后再试",nil)
  110. }
  111. this.ajaxMsg(MSG_OK,"手机号码修改成功",nil)
  112. }