Compare commits

..

1 Commits

Author SHA1 Message Date
59de00527d Ignore *.pyc-files for git
All checks were successful
continuous-integration/drone/push Build is passing
2021-06-21 16:12:54 +02:00
2 changed files with 16 additions and 28 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
/.env /.env
*.pyc

View File

@ -5,40 +5,27 @@ from app import app, db
from ki.models import User, Token from ki.models import User, Token
class UserWrongCredentialsException(Exception):
pass
class UserAllreadyLoggedInException(Exception):
pass
def auth(username, password): def auth(username, password):
auth_file_path = app.config["KI_DATA_DIR"] + "/auth.yml" auth_file_path = app.config["KI_DATA_DIR"] + "/auth.yml"
with open(auth_file_path, "r") as auth_file_stream: with open(auth_file_path, "r") as auth_file_stream:
try:
users = yaml.safe_load(auth_file_stream) users = yaml.safe_load(auth_file_stream)
except yaml.YAMLError: if username not in users:
print('Could not parse auth.yml.') return None
try:
auth_user = users[username] auth_user = users[username]
if auth_user["password"] != password: if auth_user["password"] != password:
raise UserWrongCredentialsException
except (UserWrongCredentialsException, KeyError):
print('Wrong username/password combination')
return None return None
else:
user = User.query.filter(User.auth_id.__eq__(username)).first() user = User.query.filter(User.auth_id.__eq__(username)).first()
token = Token(token=str(uuid.uuid4()), user=user) if user is None:
user = User(auth_id=username)
db.session.add(user)
token = Token(token=str(uuid.uuid4()), user=user)
db.session.add(token) db.session.add(token)
db.session.commit() db.session.commit()