Guest User

Untitled

a guest
Dec 13th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. package org.launchcode.cheesemvc.models;
  2.  
  3. import org.hibernate.validator.constraints.Email;
  4. import javax.validation.constraints.NotNull;
  5. import javax.validation.constraints.Size;
  6. import java.time.LocalDate;
  7. import java.time.LocalDateTime;
  8. import java.time.format.DateTimeFormatter;
  9.  
  10. /**
  11. * Created by ryanneal on 12/5/17.
  12. */
  13. public class User {
  14.  
  15. @NotNull
  16. @Size(min=5, max=15)
  17. private String username;
  18.  
  19. @Email
  20. private String email;
  21.  
  22. @NotNull
  23. @Size(min=6, max=25)
  24. private String password;
  25.  
  26. @NotNull(message = "Passwords do not match")
  27. private String verifyPassword;
  28.  
  29. private int userId;
  30.  
  31. private LocalDateTime date;
  32.  
  33. public User(String username, String email, String password) {
  34. this();
  35. this.username = username;
  36. this.email = email;
  37. this.password = password;
  38. }
  39.  
  40. // Why do we need an empty constructor?
  41.  
  42. public User(){
  43. this.date = LocalDateTime.now();
  44. }
  45.  
  46. public int getUserId() {
  47. return userId;
  48. }
  49.  
  50. public String getUsername() {
  51. return username;
  52. }
  53.  
  54. // We can use the get method to format our data for the view
  55. // What does this formatter do?
  56. public LocalDate getDate() {
  57. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy MM dd");
  58. String text = date.format(formatter);
  59. LocalDate parsedDate = LocalDate.parse(text, formatter);
  60. return parsedDate;
  61. }
  62.  
  63. public void checkPassword(){
  64. if (this.getPassword() != null && this.getVerifyPassword()!= null && !this.getPassword().equals(getVerifyPassword())){
  65. this.verifyPassword = null;
  66. }
  67. }
  68.  
  69. public void setUsername(String username) {
  70. this.username = username;
  71. }
  72.  
  73. public String getEmail() {
  74. return email;
  75. }
  76.  
  77. public void setEmail(String email) {
  78. this.email = email;
  79. }
  80.  
  81. // what happens if this get does not exist?
  82. public String getPassword() {
  83. return password;
  84. }
  85.  
  86. public void setPassword(String password) {
  87. this.password = password;
  88. checkPassword();
  89. }
  90.  
  91. public void setUserId(int id){
  92. this.userId = id;
  93. }
  94.  
  95. public String getVerifyPassword() {
  96. return verifyPassword;
  97. }
  98.  
  99. public void setVerifyPassword(String verifyPassword) {
  100. this.verifyPassword = verifyPassword;
  101. checkPassword();
  102. }
  103. }
Add Comment
Please, Sign In to add comment