예제 #1
0
파일: main.py 프로젝트: RNR1/GIGS
def profile():
    db.execute("SELECT * FROM users WHERE id = '{}'".format(
        session["user_id"]))
    row = db.fetchone()

    db.execute(
        "SELECT *, to_char(time, 'HH24:MI') as time FROM gigs WHERE user_id = '{}' ORDER BY date ASC"
        .format(session["user_id"]))
    gigs = db.fetchall()

    display = row[3]
    name = '{} {}'.format(row[4], row[5])
    state = row[7]
    bio = row[10]
    if len(state) is 0:
        location = '{}, {}'.format(row[6], row[8])
    else:
        location = '{}, {}, {}'.format(row[6], row[7], row[8])

    return render_template('profile.html',
                           display=display,
                           name=name,
                           location=location,
                           gigs=gigs,
                           bio=bio)
예제 #2
0
파일: auth.py 프로젝트: 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')
예제 #3
0
파일: main.py 프로젝트: 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())
예제 #4
0
파일: main.py 프로젝트: 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'))
예제 #5
0
파일: main.py 프로젝트: 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'))
예제 #6
0
파일: main.py 프로젝트: RNR1/GIGS
def bio():
    bio = request.form.get('bio')

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

    return redirect(url_for('main.profile'))
예제 #7
0
파일: auth.py 프로젝트: RNR1/GIGS
def login():
    session.clear()

    if request.method == "POST":

        if not request.form.get("email"):
            return apology("must provide username", 403)

        elif not request.form.get("password"):
            return apology("must provide password", 403)

        db.execute("SELECT * FROM users WHERE email = '{}'".format(request.form.get("email")))
        rows = db.fetchall()
        if len(rows) != 1 or not check_password_hash(rows[0][2], request.form.get("password")):
            return apology("invalid username and/or password", 403)           

        session["user_id"] = rows[0][0]
        return redirect("/profile")

    return render_template('login.html')    
예제 #8
0
파일: auth.py 프로젝트: 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!")
예제 #9
0
파일: main.py 프로젝트: RNR1/GIGS
def account():
    db.execute("SELECT * FROM users WHERE id = '{}'".format(
        session["user_id"]))
    row = db.fetchone()

    return render_template('account.html', message=False, display=row[3])