Search in sources :

Example 11 with Transactional

use of com.peterphi.std.guice.database.annotation.Transactional in project stdlib by petergeneric.

the class UserDaoImpl method changeProfile.

@Transactional
public UserEntity changeProfile(final int id, final String name, final String email, final String dateFormat, final String timeZone) {
    final UserEntity account = getById(id);
    if (account != null) {
        if (dateFormat == null || timeZone == null)
            throw new IllegalArgumentException("Must specify dateFormat and timeZone!");
        account.setName(name);
        account.setEmail(email);
        account.setDateFormat(dateFormat);
        account.setTimeZone(timeZone);
        update(account);
        return account;
    } else {
        throw new IllegalArgumentException("No such user: " + id);
    }
}
Also used : UserEntity(com.peterphi.usermanager.db.entity.UserEntity) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 12 with Transactional

use of com.peterphi.std.guice.database.annotation.Transactional in project stdlib by petergeneric.

the class UserDaoImpl method login.

@Transactional
public UserEntity login(String email, String password) {
    final UserEntity account = getUserByEmail(email);
    if (account != null && account.isLocal()) {
        final boolean correct = BCrypt.verify(account.getPassword(), password.toCharArray());
        if (correct) {
            account.setLastLogin(new DateTime());
            update(account);
            return account;
        }
    }
    // User doesn't exist (or password is wrong)
    return null;
}
Also used : UserEntity(com.peterphi.usermanager.db.entity.UserEntity) DateTime(org.joda.time.DateTime) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 13 with Transactional

use of com.peterphi.std.guice.database.annotation.Transactional in project stdlib by petergeneric.

the class UserDaoImpl method loginBySessionReconnectKey.

@Transactional
public UserEntity loginBySessionReconnectKey(String key) {
    final UserEntity account = uniqueResult(new WebQuery().eq("local", true).eq("sessionReconnectKey", key));
    if (account != null) {
        log.info("Allowed login by session reconnect key for user: " + account.getEmail());
        account.setLastLogin(new DateTime());
        update(account);
    }
    return account;
}
Also used : WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) UserEntity(com.peterphi.usermanager.db.entity.UserEntity) DateTime(org.joda.time.DateTime) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 14 with Transactional

use of com.peterphi.std.guice.database.annotation.Transactional in project stdlib by petergeneric.

the class UserDaoImpl method registerRemote.

@Transactional
public int registerRemote(final String username, final String fullName) {
    if (userExists(username))
        throw new IllegalArgumentException("User '" + username + "' already exists!");
    final UserEntity account = new UserEntity();
    account.setLocal(false);
    account.setEmail(username);
    account.setName(fullName);
    // Won't allow password logins anyway, but we also set a value that won't match any BCrypt hash
    account.setPassword("NONE");
    account.setSessionReconnectKey(null);
    account.setTimeZone(CurrentUser.DEFAULT_TIMEZONE);
    account.setDateFormat(CurrentUser.DEFAULT_DATE_FORMAT_STRING);
    return save(account);
}
Also used : UserEntity(com.peterphi.usermanager.db.entity.UserEntity) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 15 with Transactional

use of com.peterphi.std.guice.database.annotation.Transactional in project stdlib by petergeneric.

the class RoleDaoImpl method getOrCreate.

@Transactional
public RoleEntity getOrCreate(final String id, final String caption) {
    RoleEntity existing = getById(id);
    if (existing == null) {
        existing = new RoleEntity();
        existing.setId(id);
        existing.setCaption(caption);
        save(existing);
    }
    return existing;
}
Also used : RoleEntity(com.peterphi.usermanager.db.entity.RoleEntity) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Aggregations

Transactional (com.peterphi.std.guice.database.annotation.Transactional)46 UserEntity (com.peterphi.usermanager.db.entity.UserEntity)13 WebQuery (com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery)11 TemplateCall (com.peterphi.std.guice.web.rest.templating.TemplateCall)9 RoleEntity (com.peterphi.usermanager.db.entity.RoleEntity)9 AuthConstraint (com.peterphi.std.guice.common.auth.annotations.AuthConstraint)8 OAuthServiceEntity (com.peterphi.usermanager.db.entity.OAuthServiceEntity)5 AuthenticationFailureException (com.peterphi.usermanager.guice.authentication.AuthenticationFailureException)5 OAuthSessionEntity (com.peterphi.usermanager.db.entity.OAuthSessionEntity)4 Test (org.junit.Test)4 ResourceInstanceEntity (com.peterphi.servicemanager.service.db.entity.ResourceInstanceEntity)3 ResourceTemplateEntity (com.peterphi.servicemanager.service.db.entity.ResourceTemplateEntity)3 Criteria (org.hibernate.Criteria)3 List (java.util.List)2 DateTime (org.joda.time.DateTime)2 Timer (com.codahale.metrics.Timer)1 Inject (com.google.inject.Inject)1 Singleton (com.google.inject.Singleton)1 ServiceInstanceEntity (com.peterphi.servicemanager.service.db.entity.ServiceInstanceEntity)1 ResourceNetworkConfig (com.peterphi.servicemanager.service.guice.ResourceNetworkConfig)1