Exemplo n.º 1
0
Arquivo: auth.py Projeto: RNR1/GIGS
def register():
    if request.method == "POST":
        
        form = request.form.get
        email = form("email")
        password = form("password")
        confirmation = form("password-confirmation")
   
        if not email:
            return apology("must provide email")
        elif not password:
            return apology("must provide password")
        elif not confirmation or confirmation != password:
            return apology("Password's confirmation does not match")

        hash = generate_password_hash(password)
        user = User(form("email"), form('display-name'), form('first-name'), form('last-name'), form('city'), form('state'), form('country'), form('bio'))

        try:
            db.execute("""INSERT INTO users(email, hash, display, first, last, city, state, country, bio) VALUES ('{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}')"""
            .format(user.email, hash, user.display, user.first, user.last, user.location['city'], user.location['state'], user.location['country'], user.bio))
        except Exception as e:
            print(e) 
            return apology("user already exists")
        finally:
            conn.commit()

        db.execute("SELECT * FROM users WHERE email = '{}'".format(user.email))        
        row = db.fetchone() 

        session["user_id"] = row[0]
        return redirect('/')    

    return render_template('register.html')
Exemplo n.º 2
0
Arquivo: main.py Projeto: RNR1/GIGS
def add():
    if request.method == "POST":
        form = request.form.get

        if not form('date'):
            return apology("must specify date")
        elif not form('venue'):
            return apology("must specify venue name")
        elif not form('city'):
            return apology("must specify city")
        elif not form('country'):
            return apology("must specify country")

        gig = Gig(session["user_id"], form('date'), form('time'),
                  form('venue'), form('event'), form('city'), form('state'),
                  form('country'))

        try:
            db.execute(
                """INSERT INTO gigs(user_id, date, venue, event, city, state, country, time) VALUES ('{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}')"""
                .format(gig.user_id, gig.date, gig.venue, gig.event,
                        gig.location['city'], gig.location['state'],
                        gig.location['country'], gig.time))
        except Exception as error:
            print(error)
            return apology("Invalid request")
        finally:
            conn.commit()

        return redirect(url_for('main.profile'))

    return render_template('add.html',
                           countries=get_countries(),
                           states=get_states())
Exemplo n.º 3
0
Arquivo: main.py Projeto: RNR1/GIGS
def remove(id):
    try:
        db.execute("DELETE FROM gigs WHERE id = '{}'".format(id))
    except:
        return apology("can't delete")
    finally:
        conn.commit()

    return redirect(url_for('main.profile'))
Exemplo n.º 4
0
Arquivo: main.py Projeto: RNR1/GIGS
def delete_account():
    try:
        db.execute("DELETE FROM users WHERE id = '{}'".format(
            session["user_id"]))
    except:
        return apology("can't delete")
    finally:
        conn.commit()

    return redirect(url_for('auth.logout'))
Exemplo n.º 5
0
Arquivo: auth.py Projeto: RNR1/GIGS
def change_login():
    email = request.form.get('email')
    password = request.form.get('password')
    
    if not password and not email:
        return apology("all fields are required", 400)

    if password:
        hash = generate_password_hash(password)
        try:
            db.execute("UPDATE users SET hash = '{}' WHERE id = '{}'".format(hash, session["user_id"]))
        except: 
            return apology("problem updating password")
    if email:
        try:
            db.execute("UPDATE users SET email = '{}' WHERE id = '{}'".format(email, session["user_id"]))
        except: 
            return apology("problem updating email")

    conn.commit()    
    return render_template('account.html', message="Login information updated successfully!")