Search in sources :

Example 1 with UserService

use of com.axelor.apps.base.service.user.UserService in project axelor-open-suite by axelor.

the class UserController method validatePassword.

public void validatePassword(ActionRequest request, ActionResponse response) {
    try {
        UserService userService = Beans.get(UserService.class);
        String newPassword = MoreObjects.firstNonNull((String) request.getContext().get("newPassword"), "");
        boolean valid = userService.matchPasswordPattern(newPassword);
        response.setAttr("passwordPatternDescriptionLabel", "hidden", valid);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : UserService(com.axelor.apps.base.service.user.UserService) ValidationException(javax.validation.ValidationException)

Example 2 with UserService

use of com.axelor.apps.base.service.user.UserService in project axelor-open-suite by axelor.

the class UserController method validate.

public void validate(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        User user = request.getContext().asType(User.class);
        Map<String, String> errors = ModelTool.getUniqueErrors(user, UNIQUE_MESSAGES);
        if (!errors.isEmpty()) {
            response.setErrors(errors);
            return;
        }
        UserService userService = Beans.get(UserService.class);
        user = userService.changeUserPassword(user, context);
        response.setValue("transientPassword", user.getTransientPassword());
    } catch (ValidationException e) {
        response.setError(e.getMessage());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) User(com.axelor.auth.db.User) ValidationException(javax.validation.ValidationException) UserService(com.axelor.apps.base.service.user.UserService) ValidationException(javax.validation.ValidationException)

Example 3 with UserService

use of com.axelor.apps.base.service.user.UserService in project axelor-open-suite by axelor.

the class UserController method generateRandomPassword.

public void generateRandomPassword(ActionRequest request, ActionResponse response) {
    try {
        UserService userService = Beans.get(UserService.class);
        CharSequence password = userService.generateRandomPassword();
        response.setValue("newPassword", password);
        response.setValue("chkPassword", password);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : UserService(com.axelor.apps.base.service.user.UserService) ValidationException(javax.validation.ValidationException)

Aggregations

UserService (com.axelor.apps.base.service.user.UserService)3 ValidationException (javax.validation.ValidationException)3 User (com.axelor.auth.db.User)1 Context (com.axelor.rpc.Context)1