Advertisement
Guest User

Untitled

a guest
Mar 8th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. @Service
  2. class UserService {
  3. @Autowired
  4. private lateinit var userRepository: UserRepository
  5.  
  6. @Autowired
  7. private lateinit var bCryptPasswordEncoder: BCryptPasswordEncoder
  8.  
  9. fun create(user: User): User {
  10. user.password = bCryptPasswordEncoder.encode(user.password)
  11. return userRepository.save(user)
  12. }
  13.  
  14. fun myself(): String? {
  15. return userRepository.findByEmail(getCurrentUserEmail())?.fullName
  16. }
  17.  
  18. private fun getCurrentUserEmail(): String? {
  19. val user = SecurityContextHolder.getContext().authentication.principal as UserDetailsImpl
  20. return user.username
  21. }
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement