|
|
@@ -17,21 +17,21 @@ import me.chanjar.weixin.mp.api.WxMpService;
|
|
|
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
|
|
|
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.UUID;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
@AllArgsConstructor
|
|
|
public class UserService {
|
|
|
- private UserRepo userRepo;
|
|
|
- private WxMaService wxMaService;
|
|
|
- private WxMpService wxMpService;
|
|
|
- private SmsService smsService;
|
|
|
+ private UserRepo userRepo;
|
|
|
+ private WxMaService wxMaService;
|
|
|
+ private WxMpService wxMpService;
|
|
|
+ private SmsService smsService;
|
|
|
private StorageService storageService;
|
|
|
|
|
|
public User loginByPhone(String phone) {
|
|
|
@@ -54,7 +54,7 @@ public class UserService {
|
|
|
.openId(wxMpUser.getOpenId())
|
|
|
.language(wxMpUser.getLanguage())
|
|
|
.enabled(true)
|
|
|
- .authorities(Collections.singletonList(Authority.builder().name("ROLE_USER").build()))
|
|
|
+ .authorities(Collections.singleton(Authority.builder().name("ROLE_USER").build()))
|
|
|
.build();
|
|
|
userRepo.save(user);
|
|
|
}
|
|
|
@@ -76,7 +76,7 @@ public class UserService {
|
|
|
.openId(openId)
|
|
|
.avatar(Constants.DEFAULT_AVATAR)
|
|
|
.enabled(true)
|
|
|
- .authorities(Collections.singletonList(Authority.builder().name("ROLE_USER").build()))
|
|
|
+ .authorities(Collections.singleton(Authority.builder().name("ROLE_USER").build()))
|
|
|
.build();
|
|
|
userInfo = userRepo.save(userInfo);
|
|
|
return userInfo;
|
|
|
@@ -120,7 +120,7 @@ public class UserService {
|
|
|
.province(wxUserInfo.getProvince())
|
|
|
.city(wxUserInfo.getCity())
|
|
|
.enabled(true)
|
|
|
- .authorities(Collections.singletonList(Authority.builder().name("ROLE_USER").build()))
|
|
|
+ .authorities(Collections.singleton(Authority.builder().name("ROLE_USER").build()))
|
|
|
.build();
|
|
|
user = userRepo.save(user);
|
|
|
|
|
|
@@ -136,4 +136,23 @@ public class UserService {
|
|
|
|
|
|
return user;
|
|
|
}
|
|
|
+
|
|
|
+ @PostConstruct
|
|
|
+ public void init() {
|
|
|
+ User root = userRepo.findByUsername("root");
|
|
|
+ if (root == null) {
|
|
|
+ Set<Authority> authorities = new HashSet<>();
|
|
|
+ authorities.add(new Authority(Authority.NAMES.ROLE_ADMIN.name()));
|
|
|
+ authorities.add(new Authority(Authority.NAMES.ROLE_USER.name()));
|
|
|
+ root = User.builder()
|
|
|
+ .nickname("管理员")
|
|
|
+ .username("root")
|
|
|
+ .password(new BCryptPasswordEncoder().encode("123456"))
|
|
|
+ .avatar(Constants.DEFAULT_AVATAR)
|
|
|
+ .enabled(true)
|
|
|
+ .authorities(authorities)
|
|
|
+ .build();
|
|
|
+ userRepo.save(root);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|