func (this *UserController) EditUserInfo() { currentUser := this.Ctx.Input.GetData("CurrentUser").(*User) email := strings.TrimSpace(this.GetString("email", "")) weChat := strings.TrimSpace(this.GetString("wechat", "")) phone := strings.TrimSpace(this.GetString("phone", "")) if email != "" && !utils.IsEmailVaild(email) { this.ServeErrJson("email is invalid") return } if utils.HasDangerousCharacters(weChat) { this.ServeErrJson("wechat is invalid") return } if phone != "" && !utils.IsPhoneVaild(phone) { this.ServeErrJson("phone is invalid") return } currentUser.Email = email currentUser.Wechat = weChat currentUser.Phone = phone err := currentUser.Update() if err != nil { this.ServeErrJson("update failed") return } this.ServeOKJson() }
func (this *UserController) UpdateUser() { username := strings.TrimSpace(this.GetString("username", "")) email := strings.TrimSpace(this.GetString("email", "")) weChat := strings.TrimSpace(this.GetString("wechat", "")) phone := strings.TrimSpace(this.GetString("phone", "")) pwd := strings.TrimSpace(this.GetString("password", "")) rPwd := strings.TrimSpace(this.GetString("repeat_password", "")) user, _ := GetUserByUsernmae(username) if pwd != "" || rPwd != "" { if pwd != rPwd { this.ServeErrJson("new password and its confirm not same") return } else { user.Password = utils.Md5Encode(pwd) } } if email != "" { if !utils.IsEmailVaild(email) { this.ServeErrJson("email address is invalid") return } } if phone != "" { if !utils.IsPhoneVaild(phone) { this.ServeErrJson("phone number is invalid") return } } user.Email = email user.Phone = phone user.Wechat = weChat err := user.Update() if err != nil { this.ServeErrJson("update user failed") return } this.ServeOKJson() }