get user
This commit is contained in:
36
allfence.py
36
allfence.py
@@ -3,16 +3,15 @@ import bcrypt
|
||||
def create_user(db, login_info, user_info):
|
||||
|
||||
"""
|
||||
Creates a new user
|
||||
Creates a new user in the database
|
||||
|
||||
Parameters:
|
||||
db (psycopg2.connection): connection to postgres database
|
||||
login_info (dict of str:int): username and password info
|
||||
user_info (dict of str:int): name and dob info
|
||||
Args:
|
||||
db (psycopg2.connection): connection to postgres database
|
||||
login_info (dict of str:int): username and password info
|
||||
user_info (dict of str:int): name and dob info
|
||||
|
||||
Returns:
|
||||
bool: success of user creation
|
||||
str: result message
|
||||
bool, str: status, message
|
||||
"""
|
||||
|
||||
username, password = login_info["username"], login_info["password"]
|
||||
@@ -28,8 +27,27 @@ def create_user(db, login_info, user_info):
|
||||
db.commit()
|
||||
return True, "Success"
|
||||
|
||||
def get_user(db, id):
|
||||
pass
|
||||
def get_user_details(db, user_id):
|
||||
|
||||
"""
|
||||
Gets the details of a user based on their id
|
||||
|
||||
Args:
|
||||
db (psycopg2.connection): connection to postgres database
|
||||
id (int): user id
|
||||
|
||||
Returns:
|
||||
bool, dict of str to str, dict of str to str: user existance, login info (username, password), user info (name, dob)
|
||||
"""
|
||||
|
||||
with db:
|
||||
with db.cursor() as curs:
|
||||
curs.execute("SELECT * FROM Users WHERE id = %s", (user_id,))
|
||||
user = curs.fetchall()
|
||||
if not user:
|
||||
return False, {}, {}
|
||||
user = user[0]
|
||||
return True, {"username": user[1], "password_hash": user[2]}, {"name": user[3], "dob": user[4]}
|
||||
|
||||
def create_event(db):
|
||||
pass
|
||||
|
||||
8
app.py
8
app.py
@@ -11,14 +11,16 @@ db_connection = sql.connect(
|
||||
host=HOST,
|
||||
port = PORT
|
||||
)
|
||||
|
||||
# Create databases
|
||||
with db_connection.cursor() as cursor:
|
||||
cursor.execute(dedent("""
|
||||
CREATE TABLE IF NOT EXISTS Users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name varchar(255),
|
||||
username varchar(255),
|
||||
dob varchar(255),
|
||||
password_hash varchar(255)
|
||||
password_hash varchar(255),
|
||||
name varchar(255),
|
||||
dob varchar(255)
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS Events (
|
||||
id SERIAL PRIMARY KEY,
|
||||
|
||||
Reference in New Issue
Block a user