Search in sources :

Example 6 with UserEntity

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);
    }
}
Also used : UserRepository(com.zavada.repository.UserRepository) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) UserEntity(com.zavada.entity.UserEntity)

Example 7 with UserEntity

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";
}
Also used : UserEntity(com.zavada.entity.UserEntity) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 8 with UserEntity

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";
}
Also used : UserProfileRequest(com.zavada.domain.UserProfileRequest) UserEntity(com.zavada.entity.UserEntity) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 9 with UserEntity

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;
}
Also used : UserEntity(com.zavada.entity.UserEntity)

Example 10 with UserEntity

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;
}
Also used : UserEntity(com.zavada.entity.UserEntity)

Aggregations

UserEntity (com.zavada.entity.UserEntity)10 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 UserRepository (com.zavada.repository.UserRepository)2 PasswordEncoder (org.springframework.security.crypto.password.PasswordEncoder)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 CreateAdvRequest (com.zavada.domain.CreateAdvRequest)1 EditUserRequest (com.zavada.domain.EditUserRequest)1 UserProfileRequest (com.zavada.domain.UserProfileRequest)1 Car (com.zavada.entity.Car)1