use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class RegistrationController method register.
@PostMapping
public String register(@Valid RegistrationForm registrationForm, BindingResult bindingResult, WebRequest request) {
if (bindingResult.hasErrors())
return registrationView(registrationForm, request);
try {
UserEntity user = registrationService.registerUser(registrationForm);
if (user != null && user.getId() != null) {
tokenStoreService.sendTokenNotification(TokenStoreType.USER_ACTIVATION, user);
providerSignInUtils.doPostSignUp(user.getId(), request);
}
} catch (RegistrationException e) {
bindingResult.rejectValue("username", "error.registrationForm", e.getMessage());
return registrationView(registrationForm, request);
}
return REGISTRATION_CONFIRMATION;
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class ChangePasswordController method changepass.
@PostMapping
public String changepass(Model model, @Valid ChangePasswordForm changePasswordForm, BindingResult bindingResult) {
if (bindingResult.hasErrors())
return changepassView(changePasswordForm);
UserEntity user = registrationService.findUserByEmail(changePasswordForm.getEmail());
if (user == null) {
bindingResult.rejectValue("email", "error.changePasswordForm", "Can't find that email, sorry.");
return changepassView(changePasswordForm);
} else {
tokenStoreService.sendTokenNotification(TokenStoreType.CHANGE_PASSWORD, user);
}
model.addAttribute(MESSAGE, CHANGEPASS);
return CHANGEPASS_CONFIRMATION;
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class ProfileServiceImpl method updateProfilePicture.
@Override
public UserEntity updateProfilePicture(String username, InputStream image, String contentType) throws Exception {
UserEntity user = findProfileByUsername(username);
String imageObjectName = StringUtils.join(user.getId(), "/", Long.toHexString(Instant.now().toEpochMilli()), "-", UUID.randomUUID().toString());
minioClient.putObject(PICTURE_BUCKET_NAME, imageObjectName, image, contentType);
user.setPictureUrl(minioClient.getObjectUrl(PICTURE_BUCKET_NAME, imageObjectName));
return user;
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class RegistrationServiceImpl method activateUser.
@Override
@Transactional
public boolean activateUser(String activationToken) {
TokenStoreEntity tokenStoreEntity = tokenStoreRepository.findByTokenAndType(activationToken, TokenStoreType.USER_ACTIVATION);
if (tokenStoreEntity == null)
throw new RegistrationException("Invalid Activation Key");
if (tokenStoreEntity.isTokenExpired())
throw new RegistrationException("Activation Key is Expired");
if (Activeable.Status.INACTIVE.getStatus() == tokenStoreEntity.getStatus())
throw new RegistrationException("Your Account is already activated");
UserEntity user = tokenStoreEntity.getUser();
user.setEnabled(true);
tokenStoreEntity.setStatus(Activeable.Status.INACTIVE.getStatus());
return true;
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class RegistrationServiceImpl method changePassword.
@Override
@Transactional
public boolean changePassword(String activationToken, String password) {
TokenStoreEntity tokenStoreEntity = tokenStoreRepository.findByTokenAndType(activationToken, TokenStoreType.CHANGE_PASSWORD);
if (tokenStoreEntity == null)
throw new RegistrationException("Invalid Activation Key");
if (tokenStoreEntity.isTokenExpired())
throw new RegistrationException("Activation Key is Expired");
UserEntity user = tokenStoreEntity.getUser();
user.setPassword(passwordEncoder.encode(password));
tokenStoreEntity.setStatus(Activeable.Status.INACTIVE.getStatus());
return true;
}
Aggregations