summaryrefslogtreecommitdiffstats
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
parent422a8cc47489aa44b852ff0add1ef6ea63cfc1ff (diff)
downloadfatcat-03df0b8a6d1285fa4aa17e6c4216dd2716a9ac47.tar.gz
fatcat-03df0b8a6d1285fa4aa17e6c4216dd2716a9ac47.zip
account page and renaming
-rw-r--r--python/fatcat_web/__init__.py12
-rw-r--r--python/fatcat_web/auth.py14
-rw-r--r--python/fatcat_web/routes.py31
-rw-r--r--python/fatcat_web/templates/auth_account.html27
-rw-r--r--python/fatcat_web/templates/base.html15
-rw-r--r--python/fatcat_web/templates/editor_changelog.html4
-rw-r--r--python/fatcat_web/templates/editor_view.html4
7 files changed, 85 insertions, 22 deletions
diff --git a/python/fatcat_web/__init__.py b/python/fatcat_web/__init__.py
index 9cd5f812..0afee70e 100644
--- a/python/fatcat_web/__init__.py
+++ b/python/fatcat_web/__init__.py
@@ -23,21 +23,17 @@ oauth = OAuth(app)
sentry = Sentry(app)
conf = fatcat_client.Configuration()
-conf.host = "http://localhost:9411/v0"
+conf.host = Config.FATCAT_API_HOST
api = fatcat_client.DefaultApi(fatcat_client.ApiClient(conf))
+from fatcat_web import routes, auth
+
if Config.FATCAT_API_AUTH_TOKEN:
print("Found and using privileged token (eg, for account signup)")
- priv_conf = fatcat_client.Configuration()
- priv_conf.api_key["Authorization"] = Config.FATCAT_API_AUTH_TOKEN
- priv_conf.api_key_prefix["Authorization"] = "Bearer"
- priv_conf.host = 'http://localhost:9411/v0'
- priv_api = fatcat_client.DefaultApi(fatcat_client.ApiClient(local_conf))
+ priv_api = auth.auth_api(Config.FATCAT_API_AUTH_TOKEN)
else:
print("No privileged token found")
priv_api = None
-from fatcat_web import routes, auth
-
gitlab_bp = create_flask_blueprint(Gitlab, oauth, auth.handle_oauth)
app.register_blueprint(gitlab_bp, url_prefix='/auth/gitlab')
diff --git a/python/fatcat_web/auth.py b/python/fatcat_web/auth.py
index 385f5c49..c6e6f04c 100644
--- a/python/fatcat_web/auth.py
+++ b/python/fatcat_web/auth.py
@@ -1,10 +1,17 @@
from flask import Flask, render_template, send_from_directory, request, \
- url_for, abort, g, redirect, jsonify, session
-from fatcat_web import login_manager, api
+ url_for, abort, g, redirect, jsonify, session, flash
+from fatcat_web import login_manager, api, Config
from flask_login import logout_user, login_user, UserMixin
import pymacaroons
+import fatcat_client
+def auth_api(token):
+ conf = fatcat_client.Configuration()
+ conf.api_key["Authorization"] = token
+ conf.api_key_prefix["Authorization"] = "Bearer"
+ conf.host = Config.FATCAT_API_HOST
+ return fatcat_client.DefaultApi(fatcat_client.ApiClient(conf))
def handle_logout():
logout_user()
@@ -31,7 +38,7 @@ def handle_token_login(token):
session['api_token'] = token
session['editor'] = editor
login_user(load_user(editor_id))
- return redirect("/")
+ return redirect("/auth/account")
# This will need to login/signup via fatcatd API, then set token in session
def handle_oauth(remote, token, user_info):
@@ -70,6 +77,7 @@ def load_user(editor_id):
token = session['api_token']
user = UserMixin()
user.id = editor_id
+ user.editor_id = editor_id
user.username = editor['username']
user.token = token
return user
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 ###########################################################
diff --git a/python/fatcat_web/templates/auth_account.html b/python/fatcat_web/templates/auth_account.html
new file mode 100644
index 00000000..57155722
--- /dev/null
+++ b/python/fatcat_web/templates/auth_account.html
@@ -0,0 +1,27 @@
+{% extends "base.html" %}
+{% block body %}
+
+<h1>Your Account</h1>
+
+<p><b>Username:</b> <code>{{ current_user.username }}</code>
+<p><b>Editor Id:</b> <code><a href="/editor/{{ current_user.editor_id }}">{{ current_user.editor_id }}</a></code>
+
+<div>
+<p>Change username:
+<form class="" role="change_username" action="/auth/change_username" method="post">
+ <div class="ui form">
+ <div class="ui action input medium fluid">
+ <input type="text" name="username" value="{{ current_user.username }}" aria-label="account username">
+ <button class="ui button">Update</button>
+ </div>
+ </div>
+</form>
+</div>
+
+<p>In the future, you might be able to...
+<ul>
+ <li>Create a bot user
+ <li>Generate an API token
+</ul>
+
+{% endblock %}
diff --git a/python/fatcat_web/templates/base.html b/python/fatcat_web/templates/base.html
index 892ca788..27b163d2 100644
--- a/python/fatcat_web/templates/base.html
+++ b/python/fatcat_web/templates/base.html
@@ -34,7 +34,7 @@
{{ current_user.username }} <i class="dropdown icon"></i>
<div class="menu">
<a class="item" href="/editgroup/current"><i class="edit icon"></i>Edits in Progress</a>
- <a class="item" href="/editor/{{ current_user.id }}/changelog"><i class="history icon"></i>History</a>
+ <a class="item" href="/editor/{{ current_user.editor_id }}/changelog"><i class="history icon"></i>History</a>
<div class="divider"></div>
<a class="item" href="/auth/account"><i class="user icon"></i>Account</a>
<a class="item" href="/auth/logout"><i class="sign out icon"></i>Logout</a>
@@ -51,6 +51,19 @@
<!-- 4em top margin is "enough" -->
<main class="ui main container" style="margin-top: 6em; margin-bottom: 2em;">
+{% with messages = get_flashed_messages() %}
+ {% if messages %}
+ <div class="ui message">
+ {# Needs more javascript: <i class="close icon"></i> #}
+ <div class="header">Now Hear This!</div>
+ <ul class="list">
+ {% for message in messages %}
+ <li>{{ message }}
+ {% endfor %}
+ </ul>
+ </div>
+ {% endif %}
+{% endwith %}
{% block fullbody %}
<div class="ui container text">
{% block body %}Nothing to see here.{% endblock %}
diff --git a/python/fatcat_web/templates/editor_changelog.html b/python/fatcat_web/templates/editor_changelog.html
index 79127312..785c19bd 100644
--- a/python/fatcat_web/templates/editor_changelog.html
+++ b/python/fatcat_web/templates/editor_changelog.html
@@ -3,8 +3,8 @@
<h1 class="ui header">Editor Changelog: {{ editor.username }}
<div class="sub header">
- <a href="/editor/{{editor.id}}">
- <code>editor {{ editor.id }}</code>
+ <a href="/editor/{{editor.editor_id}}">
+ <code>editor {{ editor.editor_id }}</code>
</a>
</div>
</h1>
diff --git a/python/fatcat_web/templates/editor_view.html b/python/fatcat_web/templates/editor_view.html
index c9b61f5d..eef4f040 100644
--- a/python/fatcat_web/templates/editor_view.html
+++ b/python/fatcat_web/templates/editor_view.html
@@ -3,10 +3,10 @@
<h1 class="ui header">{{ editor.username }}
<div class="sub header">
- <code>editor {{ editor.id }}</code>
+ <code>editor {{ editor.editor_id }}</code>
</div>
</h1>
-<p><b><a href="/editor/{{ editor.id }}/changelog">View editor's changelog</a></b>
+<p><b><a href="/editor/{{ editor.editor_id }}/changelog">View editor's changelog</a></b>
{% endblock %}