登陆失败返回401状态,修复后台删除用户导致登陆失败的问题
This commit is contained in:
@ -5,6 +5,7 @@ import co.yixiang.modules.security.security.JwtUser;
|
||||
import co.yixiang.modules.user.entity.YxUser;
|
||||
import co.yixiang.modules.user.service.YxUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -30,10 +31,10 @@ public class JwtUserDetailsService implements UserDetailsService {
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username){
|
||||
System.out.println("username:"+username);
|
||||
System.out.println("username2:"+username);
|
||||
YxUser user = yxUserService.findByName(username);
|
||||
if (user == null) {
|
||||
throw new BadRequestException("账号不存在");
|
||||
throw new BadRequestException(HttpStatus.UNAUTHORIZED,"账号不存在");
|
||||
} else {
|
||||
return createJwtUser(user);
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ public class UserAddressController extends BaseController {
|
||||
/**
|
||||
* 删除用户地址
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
@PostMapping("/address/del")
|
||||
@ApiOperation(value = "删除用户地址",notes = "删除用户地址",response = ApiResult.class)
|
||||
public ApiResult<Boolean> deleteYxUserAddress(@Valid @RequestBody IdParam idParam){
|
||||
YxUserAddress userAddress = new YxUserAddress();
|
||||
|
@ -15,6 +15,7 @@ import co.yixiang.modules.user.entity.YxWechatUser;
|
||||
import co.yixiang.modules.user.mapper.YxUserMapper;
|
||||
import co.yixiang.modules.user.service.YxUserService;
|
||||
import co.yixiang.modules.user.service.YxWechatUserService;
|
||||
import co.yixiang.modules.user.web.vo.YxUserQueryVo;
|
||||
import co.yixiang.utils.EncryptUtils;
|
||||
import co.yixiang.utils.OrderUtil;
|
||||
import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
|
||||
@ -105,16 +106,22 @@ public class WechatController extends BaseController {
|
||||
//String url = "https://h5.dayouqiantu.cn/";
|
||||
//wxService.oauth2buildAuthorizationUrl(url, WxConsts.OAuth2Scope.SNSAPI_USERINFO, null);
|
||||
|
||||
|
||||
try {
|
||||
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = wxService.oauth2getAccessToken(code);
|
||||
WxMpUser wxMpUser = wxService.oauth2getUserInfo(wxMpOAuth2AccessToken, null);
|
||||
String openid = wxMpUser.getOpenId();
|
||||
YxWechatUser wechatUser = wechatUserService.getUserInfo(openid);;
|
||||
YxUserQueryVo yxUserQueryVo = userService.getYxUserById(wechatUser.getUid());
|
||||
JwtUser jwtUser = null;
|
||||
if(ObjectUtil.isNotNull(wechatUser)){
|
||||
if(ObjectUtil.isNotNull(wechatUser) && ObjectUtil.isNotNull(yxUserQueryVo)){
|
||||
jwtUser = (JwtUser) userDetailsService.loadUserByUsername(wechatUser.getOpenid());
|
||||
}else{
|
||||
if(ObjectUtil.isNotNull(wechatUser)){
|
||||
wechatUserService.removeById(wechatUser.getUid());
|
||||
}
|
||||
if(ObjectUtil.isNotNull(yxUserQueryVo)){
|
||||
userService.removeById(yxUserQueryVo.getUid());
|
||||
}
|
||||
//用户保存
|
||||
YxUser user = new YxUser();
|
||||
user.setAccount(wxMpUser.getNickname());
|
||||
|
@ -6,7 +6,7 @@ spring:
|
||||
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
|
||||
url: jdbc:log4jdbc:mysql://localhost:3306/yshop?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
|
||||
username: yshop
|
||||
password:
|
||||
password:
|
||||
|
||||
# 初始化配置
|
||||
initial-size: 3
|
||||
|
@ -63,6 +63,12 @@ wx:
|
||||
subAppId:
|
||||
subMchId:
|
||||
keyPath:
|
||||
miniapp:
|
||||
appid: wxa82b5b7fcb0ec161
|
||||
secret:
|
||||
token:
|
||||
aesKey:
|
||||
msgDataFormat: JSON
|
||||
logging:
|
||||
level:
|
||||
org.springframework.web: INFO
|
||||
|
@ -23,6 +23,11 @@
|
||||
<artifactId>wx-java-pay-spring-boot-starter</artifactId>
|
||||
<version>3.5.0</version>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.github.binarywang</groupId>-->
|
||||
<!-- <artifactId>wx-java-miniapp-spring-boot-starter</artifactId>-->
|
||||
<!-- <version>3.5.0</version>-->
|
||||
<!-- </dependency>-->
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
@ -42,3 +42,9 @@ wx:
|
||||
secret:
|
||||
token: yshop
|
||||
aesKey: yYuBUkC8BXImCXyu7O6hkzLj4TC5nxsWPfL4CQAZPNY
|
||||
# miniapp:
|
||||
# appid: wx604d2ea4702620d2
|
||||
# secret:
|
||||
# token:
|
||||
# aesKey:
|
||||
# msgDataFormat: JSON
|
||||
|
Reference in New Issue
Block a user