注册时无法获取页面

时间:2018-12-25 13:49:07

标签: java spring

注册成功后,电子邮件到达您需要单击链接的位置,也就是说,必须打开HTML并在其中写有关于成功注册的消息,您需要使用以下链接生成该链接:激活密钥是UUID,问题从这里开始,通过电子邮件出现消息带有链接,但是在此链接下没有HTML,我想问题出在GetMapping中。

具有身份验证之类的问题,无处不在,permilAll

 @RequestMapping(value = "/doRegist", method = RequestMethod.POST)
public String addUser(@RequestBody User user, BindingResult bindingResult) throws  Exception{
    if (bindingResult.hasErrors()) {
        throw new Exception("Ошибка Регистрации");
    }

    if(!userService.addUser(user)){

        return "User exist";
    }

    return "dashboard";
}


 @GetMapping(value = "/activate/{code}")
//@RequestMapping(value = "activation/{code}", method = RequestMethod.GET)
public String activate(ModelMap model, @PathVariable String code) {
    boolean isActivated = userService.activateUser(code);
    if (isActivated) {
        model.addAttribute("message", "User Successfully activated");
    } else
        model.addAttribute("message", "Activation code not found");
    return "verification";
}

 public class UserService {
public boolean addUser(User user){
    User userFromDb = repository.findByUsername(user.getUsername());
    if (userFromDb!=null){
        return false;
    }
    user.setActive(true);
    user.setActivationCode(UUID.randomUUID().toString());
    repository.save(user);
    if (!org.springframework.util.StringUtils.isEmpty(user.getEmail())) {
        String message = String.format(
                "Hello," + user.getUsername() + "!\n" + "Welcome.Please, visit http://localhost:9009/activate/%s",
                user.getActivationCode());
        mailSenderService.send(user.getEmail(), "Activation code", message);
    }
    return true;
}


public boolean activateUser(String activationCode) {
    User user = repository.findByActivationCode(activationCode);
    if(user == null){
        return false;
    }
      user.setActivationCode(null);

    repository.save(user);
    return true;

}

0 个答案:

没有答案