update profile routes for new models

migrate-new-models
lza_menace 2 years ago
parent da874c3994
commit ccb48a16c2

@ -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)

@ -6,17 +6,21 @@
<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">
<form method=post enctype=multipart/form-data class="mt-4">
<div class="field">
<label class="label">Payout Address</label>
<div class="control">
<input class="input" type="text" placeholder="Wownero address for payouts" name="address">
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-success">Submit</button>
<div class="field is-grouped">
<div class="control">
<button class="button is-link">Submit</button>
</div>
</div>
</form>
{% if profile %}
<p style="word-break:break-all;">Existing Address:<br>{{ profile.address }}</p>
<p style="word-break:break-all;" class="mt-4">Existing Address:<br>{{ profile.address }}</p>
{% endif %}
</div>
</div>

Loading…
Cancel
Save