hellokoding-courses icon indicating copy to clipboard operation
hellokoding-courses copied to clipboard

[BUG] springboot-registration-login project's auto login method

Open pereira-a opened this issue 6 years ago • 0 comments

In order to create the authentication token at the SecurityServiceImpl class, it's needed to pass to the constructor the password in plain text.

I recommend saving the password in registration mapping and then pass it to autologin.

Example:

@PostMapping("/registration")
    public String registration(@ModelAttribute("userForm") User userForm, BindingResult bindingResult) {
		String pw = userForm.getPassword();
        userValidator.validate(userForm, bindingResult);

        if (bindingResult.hasErrors()) {
            return "registration";
        }

        userService.save(userForm);

        securityService.autoLogin(userForm.getUsername(), pw);

        return "redirect:/welcome";
    }

pereira-a avatar Apr 07 '19 14:04 pereira-a