Guest User

Untitled

a guest
Dec 21st, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. @RestController
  2. @RequestMapping("/users")
  3. public class UserController {
  4.  
  5. @Autowired
  6. UserRepository userRepository;
  7. @Autowired
  8. BCryptPasswordEncoder bCryptPasswordEncoder;
  9.  
  10. @PostMapping("/sign-up")
  11. public void signUp(@RequestBody User user) {
  12. user.setPassword(bCryptPasswordEncoder.encode(user.getPassword()));
  13. userRepository.save(user);
  14. }
  15. }
  16.  
  17. @Entity
  18. @Table(name = "req_user")
  19. public class User {
  20.  
  21. @Id
  22. @GeneratedValue(strategy = GenerationType.AUTO)
  23. private Long id;
  24. private String username;
  25. @JsonIgnore
  26. private String password;
  27. private String email;
  28.  
  29. public User() { }
  30.  
  31. public User(String username, String password, String email) {
  32. this.id = null;
  33. this.username = username;
  34. this.password = password;
  35. this.email = email;
  36. }
  37.  
  38. ...
  39.  
  40. @JsonIgnore
  41. public String getPassword() {
  42. return password;
  43. }
  44.  
  45. @JsonProperty
  46. public void setPassword(String password) {
  47. this.password = password;
  48. }
  49.  
  50. ...
  51. }
Add Comment
Please, Sign In to add comment