45 lines
1.1 KiB
Java
45 lines
1.1 KiB
Java
package com.drinkool.models;
|
|
|
|
import io.quarkus.hibernate.orm.panache.PanacheEntity;
|
|
import jakarta.persistence.*;
|
|
import jakarta.transaction.*;
|
|
import com.password4j.Password;
|
|
|
|
@Entity
|
|
@Inheritance(strategy = InheritanceType.JOINED)
|
|
@Table(name = "users")
|
|
public abstract class User extends PanacheEntity {
|
|
@Column(nullable = false)
|
|
public String name;
|
|
|
|
@Column(nullable = false)
|
|
public String phone;
|
|
|
|
@Column(nullable = false, length = 1024)
|
|
public String hashedPassword;
|
|
|
|
public User() {
|
|
super();
|
|
}
|
|
|
|
@Transactional
|
|
public void signup(String phone, String rawPassword) {
|
|
this.signup(phone, phone, rawPassword);
|
|
}
|
|
|
|
@Transactional
|
|
public void signup(String name, String phone, String rawPassword) {
|
|
this.name = name;
|
|
this.phone = phone;
|
|
this.hashedPassword = Password.hash(rawPassword).withArgon2().getResult();
|
|
|
|
this.persist();
|
|
}
|
|
|
|
public boolean login(String rawPassword) {
|
|
if (this.hashedPassword == null)
|
|
return false;
|
|
|
|
return Password.check(rawPassword, this.hashedPassword).withArgon2();
|
|
}
|
|
} |