Compare commits

...

2 Commits

Author SHA1 Message Date
31353 0856e6a335 第五修改 2024-01-08 11:25:15 +08:00
31353 afe4128893 第四修改 2024-01-08 09:22:21 +08:00
2 changed files with 24 additions and 18 deletions

View File

@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/bwie-api/bwie-user-api/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/bwie-api/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/bwie-api/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/bwie-auth/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/bwie-auth/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/bwie-common/src/main/java" charset="UTF-8" />

View File

@ -1,5 +1,6 @@
package com.bwie.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.common.utils.UuidUtils;
import com.bwie.common.constants.JwtConstants;
import com.bwie.common.constants.TokenConstants;
@ -48,13 +49,11 @@ public class AuthServicelmpl implements AuthService{
public Result login(UserRequest userRequest) {
//判断姓名是否为空
Optional<String> optional = Optional.ofNullable(userRequest.getUsername());
String defaultName = optional.orElse("张三");
//判断
if (!optional.isPresent()){
//为null定义一个默认值
String defaultName = optional.orElse("张三");
userRequest.setUsername(defaultName);
}
String orDefault = optionalUtils.getOrDefault(optional, defaultName);
//为null 返回默认值
userRequest.setUsername(orDefault);
User user = remoteUserService.findName(userRequest.getUsername()).getData();
if (null==user){
return Result.error("用户名不存在!!!!!!!");
@ -75,11 +74,10 @@ public class AuthServicelmpl implements AuthService{
public Result sendCode(String tel) {
//判断手机号是否为空
Optional<String> optional = Optional.ofNullable(tel);
if (!optional.isPresent()){
//默认值
String defaultPhone = optional.orElse("18098734205");
tel = defaultPhone;
}
//默认值
String defaultPhone = optional.orElse("18098734205");
String defaultTel = optionalUtils.getOrDefault(optional, defaultPhone);
tel = defaultTel;
//格式验证
if (!tel.matches("^1[3-9]\\d{9}$")){
return Result.error("手机号格式有误");
@ -105,11 +103,12 @@ public class AuthServicelmpl implements AuthService{
public Result TelLogin(TelLogin telLogin) {
//判断手机号是否为空
Optional<String> optional = Optional.ofNullable(telLogin.getTel());
if (!optional.isPresent()){
//默认值
String defaultPhone = optional.orElse("18098734205");
telLogin.setTel(defaultPhone);
}
//默认值
String defaultPhone = optional.orElse("18098734205");
String orDefault = optionalUtils.getOrDefault(optional, defaultPhone);
telLogin.setTel(orDefault);
//格式验证
if (!telLogin.getTel().matches("^1[3-9]\\d{9}$")){
return Result.error("手机号格式有误");
@ -132,7 +131,11 @@ public class AuthServicelmpl implements AuthService{
@Override
public Result info() {
return null;
String token = request.getHeader(TokenConstants.TOKEN);
String userKey = JwtUtils.getUserKey(token);
String s = redisTemplate.opsForValue().get(TokenConstants.LOGIN_TOKEN_KEY + userKey);
User user = JSON.parseObject(s, User.class);
return Result.success(user);
}
/**
@ -143,7 +146,7 @@ public class AuthServicelmpl implements AuthService{
String userKey = UuidUtils.generateUuid().replaceAll("-", "");
map.put(JwtConstants.USER_KEY,userKey);
String token = JwtUtils.createToken(map);
redisTemplate.opsForValue().set(TokenConstants.LOGIN_TOKEN_KEY+userKey,token,15, TimeUnit.MINUTES);
redisTemplate.opsForValue().set(TokenConstants.LOGIN_TOKEN_KEY+userKey, JSON.toJSONString(user),15, TimeUnit.MINUTES);
return new JwtRequest(token);
}
}