保誠-保戶業務員媒合平台
wayne
2021-12-03 d7bcd8a8f81d85fe1524c4d785aaed58cd217586
pamapi/src/main/java/com/pollex/pam/web/rest/AccountResource.java
@@ -3,10 +3,15 @@
import com.pollex.pam.domain.User;
import com.pollex.pam.repository.UserRepository;
import com.pollex.pam.security.SecurityUtils;
import com.pollex.pam.security.jwt.JWTFilter;
import com.pollex.pam.service.CustomerAuthService;
import com.pollex.pam.service.CustomerService;
import com.pollex.pam.service.MailService;
import com.pollex.pam.service.UserService;
import com.pollex.pam.service.dto.AdminUserDTO;
import com.pollex.pam.service.dto.CustomerRegisterDTO;
import com.pollex.pam.service.dto.PasswordChangeDTO;
import com.pollex.pam.web.rest.UserJWTController.JWTToken;
import com.pollex.pam.web.rest.errors.*;
import com.pollex.pam.web.rest.vm.KeyAndPasswordVM;
import com.pollex.pam.web.rest.vm.ManagedUserVM;
@@ -16,7 +21,10 @@
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
@@ -40,6 +48,9 @@
    private final UserService userService;
    private final MailService mailService;
    @Autowired
    CustomerService customerService;
    public AccountResource(UserRepository userRepository, UserService userService, MailService mailService) {
        this.userRepository = userRepository;
@@ -47,23 +58,25 @@
        this.mailService = mailService;
    }
    /**
     * {@code POST  /register} : register the user.
     *
     * @param managedUserVM the managed user View Model.
     * @throws InvalidPasswordException {@code 400 (Bad Request)} if the password is incorrect.
     * @throws EmailAlreadyUsedException {@code 400 (Bad Request)} if the email is already used.
     * @throws LoginAlreadyUsedException {@code 400 (Bad Request)} if the login is already used.
     */
    @PostMapping("/register")
    @ResponseStatus(HttpStatus.CREATED)
    public void registerAccount(@Valid @RequestBody ManagedUserVM managedUserVM) {
        if (isPasswordLengthInvalid(managedUserVM.getPassword())) {
            throw new InvalidPasswordException();
        }
        User user = userService.registerUser(managedUserVM, managedUserVM.getPassword());
        mailService.sendActivationEmail(user);
    }
//    /**
//     * {@code POST  /register} : register the user.
//     *
//     * @param managedUserVM the managed user View Model.
//     * @throws InvalidPasswordException {@code 400 (Bad Request)} if the password is incorrect.
//     * @throws EmailAlreadyUsedException {@code 400 (Bad Request)} if the email is already used.
//     * @throws LoginAlreadyUsedException {@code 400 (Bad Request)} if the login is already used.
//     */
//    @PostMapping("/register")
//    @ResponseStatus(HttpStatus.CREATED)
//    public void registerAccount(@Valid @RequestBody ManagedUserVM managedUserVM) {
//        if (isPasswordLengthInvalid(managedUserVM.getPassword())) {
//            throw new InvalidPasswordException();
//        }
//        User user = userService.registerUser(managedUserVM, managedUserVM.getPassword());
//        mailService.sendActivationEmail(user);
//    }
    /**
     * {@code GET  /activate} : activate the registered user.