summaryrefslogtreecommitdiffstats
path: root/python/fatcat_web/routes.py
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-01-03 21:18:10 -0800
committerBryan Newbold <bnewbold@robocracy.org>2019-01-03 21:18:10 -0800
commit03df0b8a6d1285fa4aa17e6c4216dd2716a9ac47 (patch)
treece6cc7f35a038ff5da26b86184d83441604de024 /python/fatcat_web/routes.py
parent422a8cc47489aa44b852ff0add1ef6ea63cfc1ff (diff)
downloadfatcat-03df0b8a6d1285fa4aa17e6c4216dd2716a9ac47.tar.gz
fatcat-03df0b8a6d1285fa4aa17e6c4216dd2716a9ac47.zip
account page and renaming
Diffstat (limited to 'python/fatcat_web/routes.py')
-rw-r--r--python/fatcat_web/routes.py31
1 files changed, 25 insertions, 6 deletions
diff --git a/python/fatcat_web/routes.py b/python/fatcat_web/routes.py
index 5d46fe0b..07947fd5 100644
--- a/python/fatcat_web/routes.py
+++ b/python/fatcat_web/routes.py
@@ -2,9 +2,10 @@
import os
import json
from flask import Flask, render_template, send_from_directory, request, \
- url_for, abort, g, redirect, jsonify, session
+ url_for, abort, g, redirect, jsonify, session, flash
+from flask_login import login_required
from fatcat_web import app, api
-from fatcat_web.auth import handle_token_login, handle_logout
+from fatcat_web.auth import handle_token_login, handle_logout, load_user, auth_api
from fatcat_client.rest import ApiException
from fatcat_web.search import do_search
@@ -389,6 +390,23 @@ def token_login():
return handle_token_login(request.form.get('token'))
return render_template('auth_token_login.html')
+@app.route('/auth/change_username', methods=['POST'])
+@login_required
+def change_username():
+ # show the user a list of login options
+ if not 'username' in request.form:
+ abort(400)
+ # on behalf of user...
+ user_api = auth_api(session['api_token'])
+ editor = user_api.get_editor(session['editor']['editor_id'])
+ editor.username = request.form['username']
+ editor = user_api.update_editor(editor.editor_id, editor)
+ # update our session
+ session['editor'] = editor.to_dict()
+ load_user(editor.editor_id)
+ flash("Username updated successfully")
+ return redirect('/auth/account')
+
@app.route('/auth/logout')
def logout():
# TODO: clear extra session info
@@ -397,10 +415,11 @@ def logout():
@app.route('/auth/account')
@login_required
-def logout():
- # TODO: clear extra session info
- handle_logout()
- return render_template('auth_logout.html')
+def auth_account():
+ editor = api.get_editor(session['editor']['editor_id'])
+ session['editor'] = editor.to_dict()
+ load_user(editor.editor_id)
+ return render_template('auth_account.html')
### Static Routes ###########################################################