Search in sources :

Example 1 with UserRepository

use of com.zavada.repository.UserRepository in project Logos_Materials_October_2017 by VolodymyrZavada.

the class SpringBootConsulttionTestProjectApplication 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 2 with UserRepository

use of com.zavada.repository.UserRepository 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)

Aggregations

UserEntity (com.zavada.entity.UserEntity)2 UserRepository (com.zavada.repository.UserRepository)2 PasswordEncoder (org.springframework.security.crypto.password.PasswordEncoder)2