latosa/user.py
2024-03-02 16:15:54 +01:00

48 lines
1.5 KiB
Python

from flask import Flask
from flask_bcrypt import Bcrypt
class User:
def __init__(self, app: Flask, uid: str, display_name: str, email:str, password: str, admin: bool = False):
self.uid = uid
self.display_name = display_name
self.email = email
self.is_admin = admin
self.is_authenticated = False
self.is_active = False
self.is_anonymous = False
self.bcrypt = Bcrypt(app)
self.salt = self.get_salt()
self.password_hash = self.bcrypt.generate_password_hash(password + self.salt).decode('utf-8')
def check_password(self, password: str):
return self.bcrypt.check_password_hash(self.password_hash, password + self.salt)
def get_id(self):
return self.uid
def get_display_name(self):
return self.display_name
def get_email(self):
return self.email
def get_salt(self):
return "salt"
def set_active(self, active: bool):
self.is_active = active
def set_authenticated(self, authenticated: bool):
self.is_authenticated = authenticated
def set_anonymous(self, anonymous: bool):
self.is_anonymous = anonymous
def set_admin(self, admin: bool):
self.is_admin = admin
def set_email(self, email: str):
self.email = email
def set_password(self, password: str):
self.password_hash = self.bcrypt.generate_password_hash(password + self.salt).decode('utf-8')