修复用户登录

This commit is contained in:
guotao 2026-01-12 15:42:01 +08:00
parent f14f45faf5
commit 0edffa145b
4 changed files with 10 additions and 8 deletions

View file

@ -159,6 +159,7 @@ public class AuthController {
* @return 商家信息
*/
@GetMapping("/profile")
@Transactional(readOnly = true)
public ApiResult<MerchantDto> getProfile(@AuthenticationPrincipal LoginUser loginUser) {
if (loginUser.getMerchantId() == null) {
return ApiResult.fail("商家信息不存在");

View file

@ -16,7 +16,6 @@ import org.hibernate.annotations.Comment;
@Table
@Comment("商户信息表")
public class Merchant extends AbstractBaseEntity {
/**
* 用户信息
*/

View file

@ -1,6 +1,7 @@
package com.xjhs.findmemerchant.security;
import com.xjhs.findmemerchant.mapper.SystemUserMapper;
import com.xjhs.findmemerchant.repository.MerchantRepository;
import com.xjhs.findmemerchant.security.sms.SmsAuthenticationToken;
import jakarta.servlet.FilterChain;
@ -23,17 +24,18 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
private final JwtTokenService jwtTokenService;
private final MerchantRepository merchantRepository;
private final SystemUserMapper systemUserMapper;
private SmsAuthenticationToken getAuthenticationToken(String phone) throws Exception {
private SmsAuthenticationToken getAuthenticationToken(String phone) throws Exception {
// 手机号查商家
var merchant = merchantRepository.findBySystemUserPhone(phone).orElse(null);
if(merchant != null){
var merchant = merchantRepository.findBySystemUserPhone(phone).orElse(null);
if (merchant != null) {
var authorities = List.of(new SimpleGrantedAuthority("ROLE_USER"));
return new SmsAuthenticationToken(merchant, authorities);
var loginUser = systemUserMapper.toLoginUserInfo(merchant.getSystemUser());
return new SmsAuthenticationToken(loginUser, authorities);
}
throw new Exception("用户信息不存在");
throw new Exception("用户信息不存在");
}
@Override

View file

@ -19,6 +19,6 @@ public class RegisterVo {
* 短信验证码
*/
@NotBlank
@Size(max = 6, min = 6)
@Size(max = 4, min = 4)
private String code;
}