From e044493acc9ddc67b568e2e8e609c7b8495f23b8 Mon Sep 17 00:00:00 2001 From: codl Date: Mon, 31 Jul 2017 04:51:11 +0200 Subject: [PATCH] add a settings page that doesn't do much yet. polish? --- lib/__init__.py | 1 + lib/auth.py | 18 ++++++++++++++++++ routes.py | 18 +++++++++++------- templates/index.html | 27 +++++++++++++-------------- templates/settings.html | 14 ++++++++++++++ templates/upload_tweet_archive.html | 1 + 6 files changed, 58 insertions(+), 21 deletions(-) create mode 100644 lib/auth.py create mode 100644 templates/settings.html create mode 100644 templates/upload_tweet_archive.html diff --git a/lib/__init__.py b/lib/__init__.py index e69de29..96e2497 100644 --- a/lib/__init__.py +++ b/lib/__init__.py @@ -0,0 +1 @@ +from .auth import require_auth diff --git a/lib/auth.py b/lib/auth.py new file mode 100644 index 0000000..2dd194f --- /dev/null +++ b/lib/auth.py @@ -0,0 +1,18 @@ +from flask import g, redirect + +def require_auth(fun, redir=True): + + from functools import update_wrapper + def wrapper(*args, **kwargs): + if not g.viewer: + if redir: + return redirect('/') + else: + return 403 + else: + return fun(*args, **kwargs) + + update_wrapper(wrapper, fun) + return wrapper + + diff --git a/routes.py b/routes.py index 306fb31..e0b3984 100644 --- a/routes.py +++ b/routes.py @@ -2,6 +2,7 @@ from app import app from flask import render_template, url_for, redirect, request, g, Response from datetime import datetime import lib.twitter +from lib import require_auth from model import Account, Session, Post, TwitterArchive from app import db import tasks @@ -54,12 +55,9 @@ def twitter_login_step2(): secure=app.config.get("HTTPS")) return resp -@app.route('/upload_twitter_archive', methods=('POST',)) -def upload_twitter_archive(): - if not g.viewer or 'file' not in request.files: - return "no" - return redirect(url_for('index')) - +@app.route('/upload_tweet_archive', methods=('POST',)) +@require_auth +def upload_tweet_archive(): ta = TwitterArchive(account = g.viewer.account, body = request.files['file'].read()) db.session.add(ta) @@ -67,9 +65,15 @@ def upload_twitter_archive(): tasks.import_twitter_archive.s(ta.id).apply_async() - return "cool. your file's being processed probably" + return render_template('upload_tweet_archive.html') + +@app.route('/settings') +@require_auth +def settings(): + return render_template('settings.html') @app.route('/logout') +@require_auth def logout(): if(g.viewer): db.session.delete(g.viewer) diff --git a/templates/index.html b/templates/index.html index a2d4d5c..314b031 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,19 +1,18 @@ {% if g.viewer %} -

Hello, - -{{g.viewer.account.remote_display_name}}! Log out

+

Hello, + + {{g.viewer.account.remote_display_name}}! + Settings + Log out +

-
- Upload your tweet archive: - -
+

your posts ({{g.viewer.account.post_count()}}):

-

your posts ({{g.viewer.account.post_count()}}):

-{% for post in posts %} -

{{post.body}}

+ {% for post in posts %} +

{{post.body}}

+ {% else %} +

no posts :(

+ {% endfor %} {% else %} -

no posts :(

-{% endfor %} -{% else %} -

Hello, stranger! Log in with Twitter

+

Hello, stranger! Log in with Twitter

{% endif %} diff --git a/templates/settings.html b/templates/settings.html new file mode 100644 index 0000000..8e4f3cd --- /dev/null +++ b/templates/settings.html @@ -0,0 +1,14 @@ +

< Back

+ +{% if g.viewer.account.service == 'twitter' %} +
+ Upload your tweet archive: + +
+{% endif %} + +
+ ahh +
+ + diff --git a/templates/upload_tweet_archive.html b/templates/upload_tweet_archive.html new file mode 100644 index 0000000..d7a90f8 --- /dev/null +++ b/templates/upload_tweet_archive.html @@ -0,0 +1 @@ +

Your archive will be processed shortly. Back