Search in sources :

Example 1 with UserEntity

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;
}
Also used : UserEntity(org.codenergic.theskeleton.user.UserEntity) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 2 with UserEntity

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;
}
Also used : UserEntity(org.codenergic.theskeleton.user.UserEntity) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 3 with UserEntity

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;
}
Also used : UserEntity(org.codenergic.theskeleton.user.UserEntity)

Example 4 with UserEntity

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;
}
Also used : RegistrationException(org.codenergic.theskeleton.registration.RegistrationException) TokenStoreEntity(org.codenergic.theskeleton.tokenstore.TokenStoreEntity) UserEntity(org.codenergic.theskeleton.user.UserEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with UserEntity

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;
}
Also used : RegistrationException(org.codenergic.theskeleton.registration.RegistrationException) TokenStoreEntity(org.codenergic.theskeleton.tokenstore.TokenStoreEntity) UserEntity(org.codenergic.theskeleton.user.UserEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

UserEntity (org.codenergic.theskeleton.user.UserEntity)48 Test (org.junit.Test)30 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)14 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)10 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)8 Transactional (org.springframework.transaction.annotation.Transactional)7 WithMockUser (org.springframework.security.test.context.support.WithMockUser)6 Before (org.junit.Before)5 Authentication (org.springframework.security.core.Authentication)5 PageableHandlerMethodArgumentResolver (org.springframework.data.web.PageableHandlerMethodArgumentResolver)4 AuthenticationPrincipalArgumentResolver (org.springframework.security.web.method.annotation.AuthenticationPrincipalArgumentResolver)4 InputStream (java.io.InputStream)3 Date (java.util.Date)3 UserArgumentResolver (org.codenergic.theskeleton.core.web.UserArgumentResolver)3 PageImpl (org.springframework.data.domain.PageImpl)3 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)3 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)2 OAuth2ClientEntity (org.codenergic.theskeleton.client.OAuth2ClientEntity)2 EmailServiceTest (org.codenergic.theskeleton.core.mail.EmailServiceTest)2 RegistrationException (org.codenergic.theskeleton.registration.RegistrationException)2