|
|
@ -31,7 +31,7 @@ func (b *BaseApi) Login(c *gin.Context) { |
|
|
|
if store.Verify(l.CaptchaId, l.Captcha, true) { |
|
|
|
u := &system.SysUser{Username: l.Username, Password: l.Password} |
|
|
|
if err, user := userService.Login(u); err != nil { |
|
|
|
global.GVA_LOG.Error("登陆失败! 用户名不存在或者密码错误!", zap.Any("err", err)) |
|
|
|
global.GVA_LOG.Error("登陆失败! 用户名不存在或者密码错误!", zap.Error(err)) |
|
|
|
response.FailWithMessage("用户名不存在或者密码错误", c) |
|
|
|
} else { |
|
|
|
b.tokenNext(c, *user) |
|
|
@ -53,7 +53,7 @@ func (b *BaseApi) tokenNext(c *gin.Context, user system.SysUser) { |
|
|
|
}) |
|
|
|
token, err := j.CreateToken(claims) |
|
|
|
if err != nil { |
|
|
|
global.GVA_LOG.Error("获取token失败!", zap.Any("err", err)) |
|
|
|
global.GVA_LOG.Error("获取token失败!", zap.Error(err)) |
|
|
|
response.FailWithMessage("获取token失败", c) |
|
|
|
return |
|
|
|
} |
|
|
@ -68,7 +68,7 @@ func (b *BaseApi) tokenNext(c *gin.Context, user system.SysUser) { |
|
|
|
|
|
|
|
if err, jwtStr := jwtService.GetRedisJWT(user.Username); err == redis.Nil { |
|
|
|
if err := jwtService.SetRedisJWT(token, user.Username); err != nil { |
|
|
|
global.GVA_LOG.Error("设置登录状态失败!", zap.Any("err", err)) |
|
|
|
global.GVA_LOG.Error("设置登录状态失败!", zap.Error(err)) |
|
|
|
response.FailWithMessage("设置登录状态失败", c) |
|
|
|
return |
|
|
|
} |
|
|
@ -78,7 +78,7 @@ func (b *BaseApi) tokenNext(c *gin.Context, user system.SysUser) { |
|
|
|
ExpiresAt: claims.StandardClaims.ExpiresAt * 1000, |
|
|
|
}, "登录成功", c) |
|
|
|
} else if err != nil { |
|
|
|
global.GVA_LOG.Error("设置登录状态失败!", zap.Any("err", err)) |
|
|
|
global.GVA_LOG.Error("设置登录状态失败!", zap.Error(err)) |
|
|
|
response.FailWithMessage("设置登录状态失败", c) |
|
|
|
} else { |
|
|
|
var blackJWT system.JwtBlacklist |
|
|
@ -121,7 +121,7 @@ func (b *BaseApi) Register(c *gin.Context) { |
|
|
|
user := &system.SysUser{Username: r.Username, NickName: r.NickName, Password: r.Password, HeaderImg: r.HeaderImg, AuthorityId: r.AuthorityId, Authorities: authorities} |
|
|
|
err, userReturn := userService.Register(*user) |
|
|
|
if err != nil { |
|
|
|
global.GVA_LOG.Error("注册失败!", zap.Any("err", err)) |
|
|
|
global.GVA_LOG.Error("注册失败!", zap.Error(err)) |
|
|
|
response.FailWithDetailed(systemRes.SysUserResponse{User: userReturn}, "注册失败", c) |
|
|
|
} else { |
|
|
|
response.OkWithDetailed(systemRes.SysUserResponse{User: userReturn}, "注册成功", c) |
|
|
@ -144,7 +144,7 @@ func (b *BaseApi) ChangePassword(c *gin.Context) { |
|
|
|
} |
|
|
|
u := &system.SysUser{Username: user.Username, Password: user.Password} |
|
|
|
if err, _ := userService.ChangePassword(u, user.NewPassword); err != nil { |
|
|
|
global.GVA_LOG.Error("修改失败!", zap.Any("err", err)) |
|
|
|
global.GVA_LOG.Error("修改失败!", zap.Error(err)) |
|
|
|
response.FailWithMessage("修改失败,原密码与当前账户不符", c) |
|
|
|
} else { |
|
|
|
response.OkWithMessage("修改成功", c) |
|
|
@ -167,7 +167,7 @@ func (b *BaseApi) GetUserList(c *gin.Context) { |
|
|
|
return |
|
|
|
} |
|
|
|
if err, list, total := userService.GetUserInfoList(pageInfo); err != nil { |
|
|
|
global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) |
|
|
|
global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
|
|
|
response.FailWithMessage("获取失败", c) |
|
|
|
} else { |
|
|
|
response.OkWithDetailed(response.PageResult{ |
|
|
@ -197,14 +197,14 @@ func (b *BaseApi) SetUserAuthority(c *gin.Context) { |
|
|
|
userID := utils.GetUserID(c) |
|
|
|
uuid := utils.GetUserUuid(c) |
|
|
|
if err := userService.SetUserAuthority(userID, uuid, sua.AuthorityId); err != nil { |
|
|
|
global.GVA_LOG.Error("修改失败!", zap.Any("err", err)) |
|
|
|
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.Any("err", err)) |
|
|
|
global.GVA_LOG.Error("修改失败!", zap.Error(err)) |
|
|
|
response.FailWithMessage(err.Error(), c) |
|
|
|
} else { |
|
|
|
c.Header("new-token", token) |
|
|
@ -227,7 +227,7 @@ 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.Any("err", err)) |
|
|
|
global.GVA_LOG.Error("修改失败!", zap.Error(err)) |
|
|
|
response.FailWithMessage("修改失败", c) |
|
|
|
} else { |
|
|
|
response.OkWithMessage("修改成功", c) |
|
|
@ -255,7 +255,7 @@ func (b *BaseApi) DeleteUser(c *gin.Context) { |
|
|
|
return |
|
|
|
} |
|
|
|
if err := userService.DeleteUser(reqId.ID); err != nil { |
|
|
|
global.GVA_LOG.Error("删除失败!", zap.Any("err", err)) |
|
|
|
global.GVA_LOG.Error("删除失败!", zap.Error(err)) |
|
|
|
response.FailWithMessage("删除失败", c) |
|
|
|
} else { |
|
|
|
response.OkWithMessage("删除成功", c) |
|
|
@ -278,7 +278,7 @@ func (b *BaseApi) SetUserInfo(c *gin.Context) { |
|
|
|
return |
|
|
|
} |
|
|
|
if err, ReqUser := userService.SetUserInfo(user); err != nil { |
|
|
|
global.GVA_LOG.Error("设置失败!", zap.Any("err", err)) |
|
|
|
global.GVA_LOG.Error("设置失败!", zap.Error(err)) |
|
|
|
response.FailWithMessage("设置失败", c) |
|
|
|
} else { |
|
|
|
response.OkWithDetailed(gin.H{"userInfo": ReqUser}, "设置成功", c) |
|
|
@ -295,7 +295,7 @@ func (b *BaseApi) SetUserInfo(c *gin.Context) { |
|
|
|
func (b *BaseApi) GetUserInfo(c *gin.Context) { |
|
|
|
uuid := utils.GetUserUuid(c) |
|
|
|
if err, ReqUser := userService.GetUserInfo(uuid); err != nil { |
|
|
|
global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) |
|
|
|
global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
|
|
|
response.FailWithMessage("获取失败", c) |
|
|
|
} else { |
|
|
|
response.OkWithDetailed(gin.H{"userInfo": ReqUser}, "获取成功", c) |
|
|
|