注册成功返回token

This commit is contained in:
石皮幼鸟 2024-04-26 19:44:35 +08:00
parent dba81c95a3
commit 080078ee4f
3 changed files with 6 additions and 4 deletions

View File

@ -48,7 +48,7 @@ public class AuthController {
@ApiOperation(value = "用户注册") @ApiOperation(value = "用户注册")
@PostMapping("/register") @PostMapping("/register")
public R<UserVo> register(@RequestBody RegisterDto registerDto) { public R<String> register(@RequestBody RegisterDto registerDto) {
return authService.register(registerDto); return authService.register(registerDto);
} }

View File

@ -42,7 +42,7 @@ public interface AuthService {
* @param registerDto 注册信息 * @param registerDto 注册信息
* @return token * @return token
*/ */
R<UserVo> register(RegisterDto registerDto); R<String> register(RegisterDto registerDto);
/** /**
* 获取用户信息 * 获取用户信息

View File

@ -83,7 +83,7 @@ public class AuthServiceImpl implements AuthService {
} }
@Override @Override
public R<UserVo> register(RegisterDto registerDto) { public R<String> register(RegisterDto registerDto) {
// 根据用户名查询用户信息 // 根据用户名查询用户信息
var username = registerDto.getUsername(); var username = registerDto.getUsername();
var matchType = getMatchType(username); var matchType = getMatchType(username);
@ -121,7 +121,9 @@ public class AuthServiceImpl implements AuthService {
user.setUpdateTime(System.currentTimeMillis()); user.setUpdateTime(System.currentTimeMillis());
var insert = mongoTemplate.insert(user); var insert = mongoTemplate.insert(user);
if (insert.getId() != null) { if (insert.getId() != null) {
return R.ok(user.toVo()); var token = JwtUtil.getToken(Map.of("id", insert.getId()), CommonConstant.TOKEN_EXPIRE_TIME);
redisService.hSet(token, insert.getId(), CommonConstant.REDIS_EXPIRE_TIME);
return R.ok(token);
} else { } else {
return R.fail("注册失败,请重试"); return R.fail("注册失败,请重试");
} }