Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
16 changed files
with
355 additions
and
105 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import sqlite3 as sql | ||
from datetime import datetime | ||
|
||
|
||
database_user = "app/databases/users.db" | ||
database_locations = 'app/databases/locations.db' | ||
|
||
def create(): | ||
with sql.connect(database_user) as cur: | ||
try: | ||
cur.execute("CREATE TABLE UserDatabase(username VARCHAR2(20), password VARCHAR2(20), realname VARCHAR2(20), gender VARCHAR2(20), dob VARCHAR2(20), height VARCHAR2(20), weight VARCHAR2(20));") | ||
except: | ||
pass | ||
|
||
def user_exists(username): | ||
with sql.connect(database_user) as cur: | ||
com = f"SELECT count(*) FROM UserDatabase WHERE username='{username}';" | ||
print(com) | ||
res = cur.execute(com).fetchone()[0] | ||
if res == 0: | ||
return False | ||
else: | ||
return True | ||
|
||
def tid_exists(username): | ||
with sql.connect(database_locations) as cur: | ||
com = f"SELECT count(*) FROM Location WHERE tid='{username}';" | ||
print(com) | ||
res = cur.execute(com).fetchone()[0] | ||
if res == 0: | ||
return False | ||
else: | ||
return True | ||
|
||
def compare(username, value_in, value_type): | ||
with sql.connect(database_user) as cur: | ||
com = f"SELECT {value_type} FROM UserDatabase WHERE username='{username}';" | ||
print(com) | ||
res = cur.execute(com).fetchone()[0] | ||
print(f"comparing - {value_in} == {res}") | ||
if value_in == res: | ||
return True | ||
else: | ||
return False | ||
|
||
def check_month(month, day): | ||
if month in [1, 3, 5, 7, 8, 10, 12]: | ||
if (day > 0 and day <= 31): | ||
return True | ||
else: | ||
return False | ||
elif month == 2: | ||
if (day > 0 and day <= 28): | ||
return True | ||
else: | ||
return False | ||
else: | ||
if (day > 0 and day <= 30): | ||
return True | ||
else: | ||
return False | ||
|
||
def check_date(day, month, year): | ||
today = datetime.today().strftime('%Y-%m-%d').split("-") | ||
if int(year) > int(today[0]): | ||
return False | ||
elif int(year) == int(today[0]): | ||
if int(month) >= int(today[1]): | ||
return False | ||
else: | ||
if int(day) >= int(today[2]): | ||
return False | ||
else: | ||
return check_month(int(today[1]), int(today[2])) | ||
else: | ||
return check_month(int(month), int(day)) | ||
|
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,52 @@ | ||
import sqlite3 as sql | ||
from app.functions.auth import base | ||
|
||
|
||
database_user = "app/databases/users.db" | ||
database_locations = 'app/databases/locations.db' | ||
|
||
def change_password(data): | ||
base.create() | ||
_status = check_pass_data(data) | ||
if _status == "success": | ||
new_password(data) | ||
return _status | ||
|
||
def check_pass_data(data): | ||
_status = check_empty(data) | ||
if _status == "ok": | ||
if base.tid_exists(data['username']): | ||
_date = f"{data['day']}-{data['month']}-{data['year']}" | ||
if not base.compare(data['username'], _date, "dob"): | ||
return "wrong_date" | ||
if not (data['password'] == data['r_password']): | ||
return "pass_no_match" | ||
return "success" | ||
return "no_user" | ||
else: | ||
return _status | ||
|
||
|
||
def check_empty(data): | ||
if data['username'] == "": | ||
return "empty_id" | ||
elif data['day'] == "0": | ||
return "empty_day" | ||
elif data['month'] == "0": | ||
return "empty_month" | ||
elif data['year'] == "0": | ||
return "empty_year" | ||
elif data['password'] == "": | ||
return "empty_pass" | ||
else: | ||
return "ok" | ||
|
||
def new_password(data): | ||
con = sql.connect(database_user) | ||
cur = con.cursor() | ||
com = f"UPDATE UserDatabase SET password='{data['password']}' WHERE username='{data['username']}';" | ||
print(com) | ||
cur.execute(com) | ||
con.commit() | ||
cur.close() | ||
con.close() |
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,77 @@ | ||
import sqlite3 as sql | ||
from app.functions.auth import base | ||
|
||
|
||
database_user = "app/databases/users.db" | ||
database_locations = 'app/databases/locations.db' | ||
|
||
def create_profile(data): | ||
base.create() | ||
_status = check_prof_data(data) | ||
if _status == "success": | ||
make_user(data) | ||
return _status | ||
|
||
def check_prof_data(data): | ||
_status = check_empty(data) | ||
if _status == "ok": | ||
if base.tid_exists(data['username']): | ||
if not base.user_exists(data['username']): | ||
if not (data['password'] == data['r_password']): | ||
return "pass_no_match" | ||
elif not base.check_date(data['day'], data['month'], data['year']): | ||
return "bad_date" | ||
else: | ||
return "success" | ||
else: | ||
return "user_exists" | ||
else: | ||
return "no_id" | ||
return _status | ||
|
||
def check_empty(data): | ||
if data['username'] == "": | ||
return "empty_id" | ||
elif data['realname'] == "": | ||
return "empty_name" | ||
elif data['day'] == "0": | ||
return "empty_day" | ||
elif data['month'] == "0": | ||
return "empty_month" | ||
elif data['year'] == "0": | ||
return "empty_year" | ||
elif data['gender'] == "": | ||
return "empty_gender" | ||
elif data['height'] == "": | ||
return "empty_height" | ||
elif data['weight'] == "": | ||
return "empty_weight" | ||
elif data['password'] == "": | ||
return "empty_pass" | ||
else: | ||
return "ok" | ||
|
||
def make_user(data): | ||
con = sql.connect(database_user) | ||
cur = con.cursor() | ||
_date = f"{data['day']}-{data['month']}-{data['year']}" | ||
com = f"INSERT INTO UserDatabase values('{data['username']}','{data['password']}','{data['realname']}','{data['gender']}','{_date}','{data['height']}','{data['weight']}');" | ||
print(com) | ||
cur.execute(com) | ||
con.commit() | ||
cur.close() | ||
con.close() | ||
|
||
|
||
# ImmutableMultiDict([ | ||
# ('username', '69'), | ||
# ('realname', 'Adi'), | ||
# ('day', '23'), | ||
# ('month', '1'), | ||
# ('year', '1998'), | ||
# ('gender', 'male'), | ||
# ('height', '183'), | ||
# ('weight', '75'), | ||
# ('password', 'fisgib-duwxut-4Rowhi'), | ||
# ('r_password', 'fisgib-duwxut-4Rowhi')]) | ||
|
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,32 @@ | ||
import sqlite3 as sql | ||
from app.functions.auth import base | ||
|
||
|
||
database_user = "app/databases/users.db" | ||
database_locations = 'app/databases/locations.db' | ||
|
||
def login(data): | ||
base.create() | ||
l_status = check_login_data(data) | ||
return l_status | ||
|
||
def check_login_data(data): | ||
_status = check_empty(data) | ||
if _status == "ok": | ||
if data['username'] == "admin": | ||
return "success" | ||
if not base.user_exists(data['username']): | ||
return "no_user" | ||
if not base.compare(data['username'], data['password'], "password"): | ||
return "wrong_password" | ||
return "success" | ||
else: | ||
return _status | ||
|
||
def check_empty(data): | ||
if data['username'] == "": | ||
return "empty_id" | ||
elif data['password'] == "": | ||
return "empty_pass" | ||
else: | ||
return "ok" |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.