Search in sources :

Example 41 with User

use of com.axelor.auth.db.User in project axelor-open-suite by axelor.

the class ImportMove method getCompany.

private Company getCompany(Map<String, Object> values) {
    final Path path = (Path) values.get("__path__");
    String fileName = path.getFileName().toString();
    String registrationCode = fileName.substring(0, fileName.indexOf('F'));
    Company company = Beans.get(CompanyRepository.class).all().filter("self.partner.registrationCode = ?", registrationCode).fetchOne();
    if (company != null) {
        return company;
    } else if (Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null) != null) {
        return Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null);
    } else {
        return Beans.get(CompanyRepository.class).all().fetchOne();
    }
}
Also used : Path(java.nio.file.Path) Company(com.axelor.apps.base.db.Company) CompanyRepository(com.axelor.apps.base.db.repo.CompanyRepository) User(com.axelor.auth.db.User)

Example 42 with User

use of com.axelor.auth.db.User in project axelor-open-suite by axelor.

the class ECBCurrencyConversionService method validateAndGetRate.

@Override
public Float validateAndGetRate(int dayCount, Currency currencyFrom, Currency currencyTo, LocalDate date) throws AxelorException {
    try {
        HTTPResponse response = null;
        if (dayCount < 8) {
            HTTPClient httpclient = new HTTPClient();
            HTTPRequest request = new HTTPRequest();
            Map<String, Object> headers = new HashMap<>();
            headers.put("Accept", "application/json");
            request.setHeaders(headers);
            URL url = new URL(this.getUrlString(date, currencyFrom.getCode(), currencyTo.getCode()));
            // URL url = new URL(String.format(WSURL,currencyFrom.getCode()));
            LOG.trace("Currency conversion webservice URL: {}", new Object[] { url.toString() });
            request.setUrl(url);
            request.setMethod(HTTPMethod.GET);
            response = httpclient.execute(request);
            // JSONObject json = new JSONObject(response.getContentAsString());
            LOG.trace("Webservice response code: {}, response message: {}", response.getStatusCode(), response.getStatusMessage());
            if (response.getStatusCode() != 200)
                return -1f;
            if (response.getContentAsString().isEmpty()) {
                return this.validateAndGetRate((dayCount + 1), currencyFrom, currencyTo, date.minus(Period.ofDays(1)));
            } else {
                return this.getRateFromJson(currencyFrom, currencyTo, response);
            }
        } else {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, String.format(I18n.get(IExceptionMessage.CURRENCY_7), date.plus(Period.ofDays(1)), appBaseService.getTodayDate(Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null))));
        }
    } catch (Exception e) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CURRENCY_6));
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) HTTPRequest(wslite.http.HTTPRequest) User(com.axelor.auth.db.User) HashMap(java.util.HashMap) HTTPResponse(wslite.http.HTTPResponse) HTTPClient(wslite.http.HTTPClient) JSONObject(wslite.json.JSONObject) URL(java.net.URL) AxelorException(com.axelor.exception.AxelorException) JSONException(wslite.json.JSONException) MalformedURLException(java.net.MalformedURLException)

Example 43 with User

use of com.axelor.auth.db.User in project axelor-open-suite by axelor.

the class UserServiceImpl method generateRandomPasswordForUsers.

@Override
@Transactional(rollbackOn = { AxelorException.class, Exception.class })
public void generateRandomPasswordForUsers(List<Long> userIds) {
    AuthService authService = Beans.get(AuthService.class);
    LocalDateTime todayDateTime = Beans.get(AppBaseService.class).getTodayDateTime().toLocalDateTime();
    for (Long userId : userIds) {
        User user = userRepo.find(userId);
        String password = this.generateRandomPassword().toString();
        user.setTransientPassword(password);
        password = authService.encrypt(password);
        user.setPassword(password);
        user.setPasswordUpdatedOn(todayDateTime);
        userRepo.save(user);
    }
    // Update login date in session so that user changing own password doesn't get logged out.
    if (userIds.contains(getUserId())) {
        Session session = AuthUtils.getSubject().getSession();
        session.setAttribute("loginDate", todayDateTime);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) User(com.axelor.auth.db.User) AuthService(com.axelor.auth.AuthService) Session(org.apache.shiro.session.Session) Transactional(com.google.inject.persist.Transactional)

Example 44 with User

use of com.axelor.auth.db.User in project axelor-open-suite by axelor.

the class UserServiceImpl method verifyCurrentUserPassword.

@Override
public boolean verifyCurrentUserPassword(String password) {
    if (!StringUtils.isBlank(password)) {
        final User current = AuthUtils.getUser();
        final AuthService authService = AuthService.getInstance();
        if (authService.match(password, current.getPassword())) {
            return true;
        }
    }
    return false;
}
Also used : User(com.axelor.auth.db.User) AuthService(com.axelor.auth.AuthService)

Example 45 with User

use of com.axelor.auth.db.User in project axelor-open-suite by axelor.

the class UserServiceImpl method changeUserPassword.

@Override
public User changeUserPassword(User user, Map<String, Object> values) throws ClassNotFoundException, InstantiationException, IllegalAccessException, MessagingException, IOException, AxelorException {
    Preconditions.checkNotNull(user, I18n.get("User cannot be null."));
    Preconditions.checkNotNull(values, I18n.get("User context cannot be null."));
    final String oldPassword = (String) values.get("oldPassword");
    final String newPassword = (String) values.get("newPassword");
    final String chkPassword = (String) values.get("chkPassword");
    // no password change
    if (StringUtils.isBlank(newPassword)) {
        return user;
    }
    if (StringUtils.isBlank(oldPassword)) {
        throw new ValidationException(I18n.get("Current user password is not provided."));
    }
    if (!newPassword.equals(chkPassword)) {
        throw new ValidationException(I18n.get("Confirm password doesn't match with new password."));
    }
    if (!matchPasswordPattern(newPassword)) {
        throw new ValidationException(I18n.get(PATTERN_DESCRIPTION));
    }
    final User current = AuthUtils.getUser();
    final AuthService authService = AuthService.getInstance();
    if (!authService.match(oldPassword, current.getPassword())) {
        throw new ValidationException(I18n.get("Current user password is wrong."));
    }
    user.setTransientPassword(newPassword);
    return user;
}
Also used : ValidationException(javax.validation.ValidationException) User(com.axelor.auth.db.User) AuthService(com.axelor.auth.AuthService)

Aggregations

User (com.axelor.auth.db.User)157 AxelorException (com.axelor.exception.AxelorException)35 Employee (com.axelor.apps.hr.db.Employee)28 ArrayList (java.util.ArrayList)25 HashMap (java.util.HashMap)25 Transactional (com.google.inject.persist.Transactional)24 LocalDate (java.time.LocalDate)23 Filter (com.axelor.rpc.filter.Filter)22 BigDecimal (java.math.BigDecimal)22 ClientViewService (com.axelor.apps.portal.service.ClientViewService)20 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)17 List (java.util.List)17 Map (java.util.Map)16 TimesheetLine (com.axelor.apps.hr.db.TimesheetLine)12 LocalDateTime (java.time.LocalDateTime)12 Company (com.axelor.apps.base.db.Company)11 Partner (com.axelor.apps.base.db.Partner)11 Beans (com.axelor.inject.Beans)11 Inject (com.google.inject.Inject)11 Product (com.axelor.apps.base.db.Product)9