summaryrefslogtreecommitdiffstats
path: root/python/fatcat_web/routes.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/fatcat_web/routes.py')
-rw-r--r--python/fatcat_web/routes.py78
1 files changed, 70 insertions, 8 deletions
diff --git a/python/fatcat_web/routes.py b/python/fatcat_web/routes.py
index 998697bc..789d7bed 100644
--- a/python/fatcat_web/routes.py
+++ b/python/fatcat_web/routes.py
@@ -2,8 +2,10 @@
import os
import json
from flask import Flask, render_template, send_from_directory, request, \
- url_for, abort, g, redirect, jsonify, session
-from fatcat_web import app, api
+ url_for, abort, g, redirect, jsonify, session, flash
+from flask_login import login_required
+from fatcat_web import app, api, auth_api
+from fatcat_web.auth import handle_token_login, handle_logout, load_user, handle_ia_xauth
from fatcat_client.rest import ApiException
from fatcat_web.search import do_search
@@ -295,12 +297,6 @@ def work_view(ident):
return render_template('deleted_entity.html', entity=entity)
return render_template('work_view.html', work=entity, releases=releases)
-@app.route('/editgroup/current', methods=['GET'])
-def editgroup_current():
- raise NotImplementedError
- #eg = api.get_or_create_editgroup()
- #return redirect('/editgroup/{}'.format(eg.id))
-
@app.route('/editgroup/<ident>', methods=['GET'])
def editgroup_view(ident):
try:
@@ -327,6 +323,17 @@ def editor_changelog(ident):
return render_template('editor_changelog.html', editor=editor,
changelog_entries=changelog_entries)
+@app.route('/editor/<ident>/wip', methods=['GET'])
+def editor_wip(ident):
+ raise NotImplementedError
+ try:
+ editor = api.get_editor(ident)
+ entries = api.get_editor_wip(ident)
+ except ApiException as ae:
+ abort(ae.status)
+ return render_template('editor_changelog.html', editor=editor,
+ entries=entries)
+
@app.route('/changelog', methods=['GET'])
def changelog_view():
try:
@@ -367,6 +374,61 @@ def search():
return render_template('release_search.html', query=query, fulltext_only=fulltext_only)
+### Auth ####################################################################
+
+@app.route('/auth/login')
+def login():
+ # show the user a list of login options
+ return render_template('auth_login.html')
+
+@app.route('/auth/ia/login', methods=['GET', 'POST'])
+def ia_xauth_login():
+ if 'email' in request.form:
+ # if a login attempt...
+ return handle_ia_xauth(request.form.get('email'), request.form.get('password'))
+ # else show form
+ return render_template('auth_ia_login.html')
+
+@app.route('/auth/token_login', methods=['GET', 'POST'])
+def token_login():
+ # show the user a list of login options
+ if 'token' in request.args:
+ return handle_token_login(request.args.get('token'))
+ if 'token' in request.form:
+ 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():
+ handle_logout()
+ return render_template('auth_logout.html')
+
+@app.route('/auth/account')
+@login_required
+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 ###########################################################
@app.errorhandler(404)