use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechUserServiceImpl method updateUserDetailsWithoutPassword.
@Override
@Transactional
public void updateUserDetailsWithoutPassword(UserDto user) {
MotechUser motechUser = motechUsersDao.findByUserName(user.getUserName());
motechUser.setEmail(user.getEmail());
motechUser.setUserStatus(user.getUserStatus());
motechUser.setRoles(user.getRoles());
motechUser.setLocale(user.getLocale());
motechUsersDao.update(motechUser);
userContextsService.refreshUserContextIfActive(motechUser.getUserName());
}
use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechUserServiceImpl method register.
@Override
@Transactional
public // NO CHECKSTYLE More than 7 parameters (found 8).
void register(// NO CHECKSTYLE More than 7 parameters (found 8).
String username, // NO CHECKSTYLE More than 7 parameters (found 8).
String password, String email, String externalId, List<String> roles, Locale locale, UserStatus userStatus, String openId) {
LOGGER.info("Registering new user: {}", username);
if (isBlank(username) || isBlank(password)) {
throw new IllegalArgumentException("Username or password cannot be empty");
}
validatePassword(password);
String encodePassword = passwordEncoder.encodePassword(password);
MotechUser user = new MotechUser(username, encodePassword, email, externalId, roles, openId, locale);
user.setUserStatus(userStatus);
motechUsersDao.add(user);
LOGGER.info("Registered new user: {}", username);
}
use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechUserServiceImpl method activateUser.
@Override
@Transactional
public void activateUser(String username) {
LOGGER.info("Activating user: {}", username);
MotechUser motechUser = motechUsersDao.findByUserName(username);
if (motechUser != null) {
motechUser.setUserStatus(UserStatus.ACTIVE);
motechUsersDao.update(motechUser);
}
LOGGER.info("Activated user: {}", username);
}
use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechUserServiceImpl method getCurrentUser.
@Override
@Transactional
public UserDto getCurrentUser() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
User userInSession = (authentication == null) ? null : (User) authentication.getPrincipal();
if (userInSession == null) {
return null;
}
String currentUserName = userInSession.getUsername();
MotechUser user = motechUsersDao.findByUserName(currentUserName);
return new UserDto(user);
}
use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechUsersDao method update.
/**
* Updates given MotechUser as long as his email is not used by another user
*
* @param motechUser to be updated
*/
@Transactional
public void update(MotechUser motechUser) {
String email = motechUser.getEmail();
MotechUser otherWithSameEmail = findUserByEmail(email);
if (null != otherWithSameEmail && !otherWithSameEmail.getUserName().equals(motechUser.getUserName())) {
throw new EmailExistsException("User with email " + email + " already exists");
}
dataService.update(motechUser);
}
Aggregations