Pārlūkot izejas kodu

changed userService (src/main/service) to also create default profile and account details

Jonathan Hinds 5 gadus atpakaļ
vecāks
revīzija
9fa281b3ea

+ 31
- 1
src/main/java/rocks/zipcode/io/service/UserService.java Parādīt failu

@@ -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;

+ 4
- 2
src/main/java/rocks/zipcode/io/web/rest/AccountResource.java Parādīt failu

@@ -3,6 +3,7 @@ package rocks.zipcode.io.web.rest;
3 3
 import com.codahale.metrics.annotation.Timed;
4 4
 
5 5
 import rocks.zipcode.io.domain.User;
6
+import rocks.zipcode.io.repository.ProfileRepository;
6 7
 import rocks.zipcode.io.repository.UserRepository;
7 8
 import rocks.zipcode.io.security.SecurityUtils;
8 9
 import rocks.zipcode.io.service.MailService;
@@ -78,6 +79,7 @@ public class AccountResource {
78 79
         if (!user.isPresent()) {
79 80
             throw new InternalServerErrorException("No user was found for this activation key");
80 81
         }
82
+        //consider adding profile and account details here
81 83
     }
82 84
 
83 85
     /**
@@ -126,8 +128,8 @@ public class AccountResource {
126 128
         if (!user.isPresent()) {
127 129
             throw new InternalServerErrorException("User could not be found");
128 130
         }
129
-        userService.updateUser(userDTO.getFirstName(), userDTO.getLastName(), userDTO.getEmail(),
130
-            userDTO.getLangKey(), userDTO.getImageUrl());
131
+
132
+        userService.updateUser(userDTO.getFirstName(), userDTO.getLastName(), userDTO.getEmail(), userDTO.getLangKey(), userDTO.getImageUrl());
131 133
     }
132 134
 
133 135
     /**