2
0
mirror of https://github.com/codl/forget synced 2024-12-27 07:32:34 +01:00

stuff. if you see this then i forgot to squash before publishing

This commit is contained in:
codl 2017-07-25 23:05:46 +02:00
parent c2cbc60b09
commit 912674c3f4
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
6 changed files with 31 additions and 85 deletions

2
app.py
View File

@ -8,6 +8,8 @@ app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///forget'
app.config['SQLALCHEMY_ECHO'] = True
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.secret_key = 'hunter2'
metadata = MetaData(naming_convention = {
"ix": 'ix_%(column_0_label)s',
"uq": "uq_%(table_name)s_%(column_0_name)s",

10
lib.py
View File

@ -1,10 +0,0 @@
from model import User
from flask import request
from functools import update_wrapper
def require_auth(fun):
# TODO actual auth and session checking and such
def newfun(*args, **kwargs):
fun(User.query.get('8080418'), *args, **kwargs)
update_wrapper(newfun, fun)
return newfun

View File

@ -1,55 +0,0 @@
"""init
Revision ID: 8e80a277cdb5
Revises:
Create Date: 2017-07-25 20:02:00.543026
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '8e80a277cdb5'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
op.create_table('users',
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=False),
sa.Column('display_name', sa.String(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('pk_users'))
)
op.create_table('account',
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('remote_id', sa.String(), nullable=False),
sa.Column('service', sa.Enum('twitter', name='enum_services'), nullable=False),
sa.Column('credentials', sa.JSON(), nullable=True),
sa.Column('policy_enabled', sa.Boolean(), nullable=True),
sa.Column('policy_keep_younger', sa.Interval(), nullable=True),
sa.Column('policy_keep_latest', sa.Integer(), nullable=True),
sa.Column('policy_delete_every', sa.Interval(), nullable=True),
sa.Column('policy_ignore_favourites', sa.Boolean(), nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], name=op.f('fk_account_user_id_users')),
sa.PrimaryKeyConstraint('remote_id', 'service', name=op.f('pk_account'))
)
op.create_table('sessions',
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('token', sa.String(), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], name=op.f('fk_sessions_user_id_users')),
sa.PrimaryKeyConstraint('token', name=op.f('pk_sessions'))
)
def downgrade():
op.drop_table('sessions')
op.drop_table('account')
op.drop_table('users')

View File

@ -3,8 +3,8 @@ from datetime import datetime
from app import db
class TimestampMixin(object):
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
created_at = db.Column(db.DateTime, server_default=db.func.now())
updated_at = db.Column(db.DateTime, server_default=db.func.now(), onupdate=db.func.now())
class User(db.Model, TimestampMixin):
__tablename__ = 'users'
@ -15,25 +15,17 @@ class User(db.Model, TimestampMixin):
class Account(db.Model, TimestampMixin):
user = db.relationship(User)
user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
remote_id = db.Column(db.String, primary_key=True)
service = db.Column(
db.Enum("twitter", name="enum_services")
, primary_key=True)
remote_id = db.Column(db.String, primary_key=True)
credentials = db.Column(db.JSON)
policy_enabled = db.Column(db.Boolean, default=False)
policy_enabled = db.Column(db.Boolean, server_default='FALSE', nullable=False)
policy_keep_younger = db.Column(db.Interval)
policy_keep_latest = db.Column(db.Integer)
policy_delete_every = db.Column(db.Interval)
policy_ignore_favourites = db.Column(db.Boolean, default=True)
class Session(db.Model, TimestampMixin):
__tablename__ = 'sessions'
user = db.relationship(User)
user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
token = db.Column(db.String, primary_key=True)
policy_ignore_favourites = db.Column(db.Boolean, server_default='TRUE')

View File

@ -1,9 +1,20 @@
from app import app
from flask import request, Response
from lib import require_auth
from flask import render_template, session, url_for, redirect
from datetime import datetime
@app.route('/')
@require_auth
def index(viewer):
return "Hello, %s (%s)" % (viewer.name, viewer.twitter_id)
def index():
return render_template('index.html')
@app.route('/login/twitter')
def debug_login():
session['display_name'] = 'codl'
session['created_at'] = datetime.now()
return redirect(url_for('index'))
@app.route('/logout')
def logout():
keys = list(session.keys())
for key in keys:
del session[key]
return redirect(url_for('index'))

6
templates/index.html Normal file
View File

@ -0,0 +1,6 @@
{% if session %}
Hello, {{session['display_name']}}! <a href="/logout">Log out</a>
<code>{{session['created_at']}}</code>
{% else %}
Hello, stranger! <a href="/login/twitter">Log in with Twitter</a>
{% endif %}