2020-08-10 06:59:45 +00:00
|
|
|
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():
|
2020-08-10 22:11:53 +00:00
|
|
|
un = session["auth"]["preferred_username"]
|
|
|
|
profile_exists = Profile.filter(username=un)
|
2020-08-10 06:59:45 +00:00
|
|
|
if request.method == "POST":
|
|
|
|
address = request.form.get("address")
|
|
|
|
if len(address) in [97, 108]:
|
2020-08-10 22:11:53 +00:00
|
|
|
if profile_exists:
|
|
|
|
profile = Profile.get(username=un)
|
|
|
|
profile.address = address
|
|
|
|
profile.save()
|
|
|
|
else:
|
|
|
|
profile = Profile(
|
|
|
|
username=un,
|
|
|
|
address=address
|
|
|
|
)
|
|
|
|
profile.save()
|
2020-08-10 06:59:45 +00:00
|
|
|
return redirect(request.args.get("redirect", "/"))
|
|
|
|
else:
|
2021-11-08 09:04:58 +00:00
|
|
|
flash("WTF bro, that's not a valid Wownero address", "is-warning")
|
2020-08-10 06:59:45 +00:00
|
|
|
return redirect(request.url)
|
2020-08-10 22:11:53 +00:00
|
|
|
if profile_exists:
|
|
|
|
profile = Profile.get(username=un)
|
|
|
|
else:
|
|
|
|
profile = None
|
|
|
|
return render_template("profile/edit.html", profile=profile)
|