diff --git a/servicePoints/templates/accountNotFound.html b/servicePoints/templates/accountNotFound.html new file mode 100644 index 0000000000000000000000000000000000000000..af51f6602c25848ef46cf812e0b2512ee59f0446 --- /dev/null +++ b/servicePoints/templates/accountNotFound.html @@ -0,0 +1,19 @@ +<!DOCTYPE html> +<html> + <head> + <link rel="stylesheet" type="text/css" href="/css/style.css"> + <title>ServicePoints</title> + </head> + + <body> + <p> + The Username or Password You've Entered is Incorrect + </p> + <form action="/accounts/accountNotFound/" method="post" enctype="multipart/form-data"> + <input type="submit" name="login" value="Return to Login"/> + </form> + <form action="/accounts/accountNotFound/" method="post" enctype="multipart/form-data"> + <input type="submit" name="createAccount" value="Create Account"/> + </form> + </body> +</html> diff --git a/servicePoints/templates/create.html b/servicePoints/templates/create.html index 3b874f67b084cfc178f7225098c00f799052f644..73a9e65ca8266a72fb9dda9818d263f9476a02f3 100644 --- a/servicePoints/templates/create.html +++ b/servicePoints/templates/create.html @@ -2,9 +2,18 @@ <html> <body> <title>ServicePoints</title> +<p> + Want to register an organization with your new account account? +<a href="/accounts/createOrg/">Register as organization leader</a> +</p> + <form action="/accounts/create/" method="post" enctype="multipart/form-data"> <p> - Name + Student Organization + <input type="text" name="orgName"/> + </p> + <p> + Your Name <input type="text" name="fullname"/> </p> <p> @@ -15,10 +24,6 @@ Email <input type="text" name="email"/> </p> - <p> - Student Organization - <input type="text" name="orgName"/> - </p> <p> Password <input type="password" name="password"/> diff --git a/servicePoints/templates/createOrg.html b/servicePoints/templates/createOrg.html new file mode 100644 index 0000000000000000000000000000000000000000..afecf95f1133a8ca6b7d6616d9361ee0b081ea6f --- /dev/null +++ b/servicePoints/templates/createOrg.html @@ -0,0 +1,38 @@ +<!DOCTYPE html> +<html> +<body> +<title>ServicePoints</title> +<p> + Don't want to register a new student organization? +<a href="/accounts/create/">Register as organization member</a> +</p> + + <form action="/accounts/createOrg/" method="post" enctype="multipart/form-data"> + <p> + New Student Organization Name + <input type="text" name="orgName"/> + </p> + <p> + Your Name + <input type="text" name="fullname"/> + </p> + <p> + Username + <input type="text" name="username"/> + </p> + <p> + Email + <input type="text" name="email"/> + </p> + <p> + Password + <input type="password" name="password"/> + </p> + <input type="submit" name="signup" value="sign up"/> + </form> + <p> + Have an account? + <a href="/accounts/login/">Log in</a> + </p> +</body> +</html> diff --git a/servicePoints/templates/duplicateOrgName.html b/servicePoints/templates/duplicateOrgName.html new file mode 100644 index 0000000000000000000000000000000000000000..0ba69753e6b4bc2482c859ea5a786e7d16cad607 --- /dev/null +++ b/servicePoints/templates/duplicateOrgName.html @@ -0,0 +1,16 @@ +<!DOCTYPE html> +<html> + <head> + <link rel="stylesheet" type="text/css" href="/css/style.css"> + <title>ServicePoints</title> + </head> + + <body> + <p> + This organization already exists + </p> + <form action="/accounts/duplicateOrgName/{{prev}}" method="post" enctype="multipart/form-data"> + <input type="submit" name="return" value="Return to Create Organization"/> + </form> + </body> +</html> diff --git a/servicePoints/templates/duplicateUsername.html b/servicePoints/templates/duplicateUsername.html new file mode 100644 index 0000000000000000000000000000000000000000..b94f158c51c352b760f2daef1e90ff9b5e4528f2 --- /dev/null +++ b/servicePoints/templates/duplicateUsername.html @@ -0,0 +1,16 @@ +<!DOCTYPE html> +<html> + <head> + <link rel="stylesheet" type="text/css" href="/css/style.css"> + <title>ServicePoints</title> + </head> + + <body> + <p> + This username is taken + </p> + <form action="/accounts/duplicateUsername/{{prev}}" method="post" enctype="multipart/form-data"> + <input type="submit" name="return" value="Return to Create Account"/> + </form> + </body> +</html> diff --git a/servicePoints/templates/incompleteForm.html b/servicePoints/templates/incompleteForm.html new file mode 100644 index 0000000000000000000000000000000000000000..21d1d5be6677bba85388b81b663c523c05a9bfbe --- /dev/null +++ b/servicePoints/templates/incompleteForm.html @@ -0,0 +1,16 @@ +<!DOCTYPE html> +<html> + <head> + <link rel="stylesheet" type="text/css" href="/css/style.css"> + <title>ServicePoints</title> + </head> + + <body> + <p> + Please fill out all fields of the form + </p> + <form action="/accounts/incompleteForm/{{prev}}" method="post" enctype="multipart/form-data"> + <input type="submit" name="return" value="Return"/> + </form> + </body> +</html> diff --git a/servicePoints/templates/login.html b/servicePoints/templates/login.html index 8553696052fb3b6bc27166451623a6cc1adfef3a..35583960b5d7fd3743db23441a01d6811ae8eb7b 100644 --- a/servicePoints/templates/login.html +++ b/servicePoints/templates/login.html @@ -5,10 +5,12 @@ <title>insta485</title> </head> <body> - <h1> - <a href="/">/ </a> - <a href="/accounts/create/">create account</a> - </h1> + <p> + <a href="/accounts/create/">create student org member account</a> + </p> + <p> + <a href="/accounts/createOrg/">create student org leader account</a> + </p> </body> diff --git a/servicePoints/templates/orgNotFound.html b/servicePoints/templates/orgNotFound.html new file mode 100644 index 0000000000000000000000000000000000000000..bb037ed1444fad728c3f2cac8b69b1ad34c983cc --- /dev/null +++ b/servicePoints/templates/orgNotFound.html @@ -0,0 +1,19 @@ +<!DOCTYPE html> +<html> + <head> + <link rel="stylesheet" type="text/css" href="/css/style.css"> + <title>ServicePoints</title> + </head> + + <body> + <p> + The Student Organization You've Entered Does Not Exist + </p> + <form action="/accounts/orgNotFound/" method="post" enctype="multipart/form-data"> + <input type="submit" name="registerOrg" value="Register Your Organization"/> + </form> + <form action="/accounts/orgNotFound/" method="post" enctype="multipart/form-data"> + <input type="submit" name="login" value="Return To Login"/> + </form> + </body> +</html> diff --git a/servicePoints/views/__pycache__/accounts.cpython-36.pyc b/servicePoints/views/__pycache__/accounts.cpython-36.pyc index 394d327d3d65b11945112c8fd0612b5e23813cc9..3cb0c4ddf8b903b2865fc47105808f807bf177a3 100644 Binary files a/servicePoints/views/__pycache__/accounts.cpython-36.pyc and b/servicePoints/views/__pycache__/accounts.cpython-36.pyc differ diff --git a/servicePoints/views/accounts.py b/servicePoints/views/accounts.py index 6bfa5b97b50ed2a07264545d87d2483b0c597506..d0160b7ada0ef37e468731a143bc79d3c93079c2 100644 --- a/servicePoints/views/accounts.py +++ b/servicePoints/views/accounts.py @@ -22,7 +22,7 @@ def login(): {"who": flask.request.form['username']}) password_3 = password_1.fetchall() if not password_3: - flask.abort(403) + return flask.redirect(flask.url_for('accountNotFound')) password_2 = password_3[0]['password'] password_4 = password_2.split('$') algorithm = password_4[0] @@ -33,7 +33,7 @@ def login(): hash_obj.update(password_salted.encode('utf-8')) password_hash = hash_obj.hexdigest() if p2word != password_hash: - flask.abort(403) + return flask.redirect(flask.url_for('accountNotFound')) flask.session['username'] = flask.request.form['username'] return flask.redirect(flask.url_for('index')) context = {} @@ -53,39 +53,100 @@ def create(): if 'username' in flask.session: return flask.redirect(flask.url_for('index')) if flask.request.method == 'POST': + cursor = servicePoints.model.get_db().cursor() + name = str(flask.request.form['username']) + orgName = str(flask.request.form['orgName']) + password = str(flask.request.form['password']) + + to_add = (name,) + to_join = (orgName,) + cursor.execute('SELECT * FROM users WHERE username=?', to_add) + if cursor.fetchone() is not None: + return flask.redirect(flask.url_for('duplicateUsername', prev='create')) + + cursor.execute('SELECT * FROM orgs WHERE orgName=?', to_join) + if cursor.fetchone() is None: + return flask.redirect(flask.url_for('orgNotFound')) + + # If a user tries to create an account with an empty string as the + # password, abort(400) + if password == '': + flask.abort(400) - # If a user tries to create an account with an existing username in - # the database, abort(409) flask.session['username'] = flask.request.form['username'] flask.session['fullname'] = flask.request.form['fullname'] flask.session['orgName'] = flask.request.form['orgName'] flask.session['email'] = flask.request.form['email'] flask.session['password'] = flask.request.form['password'] + + pw = hash_pass(flask.session['password']) + data = (flask.session['username'], flask.session['fullname'], + flask.session['email'], flask.session['orgName'], + pw) + cur = servicePoints.model.get_db() + cur.execute("INSERT INTO users(username, fullname, email, orgName, " + "password) VALUES (?, ?, ?, ?, ?)", data) + + return flask.redirect(flask.url_for('index')) + + context = {} + return render_template('create.html', **context) + +@servicePoints.app.route('/accounts/createOrg/', methods=['GET', 'POST']) +def createOrg(): + """Render createOrg page.""" + # If a user is already logged in, redirect to /accounts/edit/ + if 'username' in flask.session: + return flask.redirect(flask.url_for('index')) + if flask.request.method == 'POST': + + # If a user tries to create an account with an existing username in + # the database, abort(409) cursor = servicePoints.model.get_db().cursor() - name = str(flask.session['username']) + name = str(flask.request.form['username']) + orgName = str(flask.request.form['orgName']) to_add = (name,) + to_addOrg = (orgName,) cursor.execute('SELECT * FROM users WHERE username=?', to_add) if cursor.fetchone() is not None: - flask.abort(409) + return flask.redirect(flask.url_for('duplicateUsername', prev='createOrg')) + + cursor.execute('SELECT * FROM orgs WHERE orgName=?', to_addOrg) + if cursor.fetchone() is not None: + return flask.redirect(flask.url_for('duplicateOrgName', prev='createOrg')) # If a user tries to create an account with an empty string as the # password, abort(400) - if flask.session['password'] == '': - flask.abort(400) + if len(str(flask.request.form['password'])) is 0 or len(str(flask.request.form['fullname'])) is 0: + return flask.redirect(flask.url_for('incompleteForm', prev="createOrg")) + + if len(str(flask.request.form['orgName'])) is 0 or len(str(flask.request.form['email'])) is 0: + return flask.redirect(flask.url_for('incompleteForm', prev="createOrg")) + + if len(str(flask.request.form['username'])) is 0: + return flask.redirect(flask.url_for('incompleteForm', prev="createOrg")) + + flask.session['username'] = flask.request.form['username'] + flask.session['fullname'] = flask.request.form['fullname'] + flask.session['orgName'] = flask.request.form['orgName'] + flask.session['email'] = flask.request.form['email'] + flask.session['password'] = flask.request.form['password'] pw = hash_pass(flask.session['password']) data = (flask.session['username'], flask.session['fullname'], flask.session['email'], flask.session['orgName'], pw) + orgData = (flask.session['username'], flask.session['orgName']) cur = servicePoints.model.get_db() + cur.execute("INSERT INTO orgs(username, orgName) VALUES (?, ?)", orgData) cur.execute("INSERT INTO users(username, fullname, email, orgName, " "password) VALUES (?, ?, ?, ?, ?)", data) return flask.redirect(flask.url_for('index')) context = {} - return render_template('create.html', **context) + return render_template('createOrg.html', **context) @servicePoints.app.route('/', methods=['GET', 'POST']) def index(): @@ -116,6 +177,48 @@ def delete(): flask.session.clear() cur.execute('DELETE FROM users WHERE username=?', to_add) - return flask.redirect(flask.url_for('create')) + return flask.redirect(flask.url_for('login')) context = {'username': flask.session['username']} - return render_template('delete.html', **context) \ No newline at end of file + return render_template('delete.html', **context) + +@servicePoints.app.route('/accounts/orgNotFound/', methods=['GET', 'POST']) +def orgNotFound(): + """Render delete page.""" + if flask.request.method == 'POST': + if 'login' in flask.request.form: + return flask.redirect(flask.url_for('login')) + if 'registerOrg' in flask.request.form: + return flask.redirect(flask.url_for('createOrg')) + context = {} + return render_template('orgNotFound.html', **context) + +@servicePoints.app.route('/accounts/accountNotFound/', methods=['GET', 'POST']) +def accountNotFound(): + if flask.request.method == 'POST': + if 'login' in flask.request.form: + return flask.redirect(flask.url_for('login')) + if 'createAccount' in flask.request.form: + return flask.redirect(flask.url_for('create')) + context = {} + return render_template('accountNotFound.html', **context) + +@servicePoints.app.route('/accounts/duplicateUsername/<prev>', methods=['GET', 'POST']) +def duplicateUsername(prev): + if flask.request.method == 'POST': + return flask.redirect(flask.url_for(prev)) + context = {"prev": prev} + return render_template('duplicateUsername.html', **context) + +@servicePoints.app.route('/accounts/duplicateOrgName/', methods=['GET', 'POST']) +def duplicateOrgName(): + if flask.request.method == 'POST': + return flask.redirect(flask.url_for('createOrg')) + context = {} + return render_template('duplicateOrgName.html', **context) + +@servicePoints.app.route('/accounts/incompleteForm/<prev>', methods=['GET', 'POST']) +def incompleteForm(prev): + if flask.request.method == 'POST': + return flask.redirect(flask.url_for(prev)) + context = {"prev": prev} + return render_template('incompleteForm.html', **context) diff --git a/sql/schema.sql b/sql/schema.sql index 74ba94d32c91ea9c1c5f955891c90a9695d227a8..989a33ba15ea34e4501020ef81b0eefb9b1f4e34 100644 --- a/sql/schema.sql +++ b/sql/schema.sql @@ -8,3 +8,9 @@ CREATE TABLE users( password VARCHAR(256) NOT NULL, PRIMARY KEY(username) ); + +CREATE TABLE orgs( + username VARCHAR(20) NOT NULL, + orgName VARCHAR(40) NOT NULL, + PRIMARY KEY(orgName) +); \ No newline at end of file diff --git a/var/servicePoints.sqlite3 b/var/servicePoints.sqlite3 index 9e8299e1f860840844facfaaf6e31a9c86477411..37c9916f2a06b154765e141dbaf03c370f0cc320 100644 Binary files a/var/servicePoints.sqlite3 and b/var/servicePoints.sqlite3 differ