Advertisement
Guest User

Untitled

a guest
Aug 7th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. <div class="alert alert-info" th:if="${emailSent}">
  2. An email has been sent to the email address you just registered.
  3. Please validate your email address and update your password information.
  4. </div>
  5.  
  6. <form th:action="@{/newUser}" method="post">
  7. <div class="form-group">
  8. <label for="newUsername">* Username: </label> <input
  9. required="required" type="text" class="form-control"
  10. id="newUsername" name="username" />
  11. <p style="color: #828282">Enter your username here.</p>
  12. </div>
  13.  
  14. <div class="form-group">
  15. <label for="email">* Email Address: </label> <input
  16. required="required" type="text" class="form-control"
  17. id="email" name="email" />
  18. <p style="color: #828282">A valid email address. All
  19. emails from the system withll be sent to this address. The
  20. email address is not made public and will only be used if
  21. you wish to receive a new password or wish to receive
  22. certain notification.</p>
  23. </div>
  24.  
  25. <button type="submit" class="btn btn-primary">Create new account</button>
  26. </form>
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31.  
  32. @RequestMapping(value="/newUser", method=RequestMethod.POST)
  33. public String newUserPost(HttpServletRequest request,
  34. @RequestParam("email") String userEmail,
  35. @RequestParam("username") String username,
  36. Model model) throws Exception {
  37.  
  38. model.addAttribute("classActiveNewAccount", true);
  39. model.addAttribute("email", userEmail);
  40. model.addAttribute("username", username);
  41.  
  42. if(userService.findByUsername(username) != null){
  43. model.addAttribute("usernameExists", true);
  44.  
  45. return "myAccount";
  46. }
  47.  
  48. if(userService.findByEmail(userEmail) != null){
  49. model.addAttribute("email", true);
  50.  
  51. return "myAccount";
  52. }
  53.  
  54. User user = new User();
  55. user.setUsername(username);
  56. user.setEmail(userEmail);
  57.  
  58. String password = SecurityUtility.randomPassword();
  59.  
  60. String encryptedPassword = SecurityUtility.passwordEncoder().encode(password);
  61. user.setPassword(encryptedPassword);
  62.  
  63. Role role = new Role();
  64. role.setRoleId(1);
  65. role.setName("ROLE-USER");
  66.  
  67. Set<UserRole> userRoles = new HashSet<>();
  68. userRoles.add(new UserRole(user,role));
  69.  
  70. userService.createUser(user,userRoles);
  71.  
  72. String token = UUID.randomUUID().toString();
  73. userService.createPasswordResetTokenForUser(user, token);
  74.  
  75. String appUrl = "http://"+ request.getServerName()+":"+request.getServerPort()+
  76. request.getContextPath();
  77.  
  78. SimpleMailMessage email =
  79. mailConstructor.constructResetTokenEmail(appUrl,request.getLocale(),token,user,password);
  80.  
  81. mailSender.send(email);
  82.  
  83. model.addAttribute("emailSent","true");
  84.  
  85. return "myAccount";
  86. }
  87.  
  88. spring.mail.host=smtp.live.com
  89. spring.mail.username=my hotmail mail
  90. spring.mail.password=my hotmail password
  91. spring.mail.properties.mail.smtp.auth=true
  92. spring.mail.properties.mail.smtp.socketFactory.port=465
  93. spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
  94. spring.mail.properties.mail.smtp.socketFactory.fallback=false
  95. support.email=my hotmail mail
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement