Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="alert alert-info" th:if="${emailSent}">
- An email has been sent to the email address you just registered.
- Please validate your email address and update your password information.
- </div>
- <form th:action="@{/newUser}" method="post">
- <div class="form-group">
- <label for="newUsername">* Username: </label> <input
- required="required" type="text" class="form-control"
- id="newUsername" name="username" />
- <p style="color: #828282">Enter your username here.</p>
- </div>
- <div class="form-group">
- <label for="email">* Email Address: </label> <input
- required="required" type="text" class="form-control"
- id="email" name="email" />
- <p style="color: #828282">A valid email address. All
- emails from the system withll be sent to this address. The
- email address is not made public and will only be used if
- you wish to receive a new password or wish to receive
- certain notification.</p>
- </div>
- <button type="submit" class="btn btn-primary">Create new account</button>
- </form>
- </div>
- </div>
- </div>
- </div>
- @RequestMapping(value="/newUser", method=RequestMethod.POST)
- public String newUserPost(HttpServletRequest request,
- @RequestParam("email") String userEmail,
- @RequestParam("username") String username,
- Model model) throws Exception {
- model.addAttribute("classActiveNewAccount", true);
- model.addAttribute("email", userEmail);
- model.addAttribute("username", username);
- if(userService.findByUsername(username) != null){
- model.addAttribute("usernameExists", true);
- return "myAccount";
- }
- if(userService.findByEmail(userEmail) != null){
- model.addAttribute("email", true);
- return "myAccount";
- }
- User user = new User();
- user.setUsername(username);
- user.setEmail(userEmail);
- String password = SecurityUtility.randomPassword();
- String encryptedPassword = SecurityUtility.passwordEncoder().encode(password);
- user.setPassword(encryptedPassword);
- Role role = new Role();
- role.setRoleId(1);
- role.setName("ROLE-USER");
- Set<UserRole> userRoles = new HashSet<>();
- userRoles.add(new UserRole(user,role));
- userService.createUser(user,userRoles);
- String token = UUID.randomUUID().toString();
- userService.createPasswordResetTokenForUser(user, token);
- String appUrl = "http://"+ request.getServerName()+":"+request.getServerPort()+
- request.getContextPath();
- SimpleMailMessage email =
- mailConstructor.constructResetTokenEmail(appUrl,request.getLocale(),token,user,password);
- mailSender.send(email);
- model.addAttribute("emailSent","true");
- return "myAccount";
- }
- spring.mail.host=smtp.live.com
- spring.mail.username=my hotmail mail
- spring.mail.password=my hotmail password
- spring.mail.properties.mail.smtp.auth=true
- spring.mail.properties.mail.smtp.socketFactory.port=465
- spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
- spring.mail.properties.mail.smtp.socketFactory.fallback=false
- support.email=my hotmail mail
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement