add a settings page that doesn't do much yet. polish?
This commit is contained in:
parent
aa92dbe268
commit
e044493acc
|
@ -0,0 +1 @@
|
|||
from .auth import require_auth
|
|
@ -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
|
||||
|
||||
|
18
routes.py
18
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)
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
{% 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>
|
||||
<p>Hello,
|
||||
<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>
|
||||
|
||||
<form action='/upload_twitter_archive' method='post' enctype='multipart/form-data'>
|
||||
Upload your tweet archive:
|
||||
<input type="file" name='file'><input type="submit">
|
||||
</form>
|
||||
<p>your posts ({{g.viewer.account.post_count()}}):</p>
|
||||
|
||||
<p>your posts ({{g.viewer.account.post_count()}}):</p>
|
||||
{% for post in posts %}
|
||||
<p>{{post.body}}</p>
|
||||
{% for post in posts %}
|
||||
<p>{{post.body}}</p>
|
||||
{% else %}
|
||||
<p>no posts :(</p>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<p>no posts :(</p>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<p>Hello, stranger! <a href="/login/twitter">Log in with Twitter</a></p>
|
||||
<p>Hello, stranger! <a href="/login/twitter">Log in with Twitter</a></p>
|
||||
{% endif %}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<p><a href="{{url_for('index')}}">< 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>
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
<p>Your archive will be processed shortly. <a href="{{url_for('index')}}">Back</a></p>
|
Loading…
Reference in New Issue