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);
}
}
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;
}
Aggregations