2019-04-11 21:56:55 +00:00
|
|
|
from geruecht import db
|
|
|
|
from geruecht import bcrypt
|
|
|
|
|
|
|
|
class User(db.Model):
|
2019-04-17 12:46:46 +00:00
|
|
|
""" Database Object for User
|
|
|
|
|
|
|
|
Table for all safed User
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
id: Id in Database as Primary Key.
|
|
|
|
userID: ID for the User maybe to Link?
|
|
|
|
username: Username of the User to Login
|
|
|
|
firstname: Firstname of the User
|
|
|
|
Lastname: Lastname of the User
|
|
|
|
group: Which group is the User? moneymaster, gastro, user or bar?
|
|
|
|
password: salted hashed password for the User.
|
|
|
|
"""
|
2019-04-11 21:56:55 +00:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
userID = db.Column(db.String, nullable=False, unique=True)
|
|
|
|
username = db.Column(db.String, nullable=False, unique=True)
|
|
|
|
firstname = db.Column(db.String, nullable=False)
|
|
|
|
lastname = db.Column(db.String, nullable=False)
|
|
|
|
group = db.Column(db.String, nullable=False)
|
|
|
|
password = db.Column(db.String, nullable=False)
|
|
|
|
|
2019-04-23 18:26:20 +00:00
|
|
|
geruechte = db.relationship('CreditList', backref='user', lazy=True)
|
|
|
|
|
2019-04-11 21:56:55 +00:00
|
|
|
def toJSON(self):
|
2019-04-17 12:46:46 +00:00
|
|
|
""" Create Dic to dump in JSON
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A Dic with static Attributes.
|
|
|
|
"""
|
2019-04-11 21:56:55 +00:00
|
|
|
dic = {
|
2019-04-12 12:51:37 +00:00
|
|
|
"userId": self.userID,
|
2019-04-11 21:56:55 +00:00
|
|
|
"username": self.username,
|
|
|
|
"firstname": self.firstname,
|
|
|
|
"lastname": self.lastname,
|
|
|
|
"group": self.group,
|
|
|
|
}
|
|
|
|
return dic
|
|
|
|
|
|
|
|
def login(self, password):
|
2019-04-17 12:46:46 +00:00
|
|
|
""" Login for the User
|
|
|
|
|
|
|
|
Only check the given Password:
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A Bool. True if the password is correct and False if it isn't.
|
|
|
|
"""
|
2019-04-11 21:56:55 +00:00
|
|
|
return True if bcrypt.check_password_hash(self.password, password) else False
|
|
|
|
|