-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase_functions.py
37 lines (30 loc) · 1.07 KB
/
database_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from models import Session, User
from typing import Union
def registerUser( dict ):
"""checks if a user is already on the platform, and if they are not, add them to it"""
#TODO add checking
session = Session()
new_user = User( userUUID = dict['uuidRegister'],
username = dict['usernameRegister'],
userEmail = dict['emailRegister'],
password = dict['passwordRegister']
)
session.add(new_user)
session.commit()
session.close()
return 0
def getUserData(usernameLogin: str, type: str) -> Union[str, User, int]:
"""takes the username and returns a dictionary of all the user data"""
session = Session()
user = session.query(User).filter_by(username=usernameLogin).first()
session.close()
if user == None:
return 1
print(user.username)
print(user.password)
if type == 'password':
return user.password
elif type == 'email':
return user.userEmail
elif type == 'all':
return user