add a settings page that doesn't do much yet. polish?

This commit is contained in:
codl 2017-07-31 04:51:11 +02:00
parent aa92dbe268
commit e044493acc
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
6 changed files with 58 additions and 21 deletions

View File

@ -0,0 +1 @@
from .auth import require_auth

18
lib/auth.py Normal file
View File

@ -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

View File

@ -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)

View File

@ -1,14 +1,13 @@
{% if g.viewer %}
<p>Hello,
<img src="{{g.viewer.account.remote_avatar_url}}"/>
{{g.viewer.account.remote_display_name}}! <a href="/logout">Log out</a></p>
<form action='/upload_twitter_archive' method='post' enctype='multipart/form-data'>
Upload your tweet archive:
<input type="file" name='file'><input type="submit">
</form>
<img src="{{g.viewer.account.remote_avatar_url}}" style='height:1.5em; border-radius:100%; transform:translateY(25%);'/>
{{g.viewer.account.remote_display_name}}!
<a href="{{url_for('settings')}}">Settings</a>
<a href="{{url_for('logout')}}">Log out</a>
</p>
<p>your posts ({{g.viewer.account.post_count()}}):</p>
{% for post in posts %}
<p>{{post.body}}</p>
{% else %}

14
templates/settings.html Normal file
View File

@ -0,0 +1,14 @@
<p><a href="{{url_for('index')}}">&lt; Back</a></p>
{% if g.viewer.account.service == 'twitter' %}
<form action='{{url_for('upload_tweet_archive')}}' method='post' enctype='multipart/form-data'>
Upload your tweet archive:
<input type="file" name='file'><input type="submit">
</form>
{% endif %}
<form method='post' enctype='multipart/form-data'>
ahh
</form>

View File

@ -0,0 +1 @@
<p>Your archive will be processed shortly. <a href="{{url_for('index')}}">Back</a></p>