* Fixed: c.ShouldBindXXX 未错误处理 #1224 - api层错误处理以及代码格式统一化 * Update: 代码生成器 api.go ShouldBindXxx 错误处理
This commit is contained in:
@@ -16,38 +16,44 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// @Tags Base
|
||||
// @Summary 用户登录
|
||||
// @Produce application/json
|
||||
// @Param data body systemReq.Login true "用户名, 密码, 验证码"
|
||||
// @Success 200 {object} response.Response{data=systemRes.LoginResponse,msg=string} "返回包括用户信息,token,过期时间"
|
||||
// @Router /base/login [post]
|
||||
// Login
|
||||
// @Tags Base
|
||||
// @Summary 用户登录
|
||||
// @Produce application/json
|
||||
// @Param data body systemReq.Login true "用户名, 密码, 验证码"
|
||||
// @Success 200 {object} response.Response{data=systemRes.LoginResponse,msg=string} "返回包括用户信息,token,过期时间"
|
||||
// @Router /base/login [post]
|
||||
func (b *BaseApi) Login(c *gin.Context) {
|
||||
var l systemReq.Login
|
||||
_ = c.ShouldBindJSON(&l)
|
||||
if err := utils.Verify(l, utils.LoginVerify); err != nil {
|
||||
err := c.ShouldBindJSON(&l)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = utils.Verify(l, utils.LoginVerify)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if store.Verify(l.CaptchaId, l.Captcha, true) {
|
||||
u := &system.SysUser{Username: l.Username, Password: l.Password}
|
||||
if user, err := userService.Login(u); err != nil {
|
||||
user, err := userService.Login(u)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("登陆失败! 用户名不存在或者密码错误!", zap.Error(err))
|
||||
response.FailWithMessage("用户名不存在或者密码错误", c)
|
||||
} else {
|
||||
if user.Enable != 1 {
|
||||
global.GVA_LOG.Error("登陆失败! 用户被禁止登录!")
|
||||
response.FailWithMessage("用户被禁止登录", c)
|
||||
return
|
||||
}
|
||||
b.TokenNext(c, *user)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
response.FailWithMessage("验证码错误", c)
|
||||
if user.Enable != 1 {
|
||||
global.GVA_LOG.Error("登陆失败! 用户被禁止登录!")
|
||||
response.FailWithMessage("用户被禁止登录", c)
|
||||
return
|
||||
}
|
||||
b.TokenNext(c, *user)
|
||||
}
|
||||
response.FailWithMessage("验证码错误", c)
|
||||
}
|
||||
|
||||
// 登录以后签发jwt
|
||||
// TokenNext 登录以后签发jwt
|
||||
func (b *BaseApi) TokenNext(c *gin.Context, user system.SysUser) {
|
||||
j := &utils.JWT{SigningKey: []byte(global.GVA_CONFIG.JWT.SigningKey)} // 唯一签名
|
||||
claims := j.CreateClaims(systemReq.BaseClaims{
|
||||
@@ -105,16 +111,22 @@ func (b *BaseApi) TokenNext(c *gin.Context, user system.SysUser) {
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags SysUser
|
||||
// @Summary 用户注册账号
|
||||
// @Produce application/json
|
||||
// @Param data body systemReq.Register true "用户名, 昵称, 密码, 角色ID"
|
||||
// @Success 200 {object} response.Response{data=systemRes.SysUserResponse,msg=string} "用户注册账号,返回包括用户信息"
|
||||
// @Router /user/admin_register [post]
|
||||
// Register
|
||||
// @Tags SysUser
|
||||
// @Summary 用户注册账号
|
||||
// @Produce application/json
|
||||
// @Param data body systemReq.Register true "用户名, 昵称, 密码, 角色ID"
|
||||
// @Success 200 {object} response.Response{data=systemRes.SysUserResponse,msg=string} "用户注册账号,返回包括用户信息"
|
||||
// @Router /user/admin_register [post]
|
||||
func (b *BaseApi) Register(c *gin.Context) {
|
||||
var r systemReq.Register
|
||||
_ = c.ShouldBindJSON(&r)
|
||||
if err := utils.Verify(r, utils.RegisterVerify); err != nil {
|
||||
err := c.ShouldBindJSON(&r)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = utils.Verify(r, utils.RegisterVerify)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
@@ -129,129 +141,161 @@ func (b *BaseApi) Register(c *gin.Context) {
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("注册失败!", zap.Error(err))
|
||||
response.FailWithDetailed(systemRes.SysUserResponse{User: userReturn}, "注册失败", c)
|
||||
} else {
|
||||
response.OkWithDetailed(systemRes.SysUserResponse{User: userReturn}, "注册成功", c)
|
||||
return
|
||||
}
|
||||
response.OkWithDetailed(systemRes.SysUserResponse{User: userReturn}, "注册成功", c)
|
||||
}
|
||||
|
||||
// @Tags SysUser
|
||||
// @Summary 用户修改密码
|
||||
// @Security ApiKeyAuth
|
||||
// ChangePassword
|
||||
// @Tags SysUser
|
||||
// @Summary 用户修改密码
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Param data body systemReq.ChangePasswordReq true "用户名, 原密码, 新密码"
|
||||
// @Success 200 {object} response.Response{msg=string} "用户修改密码"
|
||||
// @Router /user/changePassword [post]
|
||||
// @Param data body systemReq.ChangePasswordReq true "用户名, 原密码, 新密码"
|
||||
// @Success 200 {object} response.Response{msg=string} "用户修改密码"
|
||||
// @Router /user/changePassword [post]
|
||||
func (b *BaseApi) ChangePassword(c *gin.Context) {
|
||||
var req systemReq.ChangePasswordReq
|
||||
_ = c.ShouldBindJSON(&req)
|
||||
if err := utils.Verify(req, utils.ChangePasswordVerify); err != nil {
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = utils.Verify(req, utils.ChangePasswordVerify)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
uid := utils.GetUserID(c)
|
||||
u := &system.SysUser{GVA_MODEL: global.GVA_MODEL{ID: uid}, Password: req.Password}
|
||||
if _, err := userService.ChangePassword(u, req.NewPassword); err != nil {
|
||||
_, err = userService.ChangePassword(u, req.NewPassword)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("修改失败!", zap.Error(err))
|
||||
response.FailWithMessage("修改失败,原密码与当前账户不符", c)
|
||||
} else {
|
||||
response.OkWithMessage("修改成功", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("修改成功", c)
|
||||
}
|
||||
|
||||
// @Tags SysUser
|
||||
// @Summary 分页获取用户列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.PageInfo true "页码, 每页大小"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取用户列表,返回包括列表,总数,页码,每页数量"
|
||||
// @Router /user/getUserList [post]
|
||||
// GetUserList
|
||||
// GetUserList
|
||||
// @Tags SysUser
|
||||
// @Summary 分页获取用户列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.PageInfo true "页码, 每页大小"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取用户列表,返回包括列表,总数,页码,每页数量"
|
||||
// @Router /user/getUserList [post]
|
||||
func (b *BaseApi) GetUserList(c *gin.Context) {
|
||||
var pageInfo request.PageInfo
|
||||
_ = c.ShouldBindJSON(&pageInfo)
|
||||
if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil {
|
||||
err := c.ShouldBindJSON(&pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if list, total, err := userService.GetUserInfoList(pageInfo); err != nil {
|
||||
err = utils.Verify(pageInfo, utils.PageInfoVerify)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
list, total, err := userService.GetUserInfoList(pageInfo)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
} else {
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, "获取成功", c)
|
||||
return
|
||||
}
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, "获取成功", c)
|
||||
}
|
||||
|
||||
// @Tags SysUser
|
||||
// @Summary 更改用户权限
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body systemReq.SetUserAuth true "用户UUID, 角色ID"
|
||||
// @Success 200 {object} response.Response{msg=string} "设置用户权限"
|
||||
// @Router /user/setUserAuthority [post]
|
||||
// SetUserAuthority
|
||||
// @Tags SysUser
|
||||
// @Summary 更改用户权限
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body systemReq.SetUserAuth true "用户UUID, 角色ID"
|
||||
// @Success 200 {object} response.Response{msg=string} "设置用户权限"
|
||||
// @Router /user/setUserAuthority [post]
|
||||
func (b *BaseApi) SetUserAuthority(c *gin.Context) {
|
||||
var sua systemReq.SetUserAuth
|
||||
_ = c.ShouldBindJSON(&sua)
|
||||
err := c.ShouldBindJSON(&sua)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if UserVerifyErr := utils.Verify(sua, utils.SetUserAuthorityVerify); UserVerifyErr != nil {
|
||||
response.FailWithMessage(UserVerifyErr.Error(), c)
|
||||
return
|
||||
}
|
||||
userID := utils.GetUserID(c)
|
||||
if err := userService.SetUserAuthority(userID, sua.AuthorityId); err != nil {
|
||||
err = userService.SetUserAuthority(userID, sua.AuthorityId)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("修改失败!", zap.Error(err))
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
claims := utils.GetUserInfo(c)
|
||||
j := &utils.JWT{SigningKey: []byte(global.GVA_CONFIG.JWT.SigningKey)} // 唯一签名
|
||||
claims.AuthorityId = sua.AuthorityId
|
||||
if token, err := j.CreateToken(*claims); err != nil {
|
||||
global.GVA_LOG.Error("修改失败!", zap.Error(err))
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
} else {
|
||||
claims := utils.GetUserInfo(c)
|
||||
j := &utils.JWT{SigningKey: []byte(global.GVA_CONFIG.JWT.SigningKey)} // 唯一签名
|
||||
claims.AuthorityId = sua.AuthorityId
|
||||
if token, err := j.CreateToken(*claims); err != nil {
|
||||
global.GVA_LOG.Error("修改失败!", zap.Error(err))
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
} else {
|
||||
c.Header("new-token", token)
|
||||
c.Header("new-expires-at", strconv.FormatInt(claims.ExpiresAt, 10))
|
||||
response.OkWithMessage("修改成功", c)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags SysUser
|
||||
// @Summary 设置用户权限
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body systemReq.SetUserAuthorities true "用户UUID, 角色ID"
|
||||
// @Success 200 {object} response.Response{msg=string} "设置用户权限"
|
||||
// @Router /user/setUserAuthorities [post]
|
||||
func (b *BaseApi) SetUserAuthorities(c *gin.Context) {
|
||||
var sua systemReq.SetUserAuthorities
|
||||
_ = c.ShouldBindJSON(&sua)
|
||||
if err := userService.SetUserAuthorities(sua.ID, sua.AuthorityIds); err != nil {
|
||||
global.GVA_LOG.Error("修改失败!", zap.Error(err))
|
||||
response.FailWithMessage("修改失败", c)
|
||||
} else {
|
||||
c.Header("new-token", token)
|
||||
c.Header("new-expires-at", strconv.FormatInt(claims.ExpiresAt, 10))
|
||||
response.OkWithMessage("修改成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags SysUser
|
||||
// @Summary 删除用户
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.GetById true "用户ID"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除用户"
|
||||
// @Router /user/deleteUser [delete]
|
||||
// SetUserAuthorities
|
||||
// @Tags SysUser
|
||||
// @Summary 设置用户权限
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body systemReq.SetUserAuthorities true "用户UUID, 角色ID"
|
||||
// @Success 200 {object} response.Response{msg=string} "设置用户权限"
|
||||
// @Router /user/setUserAuthorities [post]
|
||||
func (b *BaseApi) SetUserAuthorities(c *gin.Context) {
|
||||
var sua systemReq.SetUserAuthorities
|
||||
err := c.ShouldBindJSON(&sua)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = userService.SetUserAuthorities(sua.ID, sua.AuthorityIds)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("修改失败!", zap.Error(err))
|
||||
response.FailWithMessage("修改失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("修改成功", c)
|
||||
}
|
||||
|
||||
// DeleteUser
|
||||
// @Tags SysUser
|
||||
// @Summary 删除用户
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.GetById true "用户ID"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除用户"
|
||||
// @Router /user/deleteUser [delete]
|
||||
func (b *BaseApi) DeleteUser(c *gin.Context) {
|
||||
var reqId request.GetById
|
||||
_ = c.ShouldBindJSON(&reqId)
|
||||
if err := utils.Verify(reqId, utils.IdVerify); err != nil {
|
||||
err := c.ShouldBindJSON(&reqId)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = utils.Verify(reqId, utils.IdVerify)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
@@ -260,40 +304,46 @@ func (b *BaseApi) DeleteUser(c *gin.Context) {
|
||||
response.FailWithMessage("删除失败, 自杀失败", c)
|
||||
return
|
||||
}
|
||||
if err := userService.DeleteUser(reqId.ID); err != nil {
|
||||
err = userService.DeleteUser(reqId.ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("删除失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// @Tags SysUser
|
||||
// @Summary 设置用户信息
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body system.SysUser true "ID, 用户名, 昵称, 头像链接"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "设置用户信息"
|
||||
// @Router /user/setUserInfo [put]
|
||||
// SetUserInfo
|
||||
// @Tags SysUser
|
||||
// @Summary 设置用户信息
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body system.SysUser true "ID, 用户名, 昵称, 头像链接"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "设置用户信息"
|
||||
// @Router /user/setUserInfo [put]
|
||||
func (b *BaseApi) SetUserInfo(c *gin.Context) {
|
||||
var user systemReq.ChangeUserInfo
|
||||
_ = c.ShouldBindJSON(&user)
|
||||
if err := utils.Verify(user, utils.IdVerify); err != nil {
|
||||
err := c.ShouldBindJSON(&user)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = utils.Verify(user, utils.IdVerify)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if len(user.AuthorityIds) != 0 {
|
||||
err := userService.SetUserAuthorities(user.ID, user.AuthorityIds)
|
||||
err = userService.SetUserAuthorities(user.ID, user.AuthorityIds)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("设置失败!", zap.Error(err))
|
||||
response.FailWithMessage("设置失败", c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err := userService.SetUserInfo(system.SysUser{
|
||||
err = userService.SetUserInfo(system.SysUser{
|
||||
GVA_MODEL: global.GVA_MODEL{
|
||||
ID: user.ID,
|
||||
},
|
||||
@@ -303,27 +353,33 @@ func (b *BaseApi) SetUserInfo(c *gin.Context) {
|
||||
Email: user.Email,
|
||||
SideMode: user.SideMode,
|
||||
Enable: user.Enable,
|
||||
}); err != nil {
|
||||
})
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("设置失败!", zap.Error(err))
|
||||
response.FailWithMessage("设置失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("设置成功", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("设置成功", c)
|
||||
}
|
||||
|
||||
// @Tags SysUser
|
||||
// @Summary 设置用户信息
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body system.SysUser true "ID, 用户名, 昵称, 头像链接"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "设置用户信息"
|
||||
// @Router /user/SetSelfInfo [put]
|
||||
// SetSelfInfo
|
||||
// @Tags SysUser
|
||||
// @Summary 设置用户信息
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body system.SysUser true "ID, 用户名, 昵称, 头像链接"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "设置用户信息"
|
||||
// @Router /user/SetSelfInfo [put]
|
||||
func (b *BaseApi) SetSelfInfo(c *gin.Context) {
|
||||
var user systemReq.ChangeUserInfo
|
||||
_ = c.ShouldBindJSON(&user)
|
||||
err := c.ShouldBindJSON(&user)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
user.ID = utils.GetUserID(c)
|
||||
if err := userService.SetUserInfo(system.SysUser{
|
||||
err = userService.SetUserInfo(system.SysUser{
|
||||
GVA_MODEL: global.GVA_MODEL{
|
||||
ID: user.ID,
|
||||
},
|
||||
@@ -333,45 +389,54 @@ func (b *BaseApi) SetSelfInfo(c *gin.Context) {
|
||||
Email: user.Email,
|
||||
SideMode: user.SideMode,
|
||||
Enable: user.Enable,
|
||||
}); err != nil {
|
||||
})
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("设置失败!", zap.Error(err))
|
||||
response.FailWithMessage("设置失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("设置成功", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("设置成功", c)
|
||||
}
|
||||
|
||||
// @Tags SysUser
|
||||
// @Summary 获取用户信息
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取用户信息"
|
||||
// @Router /user/getUserInfo [get]
|
||||
// GetUserInfo
|
||||
// @Tags SysUser
|
||||
// @Summary 获取用户信息
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取用户信息"
|
||||
// @Router /user/getUserInfo [get]
|
||||
func (b *BaseApi) GetUserInfo(c *gin.Context) {
|
||||
uuid := utils.GetUserUuid(c)
|
||||
if ReqUser, err := userService.GetUserInfo(uuid); err != nil {
|
||||
ReqUser, err := userService.GetUserInfo(uuid)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
} else {
|
||||
response.OkWithDetailed(gin.H{"userInfo": ReqUser}, "获取成功", c)
|
||||
return
|
||||
}
|
||||
response.OkWithDetailed(gin.H{"userInfo": ReqUser}, "获取成功", c)
|
||||
}
|
||||
|
||||
// @Tags SysUser
|
||||
// @Summary 重置用户密码
|
||||
// @Security ApiKeyAuth
|
||||
// ResetPassword
|
||||
// @Tags SysUser
|
||||
// @Summary 重置用户密码
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Param data body system.SysUser true "ID"
|
||||
// @Success 200 {object} response.Response{msg=string} "重置用户密码"
|
||||
// @Router /user/resetPassword [post]
|
||||
// @Param data body system.SysUser true "ID"
|
||||
// @Success 200 {object} response.Response{msg=string} "重置用户密码"
|
||||
// @Router /user/resetPassword [post]
|
||||
func (b *BaseApi) ResetPassword(c *gin.Context) {
|
||||
var user system.SysUser
|
||||
_ = c.ShouldBindJSON(&user)
|
||||
if err := userService.ResetPassword(user.ID); err != nil {
|
||||
err := c.ShouldBindJSON(&user)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = userService.ResetPassword(user.ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("重置失败!", zap.Error(err))
|
||||
response.FailWithMessage("重置失败"+err.Error(), c)
|
||||
} else {
|
||||
response.OkWithMessage("重置成功", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("重置成功", c)
|
||||
}
|
||||
|
Reference in New Issue
Block a user