|
|
|
import json
|
|
|
|
from flask import Flask, request, session
|
|
|
|
from flask import render_template, flash
|
|
|
|
from flask import make_response
|
|
|
|
from flask import jsonify
|
|
|
|
from flask_session import Session
|
|
|
|
from suchwow.models import Post, Profile, Comment, Notification, db
|
|
|
|
from suchwow.routes import auth, comment, post, profile
|
|
|
|
from suchwow.utils.decorators import login_required
|
|
|
|
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
app.config.from_envvar("FLASK_SECRETS")
|
|
|
|
app.secret_key = app.config["SECRET_KEY"]
|
|
|
|
Session(app)
|
|
|
|
|
|
|
|
app.register_blueprint(post.bp)
|
|
|
|
app.register_blueprint(auth.bp)
|
|
|
|
|
|
|
|
@app.route("/")
|
|
|
|
def index():
|
|
|
|
page = request.args.get("page", "1")
|
|
|
|
if page.isdigit() is False:
|
|
|
|
flash("Wow, wtf hackerman. Cool it.")
|
|
|
|
page = 1
|
|
|
|
|
|
|
|
posts = Post.select().order_by(Post.timestamp).paginate(int(page), 10)
|
|
|
|
return render_template("index.html", posts=posts, page=page)
|
|
|
|
|
|
|
|
@app.route("/debug")
|
|
|
|
@login_required
|
|
|
|
def debug():
|
|
|
|
return f"""
|
|
|
|
<h3>We are logged in!</h3>
|
|
|
|
<pre>{json.dumps(session["auth"], indent=4, sort_keys=True)}</pre><br>
|
|
|
|
<a href="/logout">Logout</a>
|
|
|
|
"""
|
|
|
|
|
|
|
|
@app.errorhandler(404)
|
|
|
|
def not_found(error):
|
|
|
|
return make_response(jsonify({"error": "Page not found"}), 404)
|
|
|
|
|
|
|
|
@app.cli.command("dbinit")
|
|
|
|
def dbinit():
|
|
|
|
db.create_tables([Post, Profile, Comment, Notification])
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
app.run()
|