|
@@ -1,9 +1,13 @@
|
1
|
1
|
package rocks.zipcode.io.service;
|
2
|
2
|
|
3
|
3
|
import rocks.zipcode.io.config.Constants;
|
|
4
|
+import rocks.zipcode.io.domain.AccountDetails;
|
4
|
5
|
import rocks.zipcode.io.domain.Authority;
|
|
6
|
+import rocks.zipcode.io.domain.Profile;
|
5
|
7
|
import rocks.zipcode.io.domain.User;
|
|
8
|
+import rocks.zipcode.io.repository.AccountDetailsRepository;
|
6
|
9
|
import rocks.zipcode.io.repository.AuthorityRepository;
|
|
10
|
+import rocks.zipcode.io.repository.ProfileRepository;
|
7
|
11
|
import rocks.zipcode.io.repository.UserRepository;
|
8
|
12
|
import rocks.zipcode.io.security.AuthoritiesConstants;
|
9
|
13
|
import rocks.zipcode.io.security.SecurityUtils;
|
|
@@ -37,17 +41,23 @@ public class UserService {
|
37
|
41
|
|
38
|
42
|
private final UserRepository userRepository;
|
39
|
43
|
|
|
44
|
+ private final ProfileRepository profileRepository;
|
|
45
|
+
|
|
46
|
+ private final AccountDetailsRepository accountDetailsRepository;
|
|
47
|
+
|
40
|
48
|
private final PasswordEncoder passwordEncoder;
|
41
|
49
|
|
42
|
50
|
private final AuthorityRepository authorityRepository;
|
43
|
51
|
|
44
|
52
|
private final CacheManager cacheManager;
|
45
|
53
|
|
46
|
|
- public UserService(UserRepository userRepository, PasswordEncoder passwordEncoder, AuthorityRepository authorityRepository, CacheManager cacheManager) {
|
|
54
|
+ public UserService(UserRepository userRepository, AccountDetailsRepository accountDetailsRepository, ProfileRepository profileRepository, PasswordEncoder passwordEncoder, AuthorityRepository authorityRepository, CacheManager cacheManager) {
|
47
|
55
|
this.userRepository = userRepository;
|
48
|
56
|
this.passwordEncoder = passwordEncoder;
|
49
|
57
|
this.authorityRepository = authorityRepository;
|
50
|
58
|
this.cacheManager = cacheManager;
|
|
59
|
+ this.profileRepository = profileRepository;
|
|
60
|
+ this.accountDetailsRepository = accountDetailsRepository;
|
51
|
61
|
}
|
52
|
62
|
|
53
|
63
|
public Optional<User> activateRegistration(String key) {
|
|
@@ -139,6 +149,18 @@ public class UserService {
|
139
|
149
|
user.setLastName(userDTO.getLastName());
|
140
|
150
|
user.setEmail(userDTO.getEmail().toLowerCase());
|
141
|
151
|
user.setImageUrl(userDTO.getImageUrl());
|
|
152
|
+
|
|
153
|
+ //create default profile
|
|
154
|
+ Profile profile = new Profile();
|
|
155
|
+ profile.setBio("");
|
|
156
|
+ profile.setUserProfile(user);
|
|
157
|
+ profile.setAccessible(true);
|
|
158
|
+
|
|
159
|
+ //create default account details
|
|
160
|
+ AccountDetails accountDetails = new AccountDetails();
|
|
161
|
+ accountDetails.setSecurityQuestion("");
|
|
162
|
+ accountDetails.setSecurityAnswer("");
|
|
163
|
+
|
142
|
164
|
if (userDTO.getLangKey() == null) {
|
143
|
165
|
user.setLangKey(Constants.DEFAULT_LANGUAGE); // default language
|
144
|
166
|
} else {
|
|
@@ -157,7 +179,15 @@ public class UserService {
|
157
|
179
|
.collect(Collectors.toSet());
|
158
|
180
|
user.setAuthorities(authorities);
|
159
|
181
|
}
|
|
182
|
+
|
160
|
183
|
userRepository.save(user);
|
|
184
|
+
|
|
185
|
+ //save the default profile
|
|
186
|
+ profileRepository.save(profile);
|
|
187
|
+
|
|
188
|
+ //save the default account details
|
|
189
|
+ accountDetailsRepository.save(accountDetails);
|
|
190
|
+
|
161
|
191
|
this.clearUserCaches(user);
|
162
|
192
|
log.debug("Created Information for User: {}", user);
|
163
|
193
|
return user;
|