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;
}
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;
}
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";
}
Aggregations