Search in sources :

Example 1 with ServerUrlIsEmptyException

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);
    }
}
Also used : UserNotFoundException(org.motechproject.security.exception.UserNotFoundException) ServerUrlIsEmptyException(org.motechproject.security.exception.ServerUrlIsEmptyException) MailSendException(org.springframework.mail.MailSendException) NonAdminUserException(org.motechproject.security.exception.NonAdminUserException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

NonAdminUserException (org.motechproject.security.exception.NonAdminUserException)1 ServerUrlIsEmptyException (org.motechproject.security.exception.ServerUrlIsEmptyException)1 UserNotFoundException (org.motechproject.security.exception.UserNotFoundException)1 MailSendException (org.springframework.mail.MailSendException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1