use of org.motechproject.security.exception.ServerUrlIsEmptyException in project motech by motech.
the class UserController method saveUser.
/**
* Creates user
*
* @param user user to be created
*/
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/users/create", method = RequestMethod.POST)
public void saveUser(@RequestBody UserDto user) {
int passLength = Math.max(GENERATED_PASSWORD_MIN_LENGTH, settingService.getMinPasswordLength());
String password = user.isGeneratePassword() ? RandomStringUtils.randomAlphanumeric(passLength) : user.getPassword();
motechUserService.register(user.getUserName(), password, user.getEmail(), "", user.getRoles(), user.getLocale());
try {
if (user.isGeneratePassword() && StringUtils.isNotBlank(user.getEmail())) {
motechUserService.sendLoginInformation(user.getUserName());
}
} catch (UserNotFoundException | NonAdminUserException | ServerUrlIsEmptyException ex) {
throw new MailSendException("Email was not sent", ex);
}
}
Aggregations