Search in sources :

Example 6 with User

use of site.model.User in project jprime by bgjug.

the class UserController method createNewPass.

@RequestMapping(value = "createNewPassword", method = RequestMethod.GET)
public String createNewPass(@RequestParam(value = "tokenId", required = true) String tokenId, Model model) {
    User owner = resetPassService.checkTokenValidity(tokenId);
    if (owner == null) {
        return "redirect:/home";
    }
    model.addAttribute("tokenId", tokenId);
    return CREATE_NEW_PASSWORD_JSP;
}
Also used : User(site.model.User) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with User

use of site.model.User in project jprime by bgjug.

the class ResetPasswordService method checkTokenValidity.

/**
 * @param tokenId
 * @return User owning the token if tokenId is valid, return NULL if tokenId
 *         is not valid
 */
public User checkTokenValidity(String tokenId) {
    String tokenShaHex = Sha512DigestUtils.shaHex(tokenId);
    ResetPasswordToken resetPasswordToken = resetPassRepository.findByTokenId(tokenShaHex);
    if (resetPasswordToken == null) {
        logger.debug("ResetPasswordToken id=" + tokenId + " , ShaHex: " + tokenShaHex + " NOT found. This could be an attacker brute forcing the token!");
        return null;
    }
    User owner = resetPasswordToken.getOwner();
    if (resetPasswordToken.isUsed()) {
        logger.debug("ResetPassworToken for user: " + owner + " with Id=" + tokenId + ", ShaHex: " + tokenShaHex + " is aleady used.");
        return null;
    }
    DateTime createdDate = resetPasswordToken.getCreatedDate();
    DateTime deadline = createdDate.plusHours(TOKEN_DURATION_IN_HOURS);
    if (deadline.isBeforeNow()) {
        logger.debug("ResetPassworToken for user: " + owner + " with Id=" + tokenId + ", ShaHex: " + tokenShaHex + "  is expired.");
        return null;
    }
    return owner;
}
Also used : User(site.model.User) ResetPasswordToken(site.model.ResetPasswordToken) DateTime(org.joda.time.DateTime)

Example 8 with User

use of site.model.User in project jprime by bgjug.

the class AdminArticleController method add.

@RequestMapping(value = "/add", method = RequestMethod.POST)
public String add(@Valid final Article article, BindingResult bindingResult) {
    if (bindingResult.hasErrors()) {
        return "/admin/article/edit.jsp";
    }
    User admin = this.adminFacade.findUserByEmail("admin@jsprime.io");
    if (admin == null) {
        admin = new User();
        admin.setEmail("admin@jsprime.io");
        admin.setFirstName("Admin");
        admin.setLastName("");
        this.adminFacade.saveUser(admin);
        // refresh
        admin = this.adminFacade.findUserByEmail("admin@jsprime.io");
    }
    article.setAuthor(admin);
    this.adminFacade.saveArticle(article);
    return "redirect:/admin/article/view";
}
Also used : User(site.model.User) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

User (site.model.User)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResetPasswordToken (site.model.ResetPasswordToken)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 MessagingException (javax.mail.MessagingException)1 EmailValidator (org.hibernate.validator.internal.constraintvalidators.bv.EmailValidator)1 DateTime (org.joda.time.DateTime)1 Before (org.junit.Before)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1