Browse Source

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

Jonathan Hinds 5 years ago
parent
commit
9fa281b3ea

+ 31
- 1
src/main/java/rocks/zipcode/io/service/UserService.java View File

1
 package rocks.zipcode.io.service;
1
 package rocks.zipcode.io.service;
2
 
2
 
3
 import rocks.zipcode.io.config.Constants;
3
 import rocks.zipcode.io.config.Constants;
4
+import rocks.zipcode.io.domain.AccountDetails;
4
 import rocks.zipcode.io.domain.Authority;
5
 import rocks.zipcode.io.domain.Authority;
6
+import rocks.zipcode.io.domain.Profile;
5
 import rocks.zipcode.io.domain.User;
7
 import rocks.zipcode.io.domain.User;
8
+import rocks.zipcode.io.repository.AccountDetailsRepository;
6
 import rocks.zipcode.io.repository.AuthorityRepository;
9
 import rocks.zipcode.io.repository.AuthorityRepository;
10
+import rocks.zipcode.io.repository.ProfileRepository;
7
 import rocks.zipcode.io.repository.UserRepository;
11
 import rocks.zipcode.io.repository.UserRepository;
8
 import rocks.zipcode.io.security.AuthoritiesConstants;
12
 import rocks.zipcode.io.security.AuthoritiesConstants;
9
 import rocks.zipcode.io.security.SecurityUtils;
13
 import rocks.zipcode.io.security.SecurityUtils;
37
 
41
 
38
     private final UserRepository userRepository;
42
     private final UserRepository userRepository;
39
 
43
 
44
+    private final ProfileRepository profileRepository;
45
+
46
+    private final AccountDetailsRepository accountDetailsRepository;
47
+
40
     private final PasswordEncoder passwordEncoder;
48
     private final PasswordEncoder passwordEncoder;
41
 
49
 
42
     private final AuthorityRepository authorityRepository;
50
     private final AuthorityRepository authorityRepository;
43
 
51
 
44
     private final CacheManager cacheManager;
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
         this.userRepository = userRepository;
55
         this.userRepository = userRepository;
48
         this.passwordEncoder = passwordEncoder;
56
         this.passwordEncoder = passwordEncoder;
49
         this.authorityRepository = authorityRepository;
57
         this.authorityRepository = authorityRepository;
50
         this.cacheManager = cacheManager;
58
         this.cacheManager = cacheManager;
59
+        this.profileRepository = profileRepository;
60
+        this.accountDetailsRepository = accountDetailsRepository;
51
     }
61
     }
52
 
62
 
53
     public Optional<User> activateRegistration(String key) {
63
     public Optional<User> activateRegistration(String key) {
139
         user.setLastName(userDTO.getLastName());
149
         user.setLastName(userDTO.getLastName());
140
         user.setEmail(userDTO.getEmail().toLowerCase());
150
         user.setEmail(userDTO.getEmail().toLowerCase());
141
         user.setImageUrl(userDTO.getImageUrl());
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
         if (userDTO.getLangKey() == null) {
164
         if (userDTO.getLangKey() == null) {
143
             user.setLangKey(Constants.DEFAULT_LANGUAGE); // default language
165
             user.setLangKey(Constants.DEFAULT_LANGUAGE); // default language
144
         } else {
166
         } else {
157
                 .collect(Collectors.toSet());
179
                 .collect(Collectors.toSet());
158
             user.setAuthorities(authorities);
180
             user.setAuthorities(authorities);
159
         }
181
         }
182
+
160
         userRepository.save(user);
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
         this.clearUserCaches(user);
191
         this.clearUserCaches(user);
162
         log.debug("Created Information for User: {}", user);
192
         log.debug("Created Information for User: {}", user);
163
         return user;
193
         return user;

+ 4
- 2
src/main/java/rocks/zipcode/io/web/rest/AccountResource.java View File

3
 import com.codahale.metrics.annotation.Timed;
3
 import com.codahale.metrics.annotation.Timed;
4
 
4
 
5
 import rocks.zipcode.io.domain.User;
5
 import rocks.zipcode.io.domain.User;
6
+import rocks.zipcode.io.repository.ProfileRepository;
6
 import rocks.zipcode.io.repository.UserRepository;
7
 import rocks.zipcode.io.repository.UserRepository;
7
 import rocks.zipcode.io.security.SecurityUtils;
8
 import rocks.zipcode.io.security.SecurityUtils;
8
 import rocks.zipcode.io.service.MailService;
9
 import rocks.zipcode.io.service.MailService;
78
         if (!user.isPresent()) {
79
         if (!user.isPresent()) {
79
             throw new InternalServerErrorException("No user was found for this activation key");
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
         if (!user.isPresent()) {
128
         if (!user.isPresent()) {
127
             throw new InternalServerErrorException("User could not be found");
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
     /**