File size: 2,202 Bytes
072a4b4
f2d48c5
3a757df
 
 
 
 
 
03dfe0d
3a757df
7b3e91c
178e0a0
6a3c717
072a4b4
178e0a0
e817f7f
3817395
072a4b4
a43bce8
072a4b4
 
 
e817f7f
 
 
 
 
 
 
 
 
 
178e0a0
7b3e91c
3a757df
7b3e91c
 
 
 
e817f7f
7b3e91c
 
 
 
5674bf3
55173bc
 
de912b6
 
e817f7f
940d4dd
e817f7f
940d4dd
 
 
 
b62b20f
5517543
072a4b4
 
3817395
 
940d4dd
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from pickle import FALSE
from pages.utils import empty
import streamlit as st
import sqlite3
import datetime

# Custom imports
from pages.utils import *
from authenticator import Hasher

def app():

    drop_table = False

    DATABASE = db_path('quiz_maker.db')
    c, conn = db_connect(DATABASE)

    if drop_table:
        st.write("User Table Dropped.")
        query = "DROP TABLE IF EXISTS users"
        c.execute(query)

    query = "CREATE TABLE IF NOT EXISTS users(uct_iso, firstname, lastname, username, email, hashed_password)"
    c.execute(query)

    usernames = []
    emails = []
    
    query = "SELECT username, email FROM users"
    for items in c.execute(query):
        usernames.append(items[0])
        emails.append(items[1])

    st.markdown("## Join")

    with st.form("join_form"):
        first_name = st.text_input("First Name")
        last_name = st.text_input("Last Name")
        user_name = st.text_input("User Name")
        email = st.text_input("Email")
        password1 = st.text_input("Password", type="password")
        password2 = st.text_input("Confirm Password", type="password")
        
        submitted = st.form_submit_button("Submit")

    if empty(first_name) or empty(last_name) or empty(user_name) or \
        empty(email) or empty(password1) or empty(password2):
        st.warning("Complete all inputs.")
    elif submitted and password1.strip() != password2.strip():
        st.warning("The passwords do not match.")
    elif user_name in usernames:
        st.warning("This user name already exists.")
    elif email in emails:
        st.warning("This email is already being used.")
    else:
        uct_iso = datetime.datetime.utcnow().isoformat()
        hashed_password = Hasher(password1).generate()
        st.write(firstname, lastname, username, email, hashed_password)
        query = "INSERT INTO users(uct_iso, firstname, lastname, username, email, hashed_password) VALUES(?, ?, ?, ?, ?, ?)"
        c.execute(query, (uct_iso, first_name, last_name, user_name, email, hashed_password))
        conn.commit()
        conn.close()
        st.success("You have joined.")