完善 h5 端后端登录流程
This commit is contained in:
parent
443ac4d569
commit
249558d93a
@ -14,27 +14,26 @@ import java.util.Date;
|
||||
*/
|
||||
public class JwtHelper {
|
||||
|
||||
private static final long tokenExpiration = 365L * 24 * 60 * 60 * 1000;
|
||||
private static final long tokenExpiration = 5 * 60 * 1000;
|
||||
private static final String tokenSignKey = "xlcs";
|
||||
|
||||
public static String createToken(Long userId, String userName) {
|
||||
String token = Jwts.builder()
|
||||
.setSubject("xlcs-USER")
|
||||
.setExpiration(new Date(System.currentTimeMillis() + tokenExpiration))
|
||||
.claim("userId", userId)
|
||||
.claim("userName", userName)
|
||||
.signWith(SignatureAlgorithm.HS512, tokenSignKey)
|
||||
.compressWith(CompressionCodecs.GZIP)
|
||||
.compact();
|
||||
return token;
|
||||
return Jwts.builder()
|
||||
.setSubject("xlcs-USER")
|
||||
.setExpiration(new Date(System.currentTimeMillis() + tokenExpiration))
|
||||
.claim("userId", userId)
|
||||
.claim("userName", userName)
|
||||
.signWith(SignatureAlgorithm.HS512, tokenSignKey)
|
||||
.compressWith(CompressionCodecs.GZIP)
|
||||
.compact();
|
||||
}
|
||||
|
||||
public static Long getUserId(String token) {
|
||||
if (StringUtils.isEmpty(token)) return null;
|
||||
|
||||
Jws<Claims> claimsJws = Jwts.parser()
|
||||
.setSigningKey(tokenSignKey)
|
||||
.parseClaimsJws(token);
|
||||
.setSigningKey(tokenSignKey)
|
||||
.parseClaimsJws(token);
|
||||
Claims claims = claimsJws.getBody();
|
||||
Integer userId = (Integer) claims.get("userId");
|
||||
return userId.longValue();
|
||||
@ -45,8 +44,8 @@ public class JwtHelper {
|
||||
if (StringUtils.isEmpty(token)) return "";
|
||||
|
||||
Jws<Claims> claimsJws = Jwts.parser()
|
||||
.setSigningKey(tokenSignKey)
|
||||
.parseClaimsJws(token);
|
||||
.setSigningKey(tokenSignKey)
|
||||
.parseClaimsJws(token);
|
||||
Claims claims = claimsJws.getBody();
|
||||
return (String) claims.get("userName");
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public class LoginMvcConfigurerAdapter extends WebMvcConfigurationSupport {
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(new UserLoginInterceptor(redisTemplate))
|
||||
.addPathPatterns("/api/**")
|
||||
.excludePathPatterns("/api/user/weixin/wxLogin/*");
|
||||
.excludePathPatterns("/api/user/weixin/wxLogin/*", "/api/user/h5/login/*");
|
||||
super.addInterceptors(registry);
|
||||
}
|
||||
}
|
||||
|
@ -16,5 +16,11 @@
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@ -36,7 +36,7 @@ public class LoginService {
|
||||
public Map<String, Object> login(String phone, String password) {
|
||||
User user = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getPhone, phone)
|
||||
.eq(User::getPassword, MD5.encrypt(password)));
|
||||
if (user.getPhone() == null) {
|
||||
if (user == null) {
|
||||
throw new xlcsException(ResultCodeEnum.ACCOUNT_PASSWORD_ERROR);
|
||||
}
|
||||
// 根据userId查询配送点和配送员信息
|
||||
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yovinchen.xlcs.common.auth.AuthContextHolder;
|
||||
import com.yovinchen.xlcs.common.exception.xlcsException;
|
||||
import com.yovinchen.xlcs.common.result.ResultCodeEnum;
|
||||
import com.yovinchen.xlcs.common.utils.MD5;
|
||||
import com.yovinchen.xlcs.enums.UserType;
|
||||
import com.yovinchen.xlcs.model.user.Leader;
|
||||
import com.yovinchen.xlcs.model.user.User;
|
||||
@ -164,7 +165,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
//构建用户信息
|
||||
user = new User();
|
||||
user.setNickName(phone);
|
||||
user.setPhone(phone);
|
||||
user.setPhotoUrl("");
|
||||
user.setPassword(MD5.encrypt(password));
|
||||
user.setUserType(UserType.USER);
|
||||
user.setIsNew(1);
|
||||
baseMapper.insert(user);
|
||||
|
Loading…
Reference in New Issue
Block a user