use of org.summerb.webappboilerplate.security.dto.UserStatus in project summerb by skarpushin.
the class UsersServiceFacadeImpl method registerUser.
@Transactional(rollbackFor = Throwable.class)
@Override
public User registerUser(Registration registration) throws FieldValidationException {
try {
Preconditions.checkArgument(registration != null, "Registration param must be not null");
// Validate display name
validateRegistration(registration);
// Validate user status
UserStatus userStatus = getUserStatusByEmail(registration.getEmail());
if (userStatus == UserStatus.AwaitingActivation) {
throw new FieldValidationException(new RegistrationAlreadyRequestedValidationError());
}
// Create user
User user = null;
if (userStatus == UserStatus.Provisioned) {
user = userService.getUserByEmail(registration.getEmail());
user.setDisplayName(registration.getDisplayName());
user.setLocale(CurrentRequestUtils.getLocale().toString());
user.setTimeZone(TimeZone.getDefault().getID());
userService.updateUser(user);
} else {
user = new User();
user.setEmail(registration.getEmail());
user.setDisplayName(registration.getDisplayName());
user.setLocale(CurrentRequestUtils.getLocale().toString());
user.setTimeZone(TimeZone.getDefault().getID());
user = userService.createUser(user);
}
// Create password
passwordService.setUserPassword(user.getUuid(), registration.getPassword());
// Create user account permissions
permissionService.grantPermission(SecurityConstants.DOMAIN, user.getUuid(), null, SecurityConstants.MARKER_AWAITING_ACTIVATION);
runUserRegisteredHandler(user);
//
return user;
} catch (UserNotFoundException e) {
throw new UserServiceUnexpectedException("User was just created, but not found", e);
} catch (Throwable t) {
Throwables.throwIfInstanceOf(t, FieldValidationException.class);
throw new RuntimeException("Unexpected error while registering user", t);
}
}
use of org.summerb.webappboilerplate.security.dto.UserStatus in project summerb by skarpushin.
the class UsersServiceFacadeImpl method validateUserIsEligableForPasswordReset.
protected void validateUserIsEligableForPasswordReset(String email) throws FieldValidationException {
ValidationContext ctx = new ValidationContext();
if (!ctx.validateEmailFormat(email, User.FN_EMAIL)) {
throw new FieldValidationException(ctx.getErrors());
}
// now see if this user exists
UserStatus userStatus = getUserStatusByEmail(email);
if (userStatus == UserStatus.NotExists || userStatus == UserStatus.Provisioned) {
throw new FieldValidationException(new RegistrationRequiredValidationError());
}
// Sanity check
if (userStatus != UserStatus.NormalUser && userStatus != UserStatus.AwaitingActivation) {
throw new RuntimeException("Password Reset scenario is not supported for user whose status is: " + userStatus);
}
}
Aggregations