use of org.summerb.webappboilerplate.security.ve.RegistrationAlreadyRequestedValidationError 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);
}
}
Aggregations