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