Esempio n. 1
0
class AirgrabValidationRequest(DBH.Model):  # pylint: disable=too-few-public-methods
    """ Table for storing airgrab validation requests.
    """

    __tablename__ = "airgrab_validation_requests"
    # required name for postgres
    # pylint: disable=invalid-name
    id = DBH.Column(DBH.Integer, primary_key=True, autoincrement=True)
    worbli_account_name = DBH.Column(DBH.String(12),
                                     unique=True,
                                     nullable=False)
    security_code = DBH.Column(DBH.String(64), unique=True, nullable=False)
    completed = DBH.Column(DBH.Boolean, nullable=False, default=False)
    snapshot_balance = DBH.relationship("SnapshotBalance")
    snapshot_balance_id = DBH.Column(DBH.Integer,
                                     DBH.ForeignKey('snapshot_balances.id'),
                                     nullable=False)
    user = DBH.relationship("User", uselist=False)
    user_id = DBH.Column(DBH.Integer,
                         DBH.ForeignKey('users.id'),
                         nullable=False)

    def __init__(self, worbli_account_name=None, security_code=None):
        self.worbli_account_name = worbli_account_name
        self.security_code = security_code
Esempio n. 2
0
class User(DBH.Model):
    """ Table for storing users
    """

    __tablename__ = "users"

    # required name for postgres
    # pylint: disable=invalid-name
    id = DBH.Column(DBH.Integer, primary_key=True, autoincrement=True)
    email = DBH.Column(DBH.String(255), unique=True, nullable=False)
    password = DBH.Column(DBH.String(255), nullable=False)
    registered_on = DBH.Column(DBH.DateTime, nullable=False)
    location = DBH.Column(DBH.String(255), unique=False, nullable=False)
    firstname = DBH.Column(DBH.String(255), unique=False, nullable=False)
    lastname = DBH.Column(DBH.String(255), unique=False, nullable=False)
    admin = DBH.Column(DBH.Boolean, nullable=False, default=False)
    registration_request_id = DBH.Column(
        DBH.Integer,
        DBH.ForeignKey('registration_requests.id'),
        nullable=False)
    registration_request = DBH.relationship("RegistrationRequest",
                                            back_populates="user")

    def __init__(self, email, password, admin=False):
        self.email = email
        self.password = BCRYPT.generate_password_hash(password).decode('utf-8')
        self.registered_on = datetime.now()
        self.admin = admin

    def is_authenticated(self, password):
        """ Quick user check for successful log in
        """
        return bool(BCRYPT.check_password_hash(self.password, password))

    def get_id(self):
        """ useful shorcut for retrieving posgresql id
        """
        return self.id

    def __repr__(self):
        return '<User {0}>'.format(self.email)