1.修改user login 接口返回map, 2.nickName 格式为XX-XXXX-XXXX

main
Gary 1 year ago
parent 7e832125bc
commit e812995138

@ -107,8 +107,12 @@ public class UserController {
return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH);
}
User user = userService.loginOrRegister(mobile);
String token = jwtUtil.createJWT(user.getId(),user.getNickname(),Constants.TOKEN_ROLE_APP_USER);
return Result.success(token);
Map<String,String> map = new HashMap<>();
map.put("token", token);
return Result.success(map);
}finally {
redisTemplate.delete(redisMobileCheckCodeKey);
}
@ -117,10 +121,12 @@ public class UserController {
@ApiOperation(value = "3.游客登录返回token", notes = "token中的subject和roles均为tourist")
@GetMapping("/touristLogin")
public Result<String> touristLogin() {
public Result<Map<String,String>> touristLogin() {
String nickName="游客-"+NickNameUtil.getRandomNickName();
String token = jwtUtil.createJWT(String.valueOf(idWorker.nextId()),nickName,Constants.TOKEN_ROLE_TOURIST);
return Result.success(token);
Map<String,String> map=new HashMap<>();
map.put("token", token);
return Result.success(map);
}
/**
@ -140,8 +146,10 @@ public class UserController {
@ApiOperation(value = "5.token续期", notes = "有效期7天")
@PostMapping("/autoLogin")
@GlobalInterceptor
public Result<String> autoLogin(@RequestHeader(value = "token", required = false) String token) {
return Result.success(userService.autoLogin(token));
public Result<Map<String, String>> autoLogin(@RequestHeader(value = "token", required = false) String token) {
Map<String,String> map=new HashMap<>();
map.put("token", userService.autoLogin(token));
return Result.success(map);
}
/**

@ -3,7 +3,21 @@ package com.luoo.user.util;
import com.apifan.common.random.RandomSource;
public class NickNameUtil {
/**
* /-XXXX-XXXX10000.000001%
* eg:
* -.
* -&
* --
* -$
*/
private static String[] SPECIAL_CHARACTER = new String[] { "~", "`", "@", "$", "%", "^", "&", "*", "+", "-", "|",
".", "<", ">" };
public static String getRandomNickName() {
return RandomSource.personInfoSource().randomChineseNickName(4);
int index = RandomSource.numberSource().randomInt(0, SPECIAL_CHARACTER.length);
String character = SPECIAL_CHARACTER[index];
return RandomSource.personInfoSource().randomChineseNickName(4) + character
+ RandomSource.personInfoSource().randomChineseNickName(4);
}
}

Loading…
Cancel
Save