mirror of
https://git.wownero.com/lza_menace/suchwow.git
synced 2024-08-15 01:03:19 +00:00
setup profiles
This commit is contained in:
parent
3d423651c0
commit
4262ec9f04
9 changed files with 81 additions and 15 deletions
|
@ -16,6 +16,7 @@ Session(app)
|
||||||
|
|
||||||
app.register_blueprint(post.bp)
|
app.register_blueprint(post.bp)
|
||||||
app.register_blueprint(auth.bp)
|
app.register_blueprint(auth.bp)
|
||||||
|
app.register_blueprint(profile.bp)
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
|
|
|
@ -3,7 +3,7 @@ from datetime import datetime
|
||||||
from suchwow import config
|
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):
|
class Post(Model):
|
||||||
id = AutoField()
|
id = AutoField()
|
||||||
|
@ -25,7 +25,7 @@ class Profile(Model):
|
||||||
id = AutoField()
|
id = AutoField()
|
||||||
username = CharField()
|
username = CharField()
|
||||||
address = CharField()
|
address = CharField()
|
||||||
notifications = IntegerField()
|
notifications = IntegerField(default=0)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
database = db
|
database = db
|
||||||
|
@ -33,8 +33,8 @@ class Profile(Model):
|
||||||
class Comment(Model):
|
class Comment(Model):
|
||||||
id = AutoField()
|
id = AutoField()
|
||||||
comment = TextField()
|
comment = TextField()
|
||||||
commenter = ForeignKeyField(Profile, field=Profile.username)
|
commenter = ForeignKeyField(Profile)
|
||||||
post = ForeignKeyField(Post, field=id)
|
post = ForeignKeyField(Post)
|
||||||
timestamp = DateTimeField(default=datetime.now)
|
timestamp = DateTimeField(default=datetime.now)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -43,7 +43,7 @@ class Comment(Model):
|
||||||
class Notification(Model):
|
class Notification(Model):
|
||||||
type = CharField()
|
type = CharField()
|
||||||
message = TextField()
|
message = TextField()
|
||||||
username = ForeignKeyField(Profile, field=Profile.username)
|
username = ForeignKeyField(Profile)
|
||||||
timestamp = DateTimeField(default=datetime.now)
|
timestamp = DateTimeField(default=datetime.now)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -4,7 +4,7 @@ from flask import send_from_directory, redirect, url_for, current_app
|
||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
from suchwow import wownero
|
from suchwow import wownero
|
||||||
from suchwow.models import Post
|
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
|
from suchwow.utils.helpers import allowed_file
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ def read(id):
|
||||||
|
|
||||||
@bp.route("/post/create", methods=["GET", "POST"])
|
@bp.route("/post/create", methods=["GET", "POST"])
|
||||||
@login_required
|
@login_required
|
||||||
|
@profile_required
|
||||||
def create():
|
def create():
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
post_title = request.form.get("title")
|
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_base = path.join(current_app.config["DATA_FOLDER"], "uploads")
|
||||||
save_path = path.join(save_path_base, filename)
|
save_path = path.join(save_path_base, filename)
|
||||||
file.save(save_path)
|
file.save(save_path)
|
||||||
# gen wallet
|
|
||||||
try:
|
try:
|
||||||
wallet = wownero.Wallet()
|
wallet = wownero.Wallet()
|
||||||
account_index = wallet.new_account()
|
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>
|
<h3>{% block title %}Latest Submissions{% endblock %}</h3>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul>
|
{% if posts %}
|
||||||
{% for post in posts %}
|
<ul>
|
||||||
<li>#{{ post.id }} - <a href="{{ url_for('post.read', id=post.id) }}">{{ post.title }}</a> - {{ post.submitter }}</li>
|
{% for post in posts %}
|
||||||
{% endfor %}
|
<li>#{{ post.id }} - <a href="{{ url_for('post.read', id=post.id) }}">{{ post.title }}</a> - {{ post.submitter }}</li>
|
||||||
</ul>
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% else %}
|
||||||
|
<p>No posts yet!</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,7 +24,7 @@
|
||||||
<a href="/?page={{ page - 1 }}" style="padding:1em;">Back</a>
|
<a href="/?page={{ page - 1 }}" style="padding:1em;">Back</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if not page == total_pages %}
|
{% if page <= total_pages and total_pages > 0 %}
|
||||||
<a href="/?page={{ page + 1 }}" style="padding:1em;">Next</a>
|
<a href="/?page={{ page + 1 }}" style="padding:1em;">Next</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,9 @@
|
||||||
<a class="nav-link" href="{{ url_for('auth.login') }}">Login</a>
|
<a class="nav-link" href="{{ url_for('auth.login') }}">Login</a>
|
||||||
</li>
|
</li>
|
||||||
{% else %}
|
{% 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">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="{{ url_for('auth.logout') }}">Logout</a>
|
<a class="nav-link" href="{{ url_for('auth.logout') }}">Logout</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
<br>
|
<br>
|
||||||
<img src="{{ url_for('post.uploaded_file', filename=post.image_name) }}" width=500/ style="margin-bottom:1em;border-radius:4px;">
|
<img src="{{ url_for('post.uploaded_file', filename=post.image_name) }}" width=500/ style="margin-bottom:1em;border-radius:4px;">
|
||||||
<hr>
|
<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>
|
<hr>
|
||||||
<h3>Comments</h3>
|
<h3>Comments</h3>
|
||||||
{% if comments %}
|
{% if comments %}
|
||||||
|
|
20
suchwow/templates/profile/edit.html
Normal file
20
suchwow/templates/profile/edit.html
Normal file
|
@ -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 flask import session, redirect, url_for
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
from suchwow.models import Profile
|
||||||
|
|
||||||
|
|
||||||
def login_required(f):
|
def login_required(f):
|
||||||
|
@ -9,3 +10,16 @@ def login_required(f):
|
||||||
return redirect(url_for("auth.login"))
|
return redirect(url_for("auth.login"))
|
||||||
return f(*args, **kwargs)
|
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…
Add table
Add a link
Reference in a new issue