Search in sources :

Example 1 with AccountPreferences

use of org.jbei.ice.storage.model.AccountPreferences in project ice by JBEI.

the class AccountPreferencesDAO method getAccountPreferences.

/**
     * Retrieve the {@link AccountPreferences} of the given {@link Account}.
     *
     * @param account account whose preferences are being retrieved
     * @return retrieved AccountPreferences
     * @throws DAOException
     */
public AccountPreferences getAccountPreferences(Account account) {
    try {
        CriteriaQuery<AccountPreferences> query = getBuilder().createQuery(AccountPreferences.class);
        Root<AccountPreferences> from = query.from(AccountPreferences.class);
        query.where(getBuilder().equal(from.get("account"), account));
        return currentSession().createQuery(query).uniqueResult();
    } catch (HibernateException e) {
        Logger.error(e);
        throw new DAOException("Failed to get AccountPreferences by Account: " + account.getFullName(), e);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) AccountPreferences(org.jbei.ice.storage.model.AccountPreferences)

Example 2 with AccountPreferences

use of org.jbei.ice.storage.model.AccountPreferences in project ice by JBEI.

the class AccountController method authenticate.

/**
     * Authenticate a user in the database.
     * <p>
     * Using the {@link org.jbei.ice.lib.account.authentication.IAuthentication} specified in the
     * settings file, authenticate the user, and return the sessionData
     *
     * @param login
     * @param password
     * @param ip       IP Address of the user.
     * @return the account identifier (email) on a successful login, otherwise {@code null}
     */
protected Account authenticate(final String login, final String password, final String ip) {
    final IAuthentication authentication = new LocalAuthentication();
    String email;
    try {
        email = authentication.authenticates(login.trim(), password);
        if (email == null) {
            loginFailureCooldown();
            return null;
        }
    } catch (final AuthenticationException e2) {
        loginFailureCooldown();
        return null;
    }
    Account account = dao.getByEmail(email);
    if (account == null)
        return null;
    AccountPreferences accountPreferences = accountPreferencesDAO.getAccountPreferences(account);
    if (accountPreferences == null) {
        accountPreferences = new AccountPreferences();
        accountPreferences.setAccount(account);
        accountPreferencesDAO.create(accountPreferences);
    }
    // add to public groups
    List<Group> groups = groupDAO.getGroupsBy(GroupType.PUBLIC, true);
    try {
        if (groups != null) {
            for (Group group : groups) {
                if (!account.getGroups().contains(group)) {
                    account.getGroups().add(group);
                }
            }
            dao.update(account);
        }
    } catch (Exception e) {
        Logger.error(e);
    }
    account.setIp(ip);
    account.setLastLoginTime(Calendar.getInstance().getTime());
    account = save(account);
    UserSessions.createNewSessionForUser(account.getEmail());
    return account;
}
Also used : Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) AuthenticationException(org.jbei.ice.lib.account.authentication.AuthenticationException) LocalAuthentication(org.jbei.ice.lib.account.authentication.LocalAuthentication) IAuthentication(org.jbei.ice.lib.account.authentication.IAuthentication) AuthenticationException(org.jbei.ice.lib.account.authentication.AuthenticationException) PermissionException(org.jbei.ice.lib.access.PermissionException) AccountPreferences(org.jbei.ice.storage.model.AccountPreferences)

Aggregations

AccountPreferences (org.jbei.ice.storage.model.AccountPreferences)2 HibernateException (org.hibernate.HibernateException)1 PermissionException (org.jbei.ice.lib.access.PermissionException)1 AuthenticationException (org.jbei.ice.lib.account.authentication.AuthenticationException)1 IAuthentication (org.jbei.ice.lib.account.authentication.IAuthentication)1 LocalAuthentication (org.jbei.ice.lib.account.authentication.LocalAuthentication)1 DAOException (org.jbei.ice.storage.DAOException)1 Account (org.jbei.ice.storage.model.Account)1 Group (org.jbei.ice.storage.model.Group)1