diff --git a/servicePoints/templates/create.html b/servicePoints/templates/create.html index 73a9e65ca8266a72fb9dda9818d263f9476a02f3..a6ad121a28229cd1b45e97a4004b08717e77efa0 100644 --- a/servicePoints/templates/create.html +++ b/servicePoints/templates/create.html @@ -1,38 +1,43 @@ <!DOCTYPE html> <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> - Student Organization - <input type="text" name="orgName"/> - </p> - <p> - Your Name - <input type="text" name="fullname"/> - </p> + <title>ServicePoints</title> <p> - Username - <input type="text" name="username"/> - </p> - <p> - Email - <input type="text" name="email"/> - </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> + <label for="orgName">Select an Organization:</label> + <select name="orgName" id="orgName"> + <option value="NONE">Choose Later</option> + {% for org in orgs %} + <option value="{{org.orgName}}">{{org.orgName}}</option> + {% endfor %} + </select> + </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> - Password - <input type="password" name="password"/> + Have an account? + <a href="/accounts/login/">Log in</a> </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/userProfile.html b/servicePoints/templates/userProfile.html index 6ffce25dab58858e3af66680ce72c286144a3c3f..c3a0c83ca90bc23239cfa3392c1cc77ae1145841 100644 --- a/servicePoints/templates/userProfile.html +++ b/servicePoints/templates/userProfile.html @@ -12,7 +12,17 @@ <a href="/accounts/logout/">logout</a> <a href="/accounts/delete/">delete</a> - + <form action="/accounts/profile/" method="post"> + <p> + <label for="orgName">Select an Organization:</label> + <select name="orgName" id="orgName"> + {% for org in orgs %} + <option value="{{org.orgName}}">{{org.orgName}}</option> + {% endfor %} + </select> + </p> + <input type="submit" name="signup" value="Update Org" /> + </form> </body> diff --git a/servicePoints/views/accounts.py b/servicePoints/views/accounts.py index c23453f976afe5bf203107f554ebd489541b78e7..73daee088c974f920dcd0d6799efa6aefaf7b969 100644 --- a/servicePoints/views/accounts.py +++ b/servicePoints/views/accounts.py @@ -73,11 +73,8 @@ def create(): 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="create")) - if len(str(flask.request.form['orgName'])) is 0 or len(str(flask.request.form['email'])) is 0: + if len(str(flask.request.form['username'])) is 0 or len(str(flask.request.form['email'])) is 0: return flask.redirect(flask.url_for('incompleteForm', prev="create")) - - if len(str(flask.request.form['username'])) is 0: - return flask.redirect(flask.url_for('incompleteForm', prev="create")) flask.session['username'] = flask.request.form['username'] flask.session['fullname'] = flask.request.form['fullname'] @@ -95,7 +92,11 @@ def create(): return flask.redirect(flask.url_for('index')) - context = {} + cursor = servicePoints.model.get_db() + + cur = cursor.execute("SELECT * FROM orgs") + orgs = cur.fetchall() + context = {"orgs": orgs} return render_template('create.html', **context) @servicePoints.app.route('/accounts/createOrg/', methods=['GET', 'POST']) @@ -263,9 +264,21 @@ def food(): context = {} return render_template('food.html', **context) -@servicePoints.app.route('/accounts/profile/') +@servicePoints.app.route('/accounts/profile/', methods=['GET', 'POST']) def profile(): - context = {} + + if flask.request.method == 'POST': + orgName = str(flask.request.form['orgName']) + + cur = servicePoints.model.get_db() + cur.execute('UPDATE users SET orgName = ? WHERE username = ?', + (orgName, flask.session['username'])) + return flask.redirect(flask.url_for('index')) + + cursor = servicePoints.model.get_db() + cur = cursor.execute("SELECT * FROM orgs") + orgs = cur.fetchall() + context = {"orgs": orgs} return render_template('userProfile.html', **context) @servicePoints.app.route('/images/<path:filename>', methods=['GET', 'POST']) @@ -310,8 +323,7 @@ def tutorsu(): username = flask.session["username"] cur2 = cursor.execute('SELECT email FROM users WHERE ' - 'username =:who', - {"who": username}) + 'username =:who', {"who": username}) emails = cur2.fetchall() # Add database info to context