use of ua.springweb.security.entity.UserEntity in project Logos_Materials_October_2017 by VolodymyrZavada.
the class SpringBootSecurityWebAppApplication method addAdmin.
static void addAdmin(ConfigurableApplicationContext context) {
String email = "admin@gmail.com";
String password = "123";
UserRepository userRepository = context.getBean(UserRepository.class);
UserEntity entity = userRepository.findUserByEmail(email);
if (entity == null) {
PasswordEncoder passwordEncoder = context.getBean(PasswordEncoder.class);
entity = new UserEntity();
entity.setEmail(email);
entity.setPassword(passwordEncoder.encode(password));
entity.setRole(Role.ROLE_ADMIN);
userRepository.save(entity);
}
}
use of ua.springweb.security.entity.UserEntity in project Logos_Materials_October_2017 by VolodymyrZavada.
the class BaseController method verifyUser.
@GetMapping("/verify")
public String verifyUser(@RequestParam("token") String token, @RequestParam("userid") String userIdStr) {
int userId = Integer.valueOf(userIdStr);
UserEntity user = userService.findUserById(userId);
if (user.getToken().equals(token)) {
user.setToken("");
user.setActivated(true);
userService.updateUser(user);
}
return "redirect:/login";
}
use of ua.springweb.security.entity.UserEntity in project Logos_Materials_October_2017 by VolodymyrZavada.
the class BaseController method showProfile.
@GetMapping("/profile")
// @PreAuthorize("hasRole('ROLE_USER') OR hasRole('ROLE_ADMIN')")
@PreAuthorize("hasAnyRole('ROLE_ADMIN', 'ROLE_USER')")
public String showProfile(Principal principal, Model model) {
UserEntity entity = userService.findUserByEmail(principal.getName());
model.addAttribute("user", entity);
return "profile";
}
use of ua.springweb.security.entity.UserEntity in project Logos_Materials_October_2017 by VolodymyrZavada.
the class BaseController method saveUser.
@PostMapping("/register")
public String saveUser(@ModelAttribute("registerModel") RegisterRequest request) {
UserEntity user = UserMapper.registerToUser(request);
String token = RandomToken.generateRandom();
user.setToken(token);
user.setActivated(false);
userService.saveUser(user);
Mail mail = new Mail();
mail.setTo(request.getEmail());
mail.setSubject("You are successfully registered");
mail.setContent("Please verify your email address by follow the link: " + "http://localhost:8090/verify?token=" + token + "&userid=" + user.getId());
emailService.sendMessage(mail);
return "redirect:/login";
}
use of ua.springweb.security.entity.UserEntity in project Logos_Materials_October_2017 by VolodymyrZavada.
the class UserMapper method registerToUser.
public static UserEntity registerToUser(RegisterRequest request) {
UserEntity user = new UserEntity();
user.setEmail(request.getEmail());
user.setPassword(request.getPassword());
user.setRole(Role.ROLE_USER);
return user;
}
Aggregations