-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.py
28 lines (22 loc) · 813 Bytes
/
user.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from attrs import define
from flask_login import UserMixin
from werkzeug.security import check_password_hash
@define(kw_only=True)
class User(UserMixin):
username: str
email: str
password: str
# There is `id` attribute, so we have to override the methods from UserMixin
def get_id(self) -> str:
"""
Override the default `id` attribute of UserMixin class.
:return: String of username.
"""
return self.username
def check_password(self, password_input: str) -> bool:
"""
Returns True if the password hash is identical, otherwise False.
:param password_input: Password inputted by user.
:return: Boolean (True or False).
"""
return check_password_hash(pwhash=self.password, password=password_input)