use of com.zavada.entity.UserEntity in project Logos_Materials_October_2017 by VolodymyrZavada.
the class SpringBootConsultationProjectApplication method addAdmin.
static void addAdmin(ConfigurableApplicationContext context) {
String adminEmail = "admin@gmail.com";
String adminPassword = "123";
UserRepository userRepository = context.getBean(UserRepository.class);
UserEntity entity = userRepository.findUserByEmail(adminEmail);
if (entity == null) {
PasswordEncoder encoder = context.getBean(PasswordEncoder.class);
entity = new UserEntity();
entity.setEmail(adminEmail);
entity.setPassword(encoder.encode(adminPassword));
entity.setRole(Role.ROLE_ADMIN);
userRepository.save(entity);
}
}
use of com.zavada.entity.UserEntity in project Logos_Materials_October_2017 by VolodymyrZavada.
the class UserController method saveEditedProfile.
@PostMapping("/edit/{userId}")
public String saveEditedProfile(@ModelAttribute("editModel") EditUserRequest request, @PathVariable("userId") int userId) throws IOException {
if (request.getFile().isEmpty()) {
return "redirect:/user/edit/" + userId;
}
UserEntity entity = UserMapper.editRequestToEntity(request);
System.out.println("pass: " + entity.getPassword());
System.out.println("pass: " + entity.getRole());
userService.editUser(entity);
CustomFileUtils.createFolder("user_" + entity.getId());
CustomFileUtils.createImage("user_" + entity.getId(), request.getFile());
return "redirect:/user";
}
use of com.zavada.entity.UserEntity in project Logos_Materials_October_2017 by VolodymyrZavada.
the class UserController method showUserProfile.
@GetMapping
public String showUserProfile(Model model, Principal principal) throws IOException {
System.out.println("Secured user name: " + principal.getName());
UserEntity entity = userService.findUserByEmail(principal.getName());
if (entity == null)
return "redirect:/";
UserProfileRequest request = UserMapper.entityToUserProfile(entity);
model.addAttribute("userProfile", request);
model.addAttribute("imageSrc", CustomFileUtils.getImage("user_" + entity.getId(), entity.getImagePath()));
return "user/profile";
}
use of com.zavada.entity.UserEntity in project Logos_Materials_October_2017 by VolodymyrZavada.
the class UserFormatter method parse.
@Override
public UserEntity parse(String text, Locale locale) throws ParseException {
UserEntity entity = new UserEntity();
entity.setId(Integer.valueOf(text));
return entity;
}
use of com.zavada.entity.UserEntity in project Logos_Materials_October_2017 by VolodymyrZavada.
the class UserMapper method registerToUser.
public static UserEntity registerToUser(RegisterRequest request) {
UserEntity entity = new UserEntity();
entity.setEmail(request.getEmail());
entity.setPassword(request.getPassword());
entity.setFirstName(request.getFirstName());
entity.setLastName(request.getLastName());
entity.setRole(Role.ROLE_USER);
return entity;
}
Aggregations