Search in sources :

Example 1 with CredentialsInfo

use of org.hisp.dhis.user.CredentialsInfo in project dhis2-core by dhis2.

the class ValidateUserAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    if (username != null) {
        UserCredentials match = userService.getUserCredentialsByUsername(username);
        if (match != null && (id == null || match.getId() != id)) {
            message = i18n.getString("username_in_use");
            return ERROR;
        }
    }
    if (openId != null) {
        UserCredentials match = userService.getUserCredentialsByOpenId(openId);
        if (match != null && (id == null || match.getId() != id)) {
            message = i18n.getString("openid_in_use");
            return ERROR;
        }
    }
    if (ldapId != null) {
        UserCredentials match = userService.getUserCredentialsByLdapId(ldapId);
        if (match != null && (id == null || match.getId() != id)) {
            message = i18n.getString("ldap_in_use");
            return ERROR;
        }
    }
    if (inviteUsername != null) {
        UserCredentials match = userService.getUserCredentialsByUsername(inviteUsername);
        if (match != null && (id == null || match.getId() != id)) {
            message = i18n.getString("username_in_use");
            return ERROR;
        }
    }
    if (rawPassword != null && !rawPassword.isEmpty()) {
        PasswordValidationResult result;
        CredentialsInfo credentialsInfo = new CredentialsInfo(username, rawPassword, email, true);
        if (id != null) {
            User user = userService.getUser(id);
            if (user != null) {
                credentialsInfo = new CredentialsInfo(user.getUsername(), rawPassword, user.getEmail(), false);
            }
        }
        result = passwordValidationService.validate(credentialsInfo);
        if (!result.isValid()) {
            message = i18n.getString(result.getI18ErrorMessage());
            return ERROR;
        }
    }
    message = i18n.getString("everything_is_ok");
    return SUCCESS;
}
Also used : User(org.hisp.dhis.user.User) PasswordValidationResult(org.hisp.dhis.user.PasswordValidationResult) CredentialsInfo(org.hisp.dhis.user.CredentialsInfo) UserCredentials(org.hisp.dhis.user.UserCredentials)

Aggregations

CredentialsInfo (org.hisp.dhis.user.CredentialsInfo)1 PasswordValidationResult (org.hisp.dhis.user.PasswordValidationResult)1 User (org.hisp.dhis.user.User)1 UserCredentials (org.hisp.dhis.user.UserCredentials)1