diff --git a/suchwow/routes/profile.py b/suchwow/routes/profile.py index 4081bc0..4daffc9 100644 --- a/suchwow/routes/profile.py +++ b/suchwow/routes/profile.py @@ -1,7 +1,8 @@ -from flask import render_template, Blueprint, flash -from flask import request, redirect, url_for, session -from suchwow.models import Profile +from flask import render_template, Blueprint, flash, request, redirect, flash + +from suchwow._models import User from suchwow.utils.decorators import login_required +from suchwow.utils.helpers import get_session_user bp = Blueprint("profile", "profile") @@ -9,27 +10,18 @@ bp = Blueprint("profile", "profile") @bp.route("/profile/edit", methods=["GET", "POST"]) @login_required def edit(): - un = session["auth"]["preferred_username"] - profile_exists = Profile.filter(username=un) + user = User.select().where(User.username == get_session_user()).first() if request.method == "POST": address = request.form.get("address") if len(address) in [97, 108]: - if profile_exists: - profile = Profile.get(username=un) - profile.address = address - profile.save() + if user: + user.address = address + user.save() else: - profile = Profile( - username=un, - address=address - ) - profile.save() + User.create(username=get_session_user()) + flash('Wallet address saved!', 'is-success') return redirect(request.args.get("redirect", "/")) else: flash("WTF bro, that's not a valid Wownero address", "is-warning") return redirect(request.url) - if profile_exists: - profile = Profile.get(username=un) - else: - profile = None - return render_template("profile/edit.html", profile=profile) + return render_template("profile/edit.html", profile=user) diff --git a/suchwow/templates/profile/edit.html b/suchwow/templates/profile/edit.html index 42af6a1..52f5500 100644 --- a/suchwow/templates/profile/edit.html +++ b/suchwow/templates/profile/edit.html @@ -6,17 +6,21 @@
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.
-