Merge pull request #491 from Nayan/MIFOSX-428CP
Update for 'set new password' during user creation
This commit is contained in:
+2
-1
@@ -29,6 +29,7 @@ import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
||||
import org.mifosplatform.infrastructure.security.domain.PlatformUser;
|
||||
import org.mifosplatform.infrastructure.security.exception.NoAuthorizationException;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformPasswordEncoder;
|
||||
import org.mifosplatform.infrastructure.security.service.RandomPasswordGenerator;
|
||||
import org.mifosplatform.organisation.office.domain.Office;
|
||||
import org.mifosplatform.organisation.staff.domain.Staff;
|
||||
import org.slf4j.Logger;
|
||||
@@ -95,7 +96,7 @@ public class AppUser extends AbstractPersistable<Long> implements PlatformUser {
|
||||
final String username = command.stringValueOfParameterNamed("username");
|
||||
String password = command.stringValueOfParameterNamed("password");
|
||||
if (StringUtils.isBlank(password)) {
|
||||
password = "autogenerate";
|
||||
password = new RandomPasswordGenerator(13).generate();
|
||||
}
|
||||
|
||||
boolean userEnabled = true;
|
||||
|
||||
+5
-8
@@ -8,7 +8,6 @@ package org.mifosplatform.useradministration.domain;
|
||||
import org.mifosplatform.infrastructure.core.domain.EmailDetail;
|
||||
import org.mifosplatform.infrastructure.core.service.PlatformEmailService;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformPasswordEncoder;
|
||||
import org.mifosplatform.infrastructure.security.service.RandomPasswordGenerator;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -30,25 +29,23 @@ public class JpaUserDomainService implements UserDomainService {
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void create(final AppUser appUser) {
|
||||
public void create(final AppUser appUser , final Boolean sendPasswordToEmail) {
|
||||
|
||||
generateKeyUsedForPasswordSalting(appUser);
|
||||
|
||||
String unencodedPassword = appUser.getPassword();
|
||||
if (org.apache.commons.lang.StringUtils.isBlank(unencodedPassword) || "autogenerate".equalsIgnoreCase(unencodedPassword)) {
|
||||
unencodedPassword = new RandomPasswordGenerator(13).generate();
|
||||
appUser.updatePassword(unencodedPassword);
|
||||
}
|
||||
|
||||
final String encodePassword = this.applicationPasswordEncoder.encode(appUser);
|
||||
appUser.updatePassword(encodePassword);
|
||||
|
||||
this.userRepository.save(appUser);
|
||||
|
||||
final EmailDetail emailDetail = new EmailDetail(appUser.getFirstname(), appUser.getFirstname(), appUser.getEmail(),
|
||||
if (sendPasswordToEmail.booleanValue()){
|
||||
final EmailDetail emailDetail = new EmailDetail(appUser.getFirstname(), appUser.getFirstname(), appUser.getEmail(),
|
||||
appUser.getUsername());
|
||||
|
||||
this.emailService.sendToUserAccount(emailDetail, unencodedPassword);
|
||||
this.emailService.sendToUserAccount(emailDetail, unencodedPassword);
|
||||
}
|
||||
}
|
||||
|
||||
private void generateKeyUsedForPasswordSalting(final AppUser appUser) {
|
||||
|
||||
+1
-1
@@ -7,5 +7,5 @@ package org.mifosplatform.useradministration.domain;
|
||||
|
||||
public interface UserDomainService {
|
||||
|
||||
void create(AppUser appUser);
|
||||
void create(AppUser appUser,Boolean sendPasswordToEmail);
|
||||
}
|
||||
|
||||
+2
-1
@@ -83,7 +83,8 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
|
||||
final Set<Role> allRoles = assembleSetOfRoles(roles);
|
||||
|
||||
final AppUser appUser = AppUser.fromJson(userOffice, allRoles, command);
|
||||
this.userDomainService.create(appUser);
|
||||
final Boolean sendPasswordToEmail = command.booleanObjectValueOfParameterNamed("sendPasswordToEmail");
|
||||
this.userDomainService.create(appUser,sendPasswordToEmail);
|
||||
|
||||
return new CommandProcessingResultBuilder() //
|
||||
.withCommandId(command.commandId()) //
|
||||
|
||||
+18
-3
@@ -32,7 +32,7 @@ public final class UserDataValidator {
|
||||
* The parameters supported for this command.
|
||||
*/
|
||||
private final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("username", "firstname", "lastname", "password",
|
||||
"repeatPassword", "email", "officeId", "notSelectedRoles", "roles"));
|
||||
"repeatPassword", "email", "officeId", "notSelectedRoles", "roles", "sendPasswordToEmail"));
|
||||
|
||||
private final FromJsonHelper fromApiJsonHelper;
|
||||
|
||||
@@ -61,8 +61,23 @@ public final class UserDataValidator {
|
||||
final String lastname = fromApiJsonHelper.extractStringNamed("lastname", element);
|
||||
baseDataValidator.reset().parameter("lastname").value(lastname).notBlank().notExceedingLengthOf(100);
|
||||
|
||||
final String email = fromApiJsonHelper.extractStringNamed("email", element);
|
||||
baseDataValidator.reset().parameter("email").value(email).notBlank().notExceedingLengthOf(100);
|
||||
final Boolean sendPasswordToEmail = this.fromApiJsonHelper.extractBooleanNamed("sendPasswordToEmail", element);
|
||||
if (sendPasswordToEmail != null) {
|
||||
if (sendPasswordToEmail.booleanValue()) {
|
||||
final String email = fromApiJsonHelper.extractStringNamed("email", element);
|
||||
baseDataValidator.reset().parameter("email").value(email).notBlank().notExceedingLengthOf(100);
|
||||
}
|
||||
else{
|
||||
final String password = fromApiJsonHelper.extractStringNamed("password", element);
|
||||
final String repeatPassword = fromApiJsonHelper.extractStringNamed("repeatPassword", element);
|
||||
baseDataValidator.reset().parameter("password").value(password).notBlank().notExceedingLengthOf(50);
|
||||
if (StringUtils.isNotBlank(password)) {
|
||||
baseDataValidator.reset().parameter("password").value(password).equalToParameter("repeatPassword", repeatPassword);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
baseDataValidator.reset().parameter("sendPasswordToEmail").value(sendPasswordToEmail).trueOrFalseRequired(false);
|
||||
}
|
||||
|
||||
final Long officeId = fromApiJsonHelper.extractLongNamed("officeId", element);
|
||||
baseDataValidator.reset().parameter("officeId").value(officeId).notNull().integerGreaterThanZero();
|
||||
|
||||
Reference in New Issue
Block a user