Exemple #1
0
class Notification(db.Model, BaseModel):
    """Model for Notification"""

    __tablename__ = 'notifications'

    # columns
    user_id = db.Column('user_id',
                        db.Integer,
                        db.ForeignKey('users.id'),
                        nullable=True)
    channel = db.Column('channel', db.Integer, nullable=False)
    template = db.Column('template', db.String(60), nullable=True)
    service = db.Column('service', db.String(60), nullable=True)
    notification_id = db.Column('notification_id',
                                db.String(60),
                                nullable=True)
    accepted = db.Column('accepted', db.Integer, nullable=False)
    rejected = db.Column('rejected', db.Integer, nullable=False)
    sent_at = db.Column('sent_at',
                        db.TIMESTAMP(timezone=True),
                        server_default=db.func.current_timestamp(),
                        nullable=False)

    # relationships
    user = db.relationship('User', back_populates='notifications')
Exemple #2
0
class AdministratorPasswordHistory(db.Model):
    """Model for AdministratorPasswordHistory"""

    __tablename__ = 'administrator_password_history'

    # columns
    id = db.Column('id', db.BigInteger, primary_key=True)
    administrator_id = db.Column('administrator_id',
                                 db.Integer,
                                 db.ForeignKey('administrators.id'),
                                 nullable=True)
    password = db.Column('password', db.String(60), nullable=False)
    set_date = db.Column('set_date',
                         db.TIMESTAMP(timezone=True),
                         server_default=db.func.current_timestamp(),
                         nullable=False)

    # timestamps
    created_at = db.Column('created_at',
                           db.TIMESTAMP(timezone=True),
                           server_default=db.func.current_timestamp(),
                           nullable=False)
    updated_at = db.Column('updated_at',
                           db.TIMESTAMP(timezone=True),
                           server_default=db.func.current_timestamp(),
                           onupdate=db.func.current_timestamp(),
                           nullable=False)

    # relationships
    administrator = db.relationship('Administrator',
                                    back_populates='password_history')
Exemple #3
0
class UserProfile(db.Model, BaseModel):
    """Model for UserProfile"""

    __tablename__ = 'user_profiles'

    CRYPT_SYM_SECRET_KEY = Config.CRYPT_SYM_SECRET_KEY

    # columns
    user_id = db.Column('user_id',
                        db.Integer,
                        db.ForeignKey('users.id'),
                        nullable=False)
    first_name = db.Column('first_name',
                           PGPString(CRYPT_SYM_SECRET_KEY, length=200),
                           nullable=False)
    last_name = db.Column('last_name',
                          PGPString(CRYPT_SYM_SECRET_KEY, length=200),
                          nullable=False)
    joined_at = db.Column('joined_at',
                          db.TIMESTAMP(timezone=True),
                          index=True,
                          server_default=db.func.current_timestamp(),
                          nullable=False)

    # relationships
    user = db.relationship('User', back_populates='profile')
Exemple #4
0
class UserTermsOfService(db.Model):
    """Model for UserTermsOfService"""

    __tablename__ = 'user_terms_of_services'

    CRYPT_SYM_SECRET_KEY = Config.CRYPT_SYM_SECRET_KEY

    # columns
    user_id = db.Column('user_id',
                        db.Integer,
                        db.ForeignKey('users.id'),
                        primary_key=True)
    terms_of_service_id = db.Column('terms_of_service_id',
                                    db.Integer,
                                    db.ForeignKey('terms_of_services.id'),
                                    primary_key=True)
    accept_date = db.Column('accept_date',
                            db.TIMESTAMP(timezone=True),
                            server_default=db.func.current_timestamp(),
                            nullable=False)
    ip_address = db.Column('ip_address',
                           PGPString(CRYPT_SYM_SECRET_KEY, length=200),
                           nullable=False)

    # relationships
    user = db.relationship('User', uselist=False)
    terms_of_service = db.relationship('TermsOfService', uselist=False)

    # timestamps
    created_at = db.Column('created_at',
                           db.TIMESTAMP(timezone=True),
                           server_default=db.func.current_timestamp(),
                           nullable=False)
    updated_at = db.Column('updated_at',
                           db.TIMESTAMP(timezone=True),
                           server_default=db.func.current_timestamp(),
                           onupdate=db.func.current_timestamp(),
                           nullable=False)
Exemple #5
0
class Region(db.Model, BaseModel):
    """Model for Region"""

    __tablename__ = 'regions'

    # columns
    name = db.Column('name', db.String(60), nullable=False)
    code_2 = db.Column('code_2', db.String(2))
    country_id = db.Column('country_id',
                           db.Integer,
                           db.ForeignKey('countries.id'),
                           nullable=False)

    # relationships
    country = db.relationship('Country', back_populates="regions")
Exemple #6
0
class PasswordReset(db.Model, BaseModel):
    """Model for PasswordReset"""

    __tablename__ = 'password_resets'

    # columns
    user_id = db.Column('user_id',
                        db.Integer,
                        db.ForeignKey('users.id'),
                        nullable=False)
    code = db.Column('code', db.String(40), nullable=False)
    is_used = db.Column('is_used', db.Boolean, nullable=False)
    requested_at = db.Column('requested_at',
                             db.TIMESTAMP(timezone=True),
                             server_default=db.func.current_timestamp(),
                             nullable=False)
    ip_address = db.Column('ip_address', db.String(50), index=True)

    # relationships
    user = db.relationship('User', back_populates='password_resets')
Exemple #7
0
import bcrypt
from sqlalchemy.ext.hybrid import hybrid_property
from itsdangerous import (TimedJSONWebSignatureSerializer as Serializer,
                          BadSignature, SignatureExpired)

from lib.sqlalchemy.base_model import BaseModel
from lib.sqlalchemy.pgp_string import PGPString
from init_dep import db
from config import Config

# relation tables
roles = db.Table(
    'admin_roles',
    db.Column('admin_id',
              db.Integer,
              db.ForeignKey('administrators.id'),
              primary_key=True),
    db.Column('role_id',
              db.Integer,
              db.ForeignKey('roles.id'),
              primary_key=True))


class AdministratorPasswordHistory(db.Model):
    """Model for AdministratorPasswordHistory"""

    __tablename__ = 'administrator_password_history'

    # columns
    id = db.Column('id', db.BigInteger, primary_key=True)
    administrator_id = db.Column('administrator_id',
Exemple #8
0
from sqlalchemy.ext.hybrid import hybrid_property
from itsdangerous import (TimedJSONWebSignatureSerializer as Serializer,
                          BadSignature, SignatureExpired)
from lib.sqlalchemy.base_model import BaseModel
from lib.sqlalchemy.pgp_string import PGPString
from modules.password_resets.model import PasswordReset
from modules.notifications.model import Notification
from init_dep import db
from config import Config

# relation tables
roles = db.Table(
    'user_roles',
    db.Column('user_id',
              db.Integer,
              db.ForeignKey('users.id'),
              primary_key=True),
    db.Column('role_id',
              db.Integer,
              db.ForeignKey('roles.id'),
              primary_key=True))


class UserPasswordHistory(db.Model):
    """Model for UserPasswordHistory"""

    __tablename__ = 'user_password_history'

    # columns
    id = db.Column('id', db.BigInteger, primary_key=True)
    user_id = db.Column('user_id',