aboutsummaryrefslogtreecommitdiff
path: root/app/models.py
blob: 47f7c9602a6b11877a3f28c60830ec42e2796d6c (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from sqlalchemy.ext.hybrid import hybrid_property
from flask_login import UserMixin

from app import bcrypt, db


class User(db.Model, UserMixin):
    __tablename__ = "users"

    first_name = db.Column(db.String)
    last_name = db.Column(db.String)
    email = db.Column(db.String(120), primary_key=True)
    confirmation = db.Column(db.Boolean)
    paid = db.Column(db.Boolean)
    role = db.Column(db.String)
    team = db.Column(db.String)
    login_type = db.Column(db.String, default="Normie")
    _password = db.Column(db.String)

    @property
    def full_name(self):
        return "{} {}".format(self.first_name, self.last_name)

    @hybrid_property
    def password(self):
        return self._password

    @password.setter
    def password(self, plaintext):
        self._password = bcrypt.generate_password_hash(plaintext)

    def check_password(self, plaintext):
        return bcrypt.check_password_hash(self.password, plaintext)

    def get_id(self):
        return self.email

    def get_role(self):
        return self.role

    def get_team(self):
        return self.team

    def is_paid(self):
        return self.paid