123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- package frontc
- import (
- "wuyebaoxiuapi/libs"
- "wuyebaoxiuapi/models/backgroundm"
- )
- type UserController struct {
- BaseController
- }
- // 用户信息
- func (this *UserController)Info() {
- this.Prepare()
- this.Data["json"] = map[string]interface{}{"code": 1, "message": "","data":this.userInfo}
- }
- // 修改密码
- func (this *UserController)UpdatePassword() {
- this.Prepare()
- user := new(backgroundm.Admin)
- userInfo := this.userInfo
- oldPassword := this.GetString("old_password") // 原密码
- newPassword := this.GetString("new_password") // 新密码
- confirmPassword := this.GetString("confirm_password") // 确认密码
- if oldPassword == "" {
- this.ajaxMsg(MSG_ERR,"请输入原密码",nil)
- }
- md5Password := libs.Md5([]byte(oldPassword+userInfo.Salt))
- if md5Password != userInfo.Password{
- this.ajaxMsg(MSG_ERR,"原密码输入错误",nil)
- }
- if newPassword == "" {
- this.ajaxMsg(MSG_ERR,"请输入新密码",nil)
- }
- if oldPassword == newPassword {
- this.ajaxMsg(MSG_ERR,"原密码与新密码不能一致",nil)
- }
- if confirmPassword == "" {
- this.ajaxMsg(MSG_ERR,"请输入确认密码",nil)
- }
- if newPassword != confirmPassword{
- this.ajaxMsg(MSG_ERR,"两次输入的密码,不一致",nil)
- }
- user.Id = userInfo.Id
- user.Salt = libs.GetRandomString(4)
- user.Password = libs.Md5([]byte(newPassword+user.Salt))
- if err := user.UpdatePassword(); err != nil {
- this.ajaxMsg(MSG_ERR,"系统繁忙,请稍后再试",nil)
- }
- this.ajaxMsg(MSG_OK,"密码修改成功",nil)
- }
- // 修改头像
- func (this *UserController)UpdateAvatarUrl() {
- this.Prepare()
- user := new(backgroundm.Admin)
- avatarUrl := this.GetString("avatar_url")
- user.Id = this.userInfo.Id
- user.AvatarUrl = avatarUrl
- if user.AvatarUrl == "" {
- this.ajaxMsg(MSG_ERR,"请上传头像",nil)
- }
- if err := user.Update(); err != nil {
- this.ajaxMsg(MSG_ERR,"系统繁忙,请稍后再试",nil)
- }
- data := make(map[string]interface{})
- data["image"] = avatarUrl
- data["types"] = 1
- this.addPicture(data)
- this.ajaxMsg(MSG_OK,"头像修改成功",nil)
- }
- // 修改学校
- func (this *UserController)UpdateSchool() {
- this.Prepare()
- user := new(backgroundm.Admin)
- school := this.GetString("school")
- user.Id = this.userInfo.Id
- user.School = school
- if user.School == "" {
- this.ajaxMsg(MSG_ERR,"请填写学校",nil)
- }
- if err := user.Update(); err != nil {
- this.ajaxMsg(MSG_ERR,"系统繁忙,请稍后再试",nil)
- }
- this.ajaxMsg(MSG_OK,"学校修改成功",nil)
- }
- // 修改日常地址
- func (this *UserController)UpdateDailyAddress() {
- this.Prepare()
- user := new(backgroundm.Admin)
- dailyAddress := this.GetString("daily_address")
- user.Id = this.userInfo.Id
- user.DailyAddress = dailyAddress
- if user.DailyAddress == "" {
- this.ajaxMsg(MSG_ERR,"请填写日常地址",nil)
- }
- if err := user.Update(); err != nil {
- this.ajaxMsg(MSG_ERR,"系统繁忙,请稍后再试",nil)
- }
- this.ajaxMsg(MSG_OK,"日常地址修改成功",nil)
- }
- // 修改手机号码
- func (this *UserController)UpdatepPhone() {
- this.Prepare()
- user := new(backgroundm.Admin)
- phone := this.GetString("phone")
- //if false == libs.Validate().IsPhone(phone){
- // this.ajaxMsg(MSG_ERR,"请输入正确的手机号码",nil)
- //}
- user.Id = this.userInfo.Id
- user.Phone = phone
- if err := user.Update(); err != nil {
- this.ajaxMsg(MSG_ERR,"系统繁忙,请稍后再试",nil)
- }
- this.ajaxMsg(MSG_OK,"手机号码修改成功",nil)
- }
|