user addition
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
|||||||
|
data
|
||||||
|
test.py
|
||||||
TODO.md
|
TODO.md
|
||||||
.venv
|
.venv
|
||||||
__pycache__
|
__pycache__
|
||||||
30
allfence.py
30
allfence.py
@@ -1,10 +1,32 @@
|
|||||||
from hashlib import sha256
|
import bcrypt
|
||||||
|
|
||||||
def create_user(db, login_info, user_info):
|
def create_user(db, login_info, user_info):
|
||||||
pass
|
|
||||||
|
|
||||||
def update_user(db, login_info, user_info):
|
"""
|
||||||
pass
|
Creates a new user
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: success of user creation
|
||||||
|
str: result message
|
||||||
|
"""
|
||||||
|
|
||||||
|
username, password = login_info["username"], login_info["password"]
|
||||||
|
password_hash = bcrypt.hashpw(password.encode(), bcrypt.gensalt()).decode()
|
||||||
|
name, dob = user_info["name"], user_info["dob"]
|
||||||
|
with db:
|
||||||
|
with db.cursor() as curs:
|
||||||
|
curs.execute("SELECT * FROM Users WHERE username = %s", (username,))
|
||||||
|
conflicts = curs.fetchall()
|
||||||
|
if conflicts:
|
||||||
|
return False, "Duplicate username"
|
||||||
|
curs.execute("INSERT INTO Users (username, password_hash, name, dob) VALUES (%s, %s, %s, %s)", (username, password_hash, name, dob))
|
||||||
|
db.commit()
|
||||||
|
return True, "Success"
|
||||||
|
|
||||||
def get_user(db, id):
|
def get_user(db, id):
|
||||||
pass
|
pass
|
||||||
|
|||||||
8
app.py
8
app.py
@@ -1,6 +1,7 @@
|
|||||||
import allfence as af
|
import allfence as af
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
import psycopg2 as sql
|
import psycopg2 as sql
|
||||||
|
from textwrap import dedent
|
||||||
|
|
||||||
DB_NAME, USER, PASSWORD, HOST, PORT = "database", "user", "password", "localhost", "5432"
|
DB_NAME, USER, PASSWORD, HOST, PORT = "database", "user", "password", "localhost", "5432"
|
||||||
db_connection = sql.connect(
|
db_connection = sql.connect(
|
||||||
@@ -10,8 +11,8 @@ db_connection = sql.connect(
|
|||||||
host=HOST,
|
host=HOST,
|
||||||
port = PORT
|
port = PORT
|
||||||
)
|
)
|
||||||
db_cursor = db_connection.cursor()
|
with db_connection.cursor() as cursor:
|
||||||
db_cursor.execute("""
|
cursor.execute(dedent("""
|
||||||
CREATE TABLE IF NOT EXISTS Users (
|
CREATE TABLE IF NOT EXISTS Users (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
name varchar(255),
|
name varchar(255),
|
||||||
@@ -33,8 +34,7 @@ CREATE TABLE IF NOT EXISTS Tournaments (
|
|||||||
end_date varchar(255),
|
end_date varchar(255),
|
||||||
events varchar(255)
|
events varchar(255)
|
||||||
);
|
);
|
||||||
""")
|
"""))
|
||||||
|
|
||||||
|
|
||||||
HOST, PORT = "0.0.0.0", 8000
|
HOST, PORT = "0.0.0.0", 8000
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
bcrypt==5.0.0
|
||||||
blinker==1.9.0
|
blinker==1.9.0
|
||||||
click==8.3.1
|
click==8.3.1
|
||||||
Flask==3.1.2
|
Flask==3.1.2
|
||||||
|
|||||||
Reference in New Issue
Block a user