Author: Pedro Lucas Porcellis <pedrolucasporcellis@gmail.com>
Add the User type
core/types/__init__.py | 1 + core/types/user.py | 42 ++++++++++++++++++++++++++++++++++++++++++
diff --git a/core/types/__init__.py b/core/types/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..f9b61db23e9eda545c21c78b8b746d90f1863990 --- /dev/null +++ b/core/types/__init__.py @@ -0,0 +1 @@ +from . import user diff --git a/core/types/user.py b/core/types/user.py new file mode 100644 index 0000000000000000000000000000000000000000..2636b6228dfccf9f9e4e9d262f2b63fdbad237da --- /dev/null +++ b/core/types/user.py @@ -0,0 +1,42 @@ +from sqlalchemy import Column, Integer, String, Unicode, Boolean, DateTime +from sqlalchemy import ForeignKey, Table, UnicodeText, Text, text +from sqlalchemy.orm import relationship, backref +from core.database import Base + +class User(Base): + __tablename__ = 'users' + id = Column(Integer, primary_key=True) + username = Column(String(80), unique=True, nullable=False) + email = Column(String(220), unique=True, nullable=False) + password = Column(String(96), nullable=False) + first_name = Column(String(250), nullable=False) + last_name = Column(String(250)) + created_at = Column(DateTime, nullable=False) + updated_at = Column(DateTime, nullable=False) + + def __init__(self, email, password, username, first_name, last_name): + self.email = email + self.password = password + self.username = username + self.first_name = first_name + self.last_name = last_name + + def is_admin(self): + # TODO: Move this to a field on the database + return self.email in ["porcellis@eletrotupi.com"] + + + # Flask.Login stuff + # We don't use most of these features + def is_authenticated(self): + return True + + def is_active(self): + return True + + def is_anonymous(self): + return False + + def get_id(self): + return int(self.id) +