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