This repository has been archived on 2020-08-02. You can view files and clone it, but cannot push or open issues or pull requests.
e-commerce/web_backend/src/main/java/org/hso/ecommerce/entities/user/User.java

52 lines
1.1 KiB
Java
Raw Normal View History

2020-04-29 22:44:16 +02:00
package org.hso.ecommerce.entities.user;
2020-04-08 18:27:46 +02:00
2020-04-29 22:44:16 +02:00
import org.hso.ecommerce.entities.booking.PaymentMethod;
import org.hso.ecommerce.entities.shop.Address;
2020-04-08 18:27:46 +02:00
import org.springframework.security.crypto.bcrypt.BCrypt;
2020-04-27 09:48:24 +02:00
import javax.persistence.*;
import javax.validation.constraints.NotNull;
2020-04-27 09:48:24 +02:00
2020-04-08 18:27:46 +02:00
@Entity
@Table(name = "users")
public class User {
@Id
2020-04-27 09:48:24 +02:00
@GeneratedValue(strategy = GenerationType.IDENTITY)
2020-04-08 18:27:46 +02:00
@Basic
public long id;
@NotNull
2020-04-08 18:27:46 +02:00
public java.sql.Timestamp created;
@NotNull
2020-04-08 18:27:46 +02:00
@Column(unique = true)
public String email;
2020-06-21 00:14:00 +02:00
2020-05-18 14:41:33 +02:00
public String salutation;
2020-04-08 18:27:46 +02:00
public String passwordHash;
public boolean isActive;
public boolean isEmployee;
@Embedded
public Address defaultDeliveryAddress;
@Embedded
public PaymentMethod defaultPayment;
2020-04-08 18:27:46 +02:00
public long getId() {
return id;
}
public boolean validatePassword(String password) {
2020-04-27 09:48:24 +02:00
return BCrypt.checkpw(password, passwordHash);
2020-04-08 18:27:46 +02:00
}
public void setPassword(String password) {
passwordHash = BCrypt.hashpw(password, BCrypt.gensalt());
}
}