15
15
import org .ays .auth .util .exception .AysUserAlreadyExistsByEmailAddressException ;
16
16
import org .ays .auth .util .exception .AysUserAlreadyExistsByPhoneNumberException ;
17
17
import org .ays .common .model .AysPhoneNumber ;
18
+ import org .ays .common .util .AysRandomUtil ;
18
19
import org .ays .institution .model .Institution ;
19
20
import org .springframework .stereotype .Service ;
20
21
import org .springframework .transaction .annotation .Transactional ;
21
22
22
23
import java .util .List ;
23
24
import java .util .Set ;
24
- import java .util .UUID ;
25
25
26
26
/**
27
27
* Service implementation for creating new users in the system.
@@ -58,9 +58,9 @@ class AysUserCreateServiceImpl implements AysUserCreateService {
58
58
* </p>
59
59
*
60
60
* @param createRequest The request object containing data for the new user.
61
- * @throws AysUserAlreadyExistsByEmailAddressException if the email address is already associated with another user.
62
- * @throws AysUserAlreadyExistsByPhoneNumberException if the phone number is already associated with another user.
63
- * @throws AysRolesNotExistException if any of the provided role IDs do not exist.
61
+ * @throws AysUserAlreadyExistsByEmailAddressException if the email address is already associated with another user.
62
+ * @throws AysUserAlreadyExistsByPhoneNumberException if the phone number is already associated with another user.
63
+ * @throws AysRolesNotExistException if any of the provided role IDs do not exist.
64
64
*/
65
65
@ Override
66
66
public void create (final AysUserCreateRequest createRequest ) {
@@ -78,10 +78,18 @@ public void create(final AysUserCreateRequest createRequest) {
78
78
this .validateRolesAndSet (user , createRequest .getRoleIds ());
79
79
80
80
user .activate ();
81
- user .setInstitution (Institution .builder ().id (identity .getInstitutionId ()).build ());
82
- user .setPassword (AysUser .Password .builder ().value (UUID .randomUUID ().toString ()).build ());
83
-
84
- AysUser savedUser = userSavePort .save (user );
81
+ user .setInstitution (
82
+ Institution .builder ()
83
+ .id (identity .getInstitutionId ())
84
+ .build ()
85
+ );
86
+ user .setPassword (
87
+ AysUser .Password .builder ()
88
+ .value (AysRandomUtil .generateText (15 ))
89
+ .build ()
90
+ );
91
+
92
+ final AysUser savedUser = userSavePort .save (user );
85
93
86
94
userMailService .sendPasswordCreateEmail (savedUser );
87
95
}
0 commit comments