package admin_user import ( base_ctl "SCRM/controllers" "SCRM/enums" base_service "SCRM/service" "SCRM/service/admin_service" "SCRM/service/role_service" "github.com/astaxie/beego" ) func AdminCtlRegistRouters() { beego.Router("/api/password/code", &AdminController{}, "post:CodeOfModifyPwd") beego.Router("/api/password/modify", &AdminController{}, "post:ModifyPwd") beego.Router("/api/admin/edit_info", &AdminController{}, "post:EditAdminUserInfo") } type AdminController struct { base_ctl.BaseAuthAPIController } // /api/admin/edit_info [post] // @param avatar:string // @param name:string // @param opwd?:string 没有原始密码的时候,认为不修改密码 // @param npwd?:string func (this *AdminController) EditAdminUserInfo() { adminUserInfo := this.GetAdminUserInfo() avatar := this.GetString("avatar") name := this.GetString("name") if len(name) == 0 { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMissingUserName) return } modifyErr := role_service.ModifyAdminUserInfo(adminUserInfo.AdminUser.Id, adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, name, avatar, "") if modifyErr != nil { this.ErrorLog("修改个人信息失败:%v", modifyErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate) } else { appRole := adminUserInfo.AppRoles[adminUserInfo.CurrentAppId] appRole.UserName = name appRole.Avatar = avatar this.ServeSuccessJSON(nil) } } // /api/password/code [post] func (this *AdminController) CodeOfModifyPwd() { ////////////////////////////// // 待把 SMS 的 service 添加完再重新放开 ////////////////////////////// this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return // adminUserInfo := this.GetAdminUserInfo() // mobile := adminUserInfo.AdminUser.Mobile // if err := service.SMSSendVerificationCode(mobile); err != nil { // utils.ErrorLog("修改密码发送验证码失败:%v", err) // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return // } else { // this.ServeSuccessJSON(map[string]interface{}{ // "msg": "短信发送成功,有效期为10分钟", // }) // } } // /api/password/modify [post] // @param password:string // @param code:string func (this *AdminController) ModifyPwd() { new_pwd := this.GetString("password") code := this.GetString("code") if len(new_pwd) == 0 || len(code) == 0 { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminUserInfo := this.GetAdminUserInfo() mobile := adminUserInfo.AdminUser.Mobile redisClient := base_service.RedisClient() defer redisClient.Close() cachedCode, err := redisClient.Get("xt_modify_pwd_" + mobile).Result() if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrVerCodeWrong) return } if code != cachedCode { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrVerCodeWrong) return } if modifyErr := admin_service.ModifyPassword(adminUserInfo.AdminUser.Id, new_pwd); modifyErr != nil { this.ErrorLog("修改密码失败:%v", modifyErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } // 清除验证码 redisClient.Del("xt_modify_pwd_" + mobile) this.ServeSuccessJSON(map[string]interface{}{ "msg": "密码已修改", }) }