setup profiles

graphs-n-shit
lza_menace 4 years ago
parent 3d423651c0
commit 4262ec9f04

@ -16,6 +16,7 @@ Session(app)
app.register_blueprint(post.bp)
app.register_blueprint(auth.bp)
app.register_blueprint(profile.bp)
@app.route("/")
def index():

@ -3,7 +3,7 @@ from datetime import datetime
from suchwow import config
db = SqliteDatabase(f'{config.DATA_FOLDER}/db/sqlite.db')
db = SqliteDatabase(f"{config.DATA_FOLDER}/db/sqlite.db")
class Post(Model):
id = AutoField()
@ -25,7 +25,7 @@ class Profile(Model):
id = AutoField()
username = CharField()
address = CharField()
notifications = IntegerField()
notifications = IntegerField(default=0)
class Meta:
database = db
@ -33,8 +33,8 @@ class Profile(Model):
class Comment(Model):
id = AutoField()
comment = TextField()
commenter = ForeignKeyField(Profile, field=Profile.username)
post = ForeignKeyField(Post, field=id)
commenter = ForeignKeyField(Profile)
post = ForeignKeyField(Post)
timestamp = DateTimeField(default=datetime.now)
class Meta:
@ -43,7 +43,7 @@ class Comment(Model):
class Notification(Model):
type = CharField()
message = TextField()
username = ForeignKeyField(Profile, field=Profile.username)
username = ForeignKeyField(Profile)
timestamp = DateTimeField(default=datetime.now)
class Meta:

@ -4,7 +4,7 @@ from flask import send_from_directory, redirect, url_for, current_app
from werkzeug.utils import secure_filename
from suchwow import wownero
from suchwow.models import Post
from suchwow.utils.decorators import login_required
from suchwow.utils.decorators import login_required, profile_required
from suchwow.utils.helpers import allowed_file
@ -25,6 +25,7 @@ def read(id):
@bp.route("/post/create", methods=["GET", "POST"])
@login_required
@profile_required
def create():
if request.method == "POST":
post_title = request.form.get("title")
@ -46,7 +47,6 @@ def create():
save_path_base = path.join(current_app.config["DATA_FOLDER"], "uploads")
save_path = path.join(save_path_base, filename)
file.save(save_path)
# gen wallet
try:
wallet = wownero.Wallet()
account_index = wallet.new_account()

@ -0,0 +1,24 @@
from flask import render_template, Blueprint, flash
from flask import request, redirect, url_for, session
from suchwow.models import Profile
from suchwow.utils.decorators import login_required
bp = Blueprint("profile", "profile")
@bp.route("/profile/edit", methods=["GET", "POST"])
@login_required
def edit():
if request.method == "POST":
address = request.form.get("address")
if len(address) in [97, 108]:
profile = Profile(
username=session["auth"]["preferred_username"],
address=address
)
profile.save()
return redirect(request.args.get("redirect", "/"))
else:
flash("WTF bro, that's not a valid Wownero address")
return redirect(request.url)
return render_template("profile/edit.html")

@ -8,11 +8,15 @@
<h3>{% block title %}Latest Submissions{% endblock %}</h3>
</div>
<ul>
{% for post in posts %}
<li>#{{ post.id }} - <a href="{{ url_for('post.read', id=post.id) }}">{{ post.title }}</a> - {{ post.submitter }}</li>
{% endfor %}
</ul>
{% if posts %}
<ul>
{% for post in posts %}
<li>#{{ post.id }} - <a href="{{ url_for('post.read', id=post.id) }}">{{ post.title }}</a> - {{ post.submitter }}</li>
{% endfor %}
</ul>
{% else %}
<p>No posts yet!</p>
{% endif %}
@ -20,7 +24,7 @@
<a href="/?page={{ page - 1 }}" style="padding:1em;">Back</a>
{% endif %}
{% if not page == total_pages %}
{% if page <= total_pages and total_pages > 0 %}
<a href="/?page={{ page + 1 }}" style="padding:1em;">Next</a>
{% endif %}

@ -18,6 +18,9 @@
<a class="nav-link" href="{{ url_for('auth.login') }}">Login</a>
</li>
{% else %}
<li class="nav-item">
<a class="nav-link" href="{{ url_for('profile.edit') }}">Profile ({{session.auth.preferred_username}})</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ url_for('auth.logout') }}">Logout</a>
</li>

@ -14,7 +14,7 @@
<br>
<img src="{{ url_for('post.uploaded_file', filename=post.image_name) }}" width=500/ style="margin-bottom:1em;border-radius:4px;">
<hr>
<p style="word-break:break-all;">Vote for this post by sending WOW to the following address:<br><b><i>{{ address }}</i></b></p>
<p style="word-break:break-all;">Vote for this post by sending WOW to the following address:<br><i>{{ address }}</i></p>
<hr>
<h3>Comments</h3>
{% if comments %}

@ -0,0 +1,20 @@
{% extends 'base.html' %}
{% block content %}
<div class="container" style="width:40%;">
<div class="edit">
<h1>Edit Profile</h1>
<p>You need to setup your profile before you can submit memes. As of now this only consists of a payout address so we know where to send Wownero if someone sends funds for your post.</p>
<form method=post enctype=multipart/form-data class="form-horizontal">
<div class="form-group">
<label class="sr-only" for="address">Payout Address</label>
<input type="text" class="form-control mb-2 mr-sm-2 mb-sm-0" id="address" placeholder="Wownero address for payouts" name="address">
</div>
<div class="form-group">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</form>
</div>
</div>
{% endblock %}

@ -1,5 +1,6 @@
from flask import session, redirect, url_for
from functools import wraps
from suchwow.models import Profile
def login_required(f):
@ -8,4 +9,17 @@ def login_required(f):
if "auth" not in session or not session["auth"]:
return redirect(url_for("auth.login"))
return f(*args, **kwargs)
return decorated_function
return decorated_function
def profile_required(f):
@wraps(f)
def decorated_function(*args, **kwargs):
un = session["auth"]["preferred_username"]
if not Profile.filter(username=un):
url = "{}?redirect={}".format(
url_for("profile.edit"),
url_for("post.create")
)
return redirect(url)
return f(*args, **kwargs)
return decorated_function

Loading…
Cancel
Save