Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.launchcode.cheesemvc.models;
- import org.hibernate.validator.constraints.Email;
- import javax.validation.constraints.NotNull;
- import javax.validation.constraints.Size;
- import java.time.LocalDate;
- import java.time.LocalDateTime;
- import java.time.format.DateTimeFormatter;
- /**
- * Created by ryanneal on 12/5/17.
- */
- public class User {
- @NotNull
- @Size(min=5, max=15)
- private String username;
- @Email
- private String email;
- @NotNull
- @Size(min=6, max=25)
- private String password;
- @NotNull(message = "Passwords do not match")
- private String verifyPassword;
- private int userId;
- private LocalDateTime date;
- public User(String username, String email, String password) {
- this();
- this.username = username;
- this.email = email;
- this.password = password;
- }
- // Why do we need an empty constructor?
- public User(){
- this.date = LocalDateTime.now();
- }
- public int getUserId() {
- return userId;
- }
- public String getUsername() {
- return username;
- }
- // We can use the get method to format our data for the view
- // What does this formatter do?
- public LocalDate getDate() {
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy MM dd");
- String text = date.format(formatter);
- LocalDate parsedDate = LocalDate.parse(text, formatter);
- return parsedDate;
- }
- public void checkPassword(){
- if (this.getPassword() != null && this.getVerifyPassword()!= null && !this.getPassword().equals(getVerifyPassword())){
- this.verifyPassword = null;
- }
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getEmail() {
- return email;
- }
- public void setEmail(String email) {
- this.email = email;
- }
- // what happens if this get does not exist?
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- checkPassword();
- }
- public void setUserId(int id){
- this.userId = id;
- }
- public String getVerifyPassword() {
- return verifyPassword;
- }
- public void setVerifyPassword(String verifyPassword) {
- this.verifyPassword = verifyPassword;
- checkPassword();
- }
- }
Add Comment
Please, Sign In to add comment