Search in sources :

Example 51 with User

use of com.haozi.app.domain.User in project hello-world by haoziapple.

the class UserMapper method userFromId.

public User userFromId(Long id) {
    if (id == null) {
        return null;
    }
    User user = new User();
    user.setId(id);
    return user;
}
Also used : User(com.haozi.app.domain.User)

Example 52 with User

use of com.haozi.app.domain.User in project hello-world by haoziapple.

the class AccountResource method registerAccount.

/**
 * POST  /register : register the user.
 *
 * @param managedUserVM the managed user View Model
 * @throws InvalidPasswordException 400 (Bad Request) if the password is incorrect
 * @throws EmailAlreadyUsedException 400 (Bad Request) if the email is already used
 * @throws LoginAlreadyUsedException 400 (Bad Request) if the login is already used
 */
@PostMapping("/register")
@Timed
@ResponseStatus(HttpStatus.CREATED)
public void registerAccount(@Valid @RequestBody ManagedUserVM managedUserVM) {
    if (!checkPasswordLength(managedUserVM.getPassword())) {
        throw new InvalidPasswordException();
    }
    userRepository.findOneByLogin(managedUserVM.getLogin().toLowerCase()).ifPresent(u -> {
        throw new LoginAlreadyUsedException();
    });
    userRepository.findOneByEmailIgnoreCase(managedUserVM.getEmail()).ifPresent(u -> {
        throw new EmailAlreadyUsedException();
    });
    User user = userService.registerUser(managedUserVM, managedUserVM.getPassword());
    mailService.sendActivationEmail(user);
}
Also used : User(com.haozi.app.domain.User) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

User (com.haozi.app.domain.User)52 Test (org.junit.Test)41 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)41 Transactional (org.springframework.transaction.annotation.Transactional)36 WithMockUser (org.springframework.security.test.context.support.WithMockUser)21 ManagedUserVM (com.haozi.app.web.rest.vm.ManagedUserVM)15 UserDTO (com.haozi.app.service.dto.UserDTO)5 Authority (com.haozi.app.domain.Authority)4 Instant (java.time.Instant)4 MimeMessage (javax.mail.internet.MimeMessage)4 Timed (com.codahale.metrics.annotation.Timed)2 KeyAndPasswordVM (com.haozi.app.web.rest.vm.KeyAndPasswordVM)2 LoginVM (com.haozi.app.web.rest.vm.LoginVM)2 Before (org.junit.Before)2 UserRepository (com.haozi.app.repository.UserRepository)1 BadRequestAlertException (com.haozi.app.web.rest.errors.BadRequestAlertException)1 EmailAlreadyUsedException (com.haozi.app.web.rest.errors.EmailAlreadyUsedException)1 LoginAlreadyUsedException (com.haozi.app.web.rest.errors.LoginAlreadyUsedException)1 URI (java.net.URI)1 java.util (java.util)1