Esempio n. 1
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(100))
    pwdhash = db.Column(db.String())
    admin = db.Column(db.Boolean())
    notes = db.Column(db.UnicodeText)
    roles = db.Column(db.String(4))

    def __init__(self, username, password, admin=False, notes='', roles='R'):
        self.username = username
        self.pwdhash = generate_password_hash(password)
        self.admin = admin
        self.notes = notes
        self.roles = self.admin and self.roles or ''

    def is_admin(self):
        return self.admin

    def check_password(self, password):
        return check_password_hash(self.pwdhash, password)

    def is_authenticated(self):
        return True

    def is_active(self):
        return True

    def is_anonymous(self):
        return False

    def get_id(self):
        return unicode(self.id)
Esempio n. 2
0
class User(db.Model):
	id = db.Column(db.Integer , primary_key = True)
	username = db.Column(db.String(10))
	pwdhash = db.Column(db.String())
	admin = db.Column(db.Boolean())

	def __init__(self,username,password,admin = False):
		self.username = username
		self.pwdhash = generate_password_hash(password) #here I need to generate_password_hash of password input
		self.admin = admin

	def check_user_password(self,password):
		return check_password_hash(self.pwdhash,password)

	def is_admin(self):
		return self.admin

	def is_authenticated(self):
		return True

	def is_active(self):
		return True

	def is_anonymous(self):
		return False

	def get_id(self):
		return self.id
Esempio n. 3
0
class Serie(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(255))
    genre = db.Column(db.String(255))
    seasons = db.Column(db.Integer)
    imdbRating = db.Column(db.Float(asdecimal=True))
    isActive = db.Column(db.Boolean())

    def __init__(self, title, genre, seasons, imdbRating, isActive):
        self.title = title
        self.genre = genre
        self.seasons = seasons
        self.imdbRating = imdbRating
        self.isActive = isActive

    def __repr_(self):
        return 'Serie {0}'.format(self.id)
Esempio n. 4
0
class User(db.Model, UserMixin):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(200))
    # Hash the password
    password = db.Column(db.String(255))
    rol = db.Column(db.String(255))
    active = db.Column('is_active',
                       db.Boolean(),
                       nullable=False,
                       server_default='1')
    email = db.Column(db.String(255), nullable=False, unique=True)
    email_confirmed_at = db.Column(db.DateTime())
    # Relationships
    roles = db.relationship('Role', secondary='user_roles')

    @property
    def is_authenticated(self):
        return True

    @property
    def is_active(self):
        return True

    @property
    def is_anonymous(self):
        return False

    def get_id(self):
        return str(self.id)

    def __init__(self, username, password, rol, email):
        self.username = username
        self.password = password
        self.rol = rol
        self.email = email

    def __repr__(self):
        return '<User %r>' % (self.username)

    def check_password(self, password):
        # Check for the hashed password
        return check_password_hash(self.password, password)
Esempio n. 5
0
class Users(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(10), nullable=False, unique=True)
    password = db.Column(db.String(), nullable=False)
    datum_registracije = db.Column(db.DateTime(),
                                   nullable=False,
                                   default=datetime.datetime.utcnow())
    uploader = db.Column(db.Boolean(), default=False)

    def __init__(self, username, password, uploader=False):
        self.username = username
        self.password = generate_password_hash(password)
        self.uploader = uploader

    @property
    def is_authenticated(self):
        return True

    @property
    def is_active(self):
        return True

    @property
    def is_anonymus(self):
        return False

    def get_id(self):
        return str(self.id)

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

    def __repr__(self):
        return self.id

    def is_uploader(self):
        return self.uploader

    def __str__(self):
        return str(self.id)
Esempio n. 6
0
class Trava_Users(db.Model):
    __tablename__ = 'trava_users'
    
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(50), nullable=False)
    password = db.Column(db.String(255), nullable=False)
    firstname = db.Column(db.String(50), nullable=False)
    lastname = db.Column(db.String(50), nullable=False)
    dob = db.Column(db.DateTime())
    signup = db.Column(db.DateTime())
    signin = db.Column(db.DateTime())
    active = db.Column(db.Boolean())
    role = db.relationship('Trava_Admin', backref='user', lazy='dynamic')
    picture = db.relationship('Trava_Pictures', backref='user', lazy='dynamic')

    def __repr__(self):
        return f'<User id: {self.id} name: {self.firstname} {self.lastname}>'

    def __str__(self):
        return f'<User id: {self.id} name: {self.firstname} {self.lastname}>'

    def __init__(self, email, password, firstname, lastname, dob):
        self.email = email
        self.password = bcrypt.generate_password_hash(password)
        self.firstname = firstname.lower().capitalize() 
        self.lastname = lastname.lower().capitalize()
        self.dob = dob
        self.signup = datetime.utcnow()
        self.signin = datetime.utcnow()
        self.active = False
    
    def password_hash(self, password):
        return bcrypt.generate_password_hash(password)
    
    def password_check(self, pw_hash, candidate):
        return bcrypt.check_password_hash(pw_hash, candidate)

    def encode_auth_token(self, current_user, exp, name='user_login_token'):
        """Generates the Auth Token"""
        try:
            payload = {
                'name': name,
                'user_id': current_user.id,
                'hashed':current_user.password,
                'exp': datetime.utcnow() + timedelta(seconds=exp),
                'iat': datetime.utcnow(),
                'reset': exp
            }
            
            token = jwt.encode(
                payload,
                app.config.get('SECRET_KEY'),
                algorithm='HS256'
            ).decode("utf-8")

            return token
            
        except Exception as e:
            print(e)
            return e

    def decode_auth_token(self, token):
        try:
            decoded = jwt.decode(
                token, 
                app.config.get('SECRET_KEY'),
                algorithm='HS256'
            )
            return decoded

        except Exception as e :
            print(e)
            return e