use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechUsersDao method getOpenIdUsers.
/**
* Returns all MotechUsers that comes from
* {@link LoginMode#OPEN_ID}
*
* @return list that contains users
*/
@Transactional
public List<MotechUser> getOpenIdUsers() {
List<MotechUser> users = dataService.retrieveAll();
Iterator<MotechUser> iterator = users.iterator();
while (iterator.hasNext()) {
MotechUser user = iterator.next();
if (isBlank(user.getOpenId())) {
iterator.remove();
}
}
return users;
}
use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechRoleServiceImpl method deleteRole.
@Override
@Transactional
public void deleteRole(RoleDto role) {
LOGGER.info("Deleting role: {}", role.getRoleName());
MotechRole motechRole = findByRoleName(role.getRoleName());
if (motechRole.isDeletable()) {
List<MotechUser> users = motechUsersDao.findByRole(role.getRoleName());
if (!users.isEmpty()) {
throw new RoleHasUserException("Role cannot be deleted because a user has the role.");
}
motechRolesDataService.delete(motechRole);
userContextsService.refreshAllUsersContextIfActive();
LOGGER.info("Deleted role: {}", role);
} else {
LOGGER.warn("The role {} cant be deleted", role.getRoleName());
}
}
use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechUserServiceImpl method sendLoginInformation.
@Override
@Transactional
public void sendLoginInformation(String userName) throws UserNotFoundException, NonAdminUserException {
String token;
MotechUser user = motechUsersDao.findByUserName(userName);
if (settingsFacade.getPlatformSettings().getLoginMode().isRepository()) {
token = passwordRecoveryService.passwordRecoveryRequest(user.getEmail(), false);
} else {
token = passwordRecoveryService.oneTimeTokenOpenId(user.getEmail(), false);
}
emailSender.sendLoginInfo(user, token);
}
use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechUserServiceImpl method deleteUser.
@Override
@Transactional
public void deleteUser(UserDto user) {
LOGGER.info("Deleting user: {}", user.getUserName());
MotechUser motechUser = motechUsersDao.findByUserName(user.getUserName());
motechUsersDao.remove(motechUser);
userContextsService.logoutUser(user.getUserName());
LOGGER.info("Deleted user: {}", user.getUserName());
}
use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechUserServiceImpl method changePassword.
@Override
@Transactional
public MotechUserProfile changePassword(String userName, String oldPassword, String newPassword) {
MotechUser motechUser = motechUsersDao.findByUserName(userName);
validatePassword(newPassword);
if (motechUser != null && passwordEncoder.isPasswordValid(motechUser.getPassword(), oldPassword)) {
motechUser.setPassword(passwordEncoder.encodePassword(newPassword));
motechUsersDao.update(motechUser);
return new MotechUserProfile(motechUser);
}
return null;
}
Aggregations