Exemple #1
0
def add_bike_profile():
    if request.method == 'GET':
        db = get_db()
        c = db.cursor()
        c.execute('SELECT id, manufacturer' ' FROM bike')
        bikes = c.fetchall()
        #bikes = list(bikes_1)
        return render_template('user_tasks/add_bike_profile.html', bikes=bikes)
    else:
        user_bike = request.form['bikes']
        db = get_db()
        c = db.cursor()
        error = None
        c.execute(
            'SELECT user_id, bike_id FROM user_bike WHERE user_id = %s AND bike_id = %s',
            [g.user[0], user_bike])
        ub = c.fetchone()
#pdb.set_trace()

    if ub is not None:
        error = 'Bike {} is already added.'.format(user_bike)
        flash(error)
    if error is None:
        c.execute('INSERT INTO user_bike (user_id, bike_id) VALUES (%s, %s)',
                  [g.user[0], user_bike])
        db.commit()
        success_message = 'Bike {} added to your profile'.format(user_bike)
        flash(success_message)
#return redirect('user_tasks/add_bike_profile.html')
    c.execute('SELECT id, manufacturer' ' FROM bike')
    bikes = c.fetchall()
    #bikes = list(bikes_1)
    return render_template('user_tasks/add_bike_profile.html', bikes=bikes)
Exemple #2
0
def register():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        db = get_db()
        c = db.cursor()
        error = None

        if not username:
            error = 'Username is required.'
        elif not password:
            error = 'Password is required.'
        c.execute(
            'SELECT id FROM user WHERE username = %s', [username,]
        )
        ur = c.fetchone()
        if ur is not None:
            error = 'User {} is already registered.'.format(username)

        if error is None:
            c.execute(
                'INSERT INTO user (username, password) VALUES (%s, %s)',
                [username, generate_password_hash(password)]
            )
            db.commit()
            return redirect(url_for('auth.login'))

        flash(error)

    return render_template('auth/register.html')
Exemple #3
0
def load_logged_in_user():
    user_id = session.get('user_id')

    if user_id is None:
        g.user = None
    else:
        db = get_db()
        c = db.cursor()
        c.execute(
            'SELECT * FROM user WHERE username = %s', [user_id,]
        )
	#pdb.set_trace()
        g.user = c.fetchone()
Exemple #4
0
def add_bike_db():
    if request.method == 'POST':
        #pdb.set_trace()
        manufacturer = request.form['manufacturer']
        error = None

        if not manufacturer:
            error = 'Manufacturer is required.'

        ##if error is not None:
        ##flash(error)
        else:
            db = get_db()
            c = db.cursor()
            c.execute('INSERT INTO bike (manufacturer)'
                      ' VALUES (%s)', [
                          manufacturer,
                      ])
            db.commit()
            return redirect(url_for('blog.index'))

    return render_template('user_tasks/add_bike_db.html')
Exemple #5
0
def login():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        db = get_db()
        error = None
        c= db.cursor()
        c.execute(
            'SELECT * FROM user WHERE username = %s', [username,]
        )
        user = c.fetchone()
        if user is None:
            error = 'Incorrect username'
        if not check_password_hash(user[2], password):
            error = 'Incorrect password.'

        if error is None:
            session.clear()
            session['user_id'] = user[1]
            return redirect(url_for('index'))

        flash(error)

    return render_template('auth/login_ti.html')