use of org.craftercms.studio.api.v2.dal.QueryParameterNames.USER_ID in project studio by craftercms.
the class UserServiceInternalImpl method setUserPassword.
@RetryingOperation
@Override
public boolean setUserPassword(String username, String newPassword) throws UserNotFoundException, UserExternallyManagedException, ServiceLayerException {
if (!userExists(-1, username)) {
throw new UserNotFoundException();
} else {
if (verifyPasswordRequirements(newPassword)) {
Map<String, Object> params = new HashMap<String, Object>();
params.put(USER_ID, -1);
params.put(USERNAME, username);
try {
User user = userDao.getUserByIdOrUsername(params);
if (user.isExternallyManaged()) {
throw new UserExternallyManagedException();
} else {
String hashedPassword = CryptoUtils.hashPassword(newPassword);
params = new HashMap<String, Object>();
params.put(USERNAME, username);
params.put(PASSWORD, hashedPassword);
userDao.setUserPassword(params);
return true;
}
} catch (Exception e) {
throw new ServiceLayerException("Unknown database error", e);
}
} else {
throw new PasswordRequirementsFailedException("User password does not fulfill requirements");
}
}
}
use of org.craftercms.studio.api.v2.dal.QueryParameterNames.USER_ID in project studio by craftercms.
the class UserServiceInternalImpl method updateUser.
@RetryingOperation
@Override
public void updateUser(User user) throws UserNotFoundException, ServiceLayerException {
long userId = user.getId();
String username = user.getUsername() != null ? user.getUsername() : StringUtils.EMPTY;
User oldUser = getUserByIdOrUsername(userId, username);
Map<String, Object> params = new HashMap<>();
params.put(USER_ID, oldUser.getId());
params.put(FIRST_NAME, user.getFirstName());
params.put(LAST_NAME, user.getLastName());
params.put(EMAIL, user.getEmail());
params.put(TIMEZONE, StringUtils.EMPTY);
params.put(LOCALE, StringUtils.EMPTY);
try {
userDao.updateUser(params);
} catch (Exception e) {
throw new ServiceLayerException("Unknown database error", e);
}
}
use of org.craftercms.studio.api.v2.dal.QueryParameterNames.USER_ID in project studio by craftercms.
the class UserServiceInternalImpl method getUserGroups.
@Override
public List<Group> getUserGroups(long userId, String username) throws UserNotFoundException, ServiceLayerException {
if (!userExists(userId, username)) {
throw new UserNotFoundException("No user found for username '" + username + "' or id '" + userId + "'");
}
Map<String, Object> params = new HashMap<>();
params.put(USER_ID, userId);
params.put(USERNAME, username);
try {
return userDao.getUserGroups(params);
} catch (Exception e) {
throw new ServiceLayerException("Unknown database error", e);
}
}
use of org.craftercms.studio.api.v2.dal.QueryParameterNames.USER_ID in project studio by craftercms.
the class UserServiceInternalImpl method getUserByIdOrUsername.
@Override
public User getUserByIdOrUsername(long userId, String username) throws ServiceLayerException, UserNotFoundException {
Map<String, Object> params = new HashMap<>();
params.put(USER_ID, userId);
params.put(USERNAME, username);
User user;
try {
user = userDao.getUserByIdOrUsername(params);
} catch (Exception e) {
throw new ServiceLayerException("Unknown database error", e);
}
if (user == null) {
throw new UserNotFoundException("No user found for username '" + username + "' or id '" + userId + "'");
}
return user;
}
use of org.craftercms.studio.api.v2.dal.QueryParameterNames.USER_ID in project studio by craftercms.
the class UserDetailsManagerImpl method loadUserByUsername.
@Override
public UserDetails loadUserByUsername(String username) throws ServiceLayerException {
Map<String, Object> params = new HashMap<String, Object>();
params.put(USER_ID, -1);
params.put(USERNAME, username);
try {
User user = userDAO.getUserByIdOrUsername(params);
return user;
} catch (Exception e) {
throw new ServiceLayerException("Unknown database error", e);
}
}
Aggregations