Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
newr1/location_app/app/functions/auth/login.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
48 lines (41 sloc)
1.16 KB
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
import sqlite3 as sql | |
from app.functions.auth import base | |
def login(data): | |
""" | |
Takes in data for login and checks if the data | |
matches with the one in the database and returns | |
'success' or an error message | |
""" | |
base.create() | |
_status = check_login_data(data) | |
return _status | |
def check_login_data(data): | |
""" | |
Checks the validity of inputed data, if | |
the username is admin then other checks | |
aren't made | |
""" | |
_status = check_empty(data) | |
if _status == "ok": | |
if data['username'] == "admin": | |
return "success" | |
if not base.user_exists(data['username']): | |
return "no_id" | |
if not base.compare(data['username'], | |
data['password'], | |
"password"): | |
return "wrong_pass" | |
return "success" | |
else: | |
return _status | |
def check_empty(data): | |
""" | |
Checks if all the fields in the dictionary are filled, | |
if not tells which one is missing | |
""" | |
if data['username'] == "": | |
return "empty_id" | |
elif data['password'] == "": | |
return "empty_pass" | |
else: | |
return "ok" |