Esempio n. 1
0
def edit_usr():
    if ('uid' not in session):
        abort(404)
    cred = request.form
    obj = account_api.User()
    for i in cred:
        if (session[i] == cred[i]):
            continue
        res = obj.ChangeAttr(i, cred[i], session['uid'])
        if (res == True):
            session[i] = cred[i]
        elif (res == -2):
            flash(
                f"Could not change your {i} because its been taken by someone else",
                "warning")
    return redirect(url_for("view", func="buying"))
Esempio n. 2
0
def signup():
    if ( request.method == 'POST' ):
        fname = request.form['fname'].lower().capitalize()
        lname = request.form['lname'].lower().capitalize()
        name = f"{fname} {lname}"
        email = request.form['email']
        pwd = request.form['pwd']
        obj = account_api.User()
        res = obj.create( name, email, pwd )
        if (res == -2):
            flash( "Your email is taken", "warning" ) 
            return redirect( url_for( "signup" ) )
        else:
            flash( "Your account has been created successfully.", "success" )
        return redirect( url_for( 'login' ) )
    return render_template( "sign-up.html" )
Esempio n. 3
0
def edit_usr():
    if ( 'uid' not in session ):
        abort(404)
    cred = dict(request.form)
    cred['name'] = f"{cred.pop('fname')} {cred.pop('lname')}"
    obj = account_api.User()
    for i in cred:
        if ( session[i] == cred[i] ):
            continue
        res = obj.ChangeAttr( i, cred[ i ], session['uid'] )
        if ( res == True ):
            session[ i ] = cred[i]
        elif ( res == -2 ):
            flash( f"Could not change your {i} because its been taken by someone else", "warning" )
        else:
            flash( f"Could not change {i} for some reason", "warning" )
    return redirect( url_for( "home" ) )
Esempio n. 4
0
def signup():
    if (request.method == 'POST'):
        dat = request.form
        if (dat['pwd'] != dat['re_pass']):
            flash("Passwords do not match2", "warning")
            return redirect(url_for('signup'))
        res = account_api.User().create(dat['name'], dat['email'], dat['pwd'])
        if (res == True):
            flash(
                "Account created successfully, you can now login with your new user1",
                "success")
            return redirect(url_for("login"))
        elif (res == -2):
            flash("A user with this email already exists2", "warning")
        else:
            flash("Something went wrong please try again later0", "danger")
        return redirect(url_for('signup'))
    return render_template("html/signup.html")
Esempio n. 5
0
def login():
    if (request.method == 'POST'):
        dat = request.form
        obj = account_api.User()
        res = obj.login(**dat)
        if (res != False):
            session['uid'] = res[0]
            session['name'] = res[1]
            session['email'] = res[2]
            session['pwd'] = dat['pwd']
            act = pd.to_datetime(res[4])
            session['activation'] = compute_activated(act)
            return redirect(url_for("view", func="buying"))
        else:
            flash(
                "Oops, Your email or password is incorrect please try again0",
                "danger")
        return redirect(url_for("login"))
    return render_template("html/login.html")
Esempio n. 6
0
def login():
    if ( request.method == "POST" ):
        email = request.form['email']
        pwd = request.form['pwd']
        obj = account_api.User()
        res = obj.login( email, pwd )
        if ( res == False ):
            flash( "Authentication error.", "danger" )
            return redirect( url_for( 'login' ) )
        session['uid'] = res[0]
        session['name'] = res[1]
        session['email'] = res[2]
        session['pwd'] = pwd
        session['bio'] = res[4]
        session['dfe'] = res[5]
        session['settings'] = api.load_settings( res[0] )
        return redirect( url_for( 'home' ) )
        # return redirect( url_for( 'login' ) )
    else:
        if ( 'uid' in session ):
            return redirect( url_for( 'home' ) )
    return render_template( "sign-in.html" )
Esempio n. 7
0
def reset_pwd():
    if ( request.method == 'POST' ):
        email = request.form['email']
        new_pass = api.gen_pass()
        try:
            uid = api.fetch_uid( email )
        except:
            flash( "Email is not a Neighborhood user0", 'danger' )
            return redirect( url_for( "reset_pwd" ) )
        obj = account_api.User()
        if not ( obj.ChangeAttr( "pwd", new_pass, uid ) ):
            flash( "That didnt work. please try again later0", "danger" )
            return redirect( url_for( "reset_pwd" ) )
        else:
            msg = f"Hi your neighborhood password has been successfully changed to {new_pass}"
            # send_simple_message( msg, "CONTRACT password reset", email )
            t = Thread( target = send_simple_message, args = (msg, "Neighborhood password reset", email) )
            t.start()
            # print(f"\n\n\n\n{new_pass}\n\n\n\n")
            flash( "Password has been reset successfully1", "success" )
            flash( "You'll recieve a new password in your mailbox1", "warning" )
        return redirect( url_for('login') )
    return render_template( "html/reset-pwd.html" )
Esempio n. 8
0
def disconnect():
    if 'uid' not in session:
        abort(501)
    obj = account_api.User().ChangeAttr( 'active', 0, session['uid'] )
    emit( "inactive", {'uid': session['uid']}, broadcast = True )