|
|
@@ -9,6 +9,7 @@ import com.izouma.zhirongip.domain.User;
|
|
|
import com.izouma.zhirongip.dto.PageQuery;
|
|
|
import com.izouma.zhirongip.dto.UserRegister;
|
|
|
import com.izouma.zhirongip.enums.AuthorityName;
|
|
|
+import com.izouma.zhirongip.exception.AuthenticationException;
|
|
|
import com.izouma.zhirongip.exception.BusinessException;
|
|
|
import com.izouma.zhirongip.repo.InstitutionRepo;
|
|
|
import com.izouma.zhirongip.repo.PersonalRepo;
|
|
|
@@ -83,8 +84,17 @@ public class UserService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public User loginByPhone(String phone) {
|
|
|
- return userRepo.findByPhoneAndDelFalse(phone);
|
|
|
+ public User loginByPhone(String phone, String code) {
|
|
|
+ User user = userRepo.findByPhoneAndDelFalse(phone);
|
|
|
+ if (user == null) {
|
|
|
+ throw new AuthenticationException("手机号未注册", null);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ smsService.verify(phone, code);
|
|
|
+ } catch (SmsService.SmsVerifyException e) {
|
|
|
+ throw new AuthenticationException("验证码错误", e);
|
|
|
+ }
|
|
|
+ return user;
|
|
|
}
|
|
|
|
|
|
public User loginMp(String code) throws WxErrorException {
|
|
|
@@ -93,17 +103,17 @@ public class UserService {
|
|
|
User user = userRepo.findByOpenIdAndDelFalse(wxMpUser.getOpenId());
|
|
|
if (user == null) {
|
|
|
user = User.builder()
|
|
|
- .username(UUID.randomUUID().toString())
|
|
|
- .nickname(wxMpUser.getNickname())
|
|
|
- .avatar(wxMpUser.getHeadImgUrl())
|
|
|
- .sex(wxMpUser.getSexDesc())
|
|
|
- .country(wxMpUser.getCountry())
|
|
|
- .province(wxMpUser.getProvince())
|
|
|
- .city(wxMpUser.getCity())
|
|
|
- .openId(wxMpUser.getOpenId())
|
|
|
- .language(wxMpUser.getLanguage())
|
|
|
- .authorities(Collections.singleton(Authority.builder().name("ROLE_USER").build()))
|
|
|
- .build();
|
|
|
+ .username(UUID.randomUUID().toString())
|
|
|
+ .nickname(wxMpUser.getNickname())
|
|
|
+ .avatar(wxMpUser.getHeadImgUrl())
|
|
|
+ .sex(wxMpUser.getSexDesc())
|
|
|
+ .country(wxMpUser.getCountry())
|
|
|
+ .province(wxMpUser.getProvince())
|
|
|
+ .city(wxMpUser.getCity())
|
|
|
+ .openId(wxMpUser.getOpenId())
|
|
|
+ .language(wxMpUser.getLanguage())
|
|
|
+ .authorities(Collections.singleton(Authority.builder().name("ROLE_USER").build()))
|
|
|
+ .build();
|
|
|
userRepo.save(user);
|
|
|
}
|
|
|
return user;
|
|
|
@@ -119,12 +129,12 @@ public class UserService {
|
|
|
return userInfo;
|
|
|
}
|
|
|
userInfo = User.builder()
|
|
|
- .username(UUID.randomUUID().toString())
|
|
|
- .nickname("用户" + RandomStringUtils.randomAlphabetic(6))
|
|
|
- .openId(openId)
|
|
|
- .avatar(Constants.DEFAULT_AVATAR)
|
|
|
- .authorities(Collections.singleton(Authority.builder().name("ROLE_USER").build()))
|
|
|
- .build();
|
|
|
+ .username(UUID.randomUUID().toString())
|
|
|
+ .nickname("用户" + RandomStringUtils.randomAlphabetic(6))
|
|
|
+ .openId(openId)
|
|
|
+ .avatar(Constants.DEFAULT_AVATAR)
|
|
|
+ .authorities(Collections.singleton(Authority.builder().name("ROLE_USER").build()))
|
|
|
+ .build();
|
|
|
userInfo = userRepo.save(userInfo);
|
|
|
return userInfo;
|
|
|
} catch (WxErrorException e) {
|
|
|
@@ -158,16 +168,16 @@ public class UserService {
|
|
|
if (user == null) {
|
|
|
|
|
|
user = User.builder()
|
|
|
- .username(UUID.randomUUID().toString())
|
|
|
- .nickname(wxUserInfo.getNickName())
|
|
|
- .openId(wxUserInfo.getOpenId())
|
|
|
- .avatar(avatarUrl)
|
|
|
- .sex(wxUserInfo.getGender())
|
|
|
- .country(wxUserInfo.getCountry())
|
|
|
- .province(wxUserInfo.getProvince())
|
|
|
- .city(wxUserInfo.getCity())
|
|
|
- .authorities(Collections.singleton(Authority.builder().name("ROLE_USER").build()))
|
|
|
- .build();
|
|
|
+ .username(UUID.randomUUID().toString())
|
|
|
+ .nickname(wxUserInfo.getNickName())
|
|
|
+ .openId(wxUserInfo.getOpenId())
|
|
|
+ .avatar(avatarUrl)
|
|
|
+ .sex(wxUserInfo.getGender())
|
|
|
+ .country(wxUserInfo.getCountry())
|
|
|
+ .province(wxUserInfo.getProvince())
|
|
|
+ .city(wxUserInfo.getCity())
|
|
|
+ .authorities(Collections.singleton(Authority.builder().name("ROLE_USER").build()))
|
|
|
+ .build();
|
|
|
user = userRepo.save(user);
|
|
|
|
|
|
} else {
|
|
|
@@ -206,12 +216,12 @@ public class UserService {
|
|
|
|
|
|
String phone1 = phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
|
|
|
User user = User.builder()
|
|
|
- .phone(phone)
|
|
|
- .username(phone)
|
|
|
- .nickname("用户" + phone1)
|
|
|
- .password(new BCryptPasswordEncoder().encode(password))
|
|
|
- .authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
|
|
|
- .build();
|
|
|
+ .phone(phone)
|
|
|
+ .username(phone)
|
|
|
+ .nickname("用户" + phone1)
|
|
|
+ .password(new BCryptPasswordEncoder().encode(password))
|
|
|
+ .authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
|
|
|
+ .build();
|
|
|
return userRepo.save(user);
|
|
|
}
|
|
|
|