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