Search in sources :

Example 1 with User

use of com.koderki.persistance.models.User in project rocket_journal by koderki.

the class MyUserDetailsService method loadUserByUsername.

public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
    User user = userRepository.findByEmail(email);
    if (user == null) {
        throw new UsernameNotFoundException("No user found with username: " + email);
    }
    boolean enabled = true;
    boolean accountNonExpired = true;
    boolean credentialsNonExpired = true;
    boolean accountNonLocked = true;
    return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(), enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, getAuthorities(user.getRoles()));
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) User(com.koderki.persistance.models.User)

Example 2 with User

use of com.koderki.persistance.models.User in project rocket_journal by koderki.

the class UserService method registerNewUserAccount.

@Transactional
@Override
public User registerNewUserAccount(UserDto accountDto) throws EmailExistsException {
    if (emailExist(accountDto.getEmail())) {
        throw new EmailExistsException("There is an account with that email address: " + accountDto.getEmail());
    }
    User user = new User();
    user.setEnabled(true);
    user.setPassword(accountDto.getPassword());
    user.setEmail(accountDto.getEmail());
    user.setRoles(Arrays.asList(roleRepository.findByName("ROLE_USER")));
    return repository.save(user);
}
Also used : User(com.koderki.persistance.models.User) EmailExistsException(com.koderki.validators.EmailExistsException) Transactional(javax.transaction.Transactional)

Aggregations

User (com.koderki.persistance.models.User)2 EmailExistsException (com.koderki.validators.EmailExistsException)1 Transactional (javax.transaction.Transactional)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1