-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added security functionality, recipe-materials relationship
- Loading branch information
Showing
6 changed files
with
78 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from db import db | ||
|
||
class UserModel(db.Model): | ||
__tablename__ = 'users' | ||
|
||
id = db.Column(db.Integer, primary_key=True) | ||
username = db.Column(db.String(80)) | ||
password = db.Column(db.String(80)) | ||
|
||
def __init__(self, username, password): | ||
self.username = username | ||
self.password = password | ||
|
||
def save_to_db(self): | ||
db.session.add(self) | ||
db.session.commit() | ||
|
||
def json(self): | ||
return {'id' : self.id, | ||
'username' : self.username, | ||
'password' : self.password, | ||
} | ||
|
||
@classmethod | ||
def find_by_username(cls, username): | ||
return cls.query.filter_by(username=username).first() | ||
|
||
@classmethod | ||
def find_by_id(cls, _id): | ||
return cls.query.filter_by(id=_id).first() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from werkzeug.security import safe_str_cmp | ||
from models.user import UserModel | ||
|
||
def authenticate(username, password): | ||
user = UserModel.find_by_username(username) | ||
if user and safe_str_cmp(password,user.password): | ||
return user | ||
|
||
def identity(payload): | ||
user_id = payload['identity'] | ||
return UserModel.find_by_id(user_id) |