MCPcopy Index your code
hub / github.com/TruthHun/DocHub / Edit

Method Edit

controllers/HomeControllers/UserController.go:795–847  ·  view source on GitHub ↗

编辑个人信息

()

Source from the content-addressed store, hash-verified

793
794//编辑个人信息
795func (this *UserController) Edit() {
796 if this.IsLogin == 0 {
797 this.ResponseJson(false, "请先登录")
798 }
799 changepwd := false
800 cols := []string{"Intro"}
801 rules := map[string][]string{
802 "OldPassword": {"required"},
803 "NewPassword": {"required"},
804 "RePassword": {"required"},
805 "Intro": {"required"},
806 }
807 params, errs := helper.Valid(this.Ctx.Request.Form, rules)
808 if len(errs) > 0 {
809 this.ResponseJson(false, "参数不正确")
810 }
811 var user = models.User{Id: this.IsLogin}
812 orm.NewOrm().Read(&user)
813 if len(params["OldPassword"].(string)) > 0 || len(params["NewPassword"].(string)) > 0 || len(params["RePassword"].(string)) > 0 {
814 if len(params["NewPassword"].(string)) < 6 || len(params["RePassword"].(string)) < 6 {
815 this.ResponseJson(false, "密码长度必须至少6个字符")
816 }
817 opwd := helper.MD5Crypt(params["OldPassword"].(string))
818 npwd := helper.MD5Crypt(params["NewPassword"].(string))
819 rpwd := helper.MD5Crypt(params["RePassword"].(string))
820 if user.Password != opwd {
821 this.ResponseJson(false, "原密码不正确")
822 }
823 if npwd != rpwd {
824 this.ResponseJson(false, "确认密码和新密码必须一致")
825 }
826 if opwd == npwd {
827 this.ResponseJson(false, "确认密码不能与原密码相同")
828 }
829 user.Password = rpwd
830 cols = append(cols, "Password")
831 changepwd = true
832 }
833 user.Intro = params["Intro"].(string)
834 affected, err := orm.NewOrm().Update(&user, cols...)
835 if err != nil {
836 helper.Logger.Error(err.Error())
837 this.ResponseJson(false, "设置失败,请刷新页面重试")
838 }
839 if affected == 0 {
840 this.ResponseJson(true, "设置失败,可能您未对内容做更改")
841 }
842 if changepwd {
843 this.ResetCookie()
844 this.ResponseJson(true, "设置成功,您设置了新密码,请重新登录")
845 }
846 this.ResponseJson(true, "设置成功")
847}

Callers

nothing calls this directly

Calls 3

UpdateMethod · 0.80
ResetCookieMethod · 0.80
ResponseJsonMethod · 0.45

Tested by

no test coverage detected