Example #1
0
def add_user():
    handle = request.form.get('handle')
    password = request.form.get('pass')
    password2 = request.form.get('pass2')
    hand = db_access.get_user_by_handle(handle)
    session['handle'] = handle
    logged = False
    if hand:
        flash('Username already taken!', 'danger')
        return render_template('index.html')

    if len(password) <= 5:
        flash('Password must be 6 characters!', 'danger')
        return render_template('index.html')
    else:
        if password == password2:
            flash('Login successful! Welcome ', 'success')
            db_access.add_user(handle, password)
            logged = True
            session['log'] = logged
            handle = session['handle']
            user = db_access.get_user_by_handle(handle)
            lead_id = user['id']
            follow_id = user['id']
            db_access.follow_user(lead_id, follow_id)
            return redirect(url_for('chirps'))
        elif password != password2:
            flash('Passwords didn\'t match!', 'danger')
            return render_template('index.html')
Example #2
0
def follow_user(user_id):
    handle = session['handle']
    lead_id = user_id
    user = db_access.get_user_by_handle(handle)
    follow_id = user['id']
    following = db_access.get_all_followers(follow_id)
    db_access.follow_user(lead_id, follow_id)
    return redirect(url_for('users'))
Example #3
0
def delete_user(user_id):
    db_access.delete_user(user_id)
    handle = session['handle']
    user = db_access.get_user_by_handle(handle)
    if user:
        return redirect(url_for('users'))
    else:
        return redirect(url_for('sign_out'))
Example #4
0
def chirp():
    handle = session['handle']
    body = request.form.get('cap')
    time = strftime("%Y-%m-%d %H:%M:%S", gmtime())
    user = db_access.get_user_by_handle(handle)
    id = user['id']
    db_access.chirp(body, id, time)
    print('got information')
    return redirect(url_for('chirps'))
Example #5
0
def chirps():
    USERname = session['handle']
    logged = session['log']
    handle = session['handle']
    user = db_access.get_user_by_handle(handle)
    id = user['id']
    chirp_list = db_access.get_all_chirps_by_following(id)
    return render_template('admin/chirps.html',
                           chirps=chirp_list,
                           logged=logged,
                           USERname=USERname)
Example #6
0
def users():
    handle = session['handle']
    user = db_access.get_user_by_handle(handle)
    follow_id = user['id']
    user_list = db_access.get_all_users(follow_id)
    following_list = db_access.get_all_followers(follow_id)
    USERname = session['handle']
    logged = session['log']
    return render_template('admin/users.html',
                           following=following_list,
                           users=user_list,
                           USERname=USERname,
                           logged=logged)
Example #7
0
def sign_in():
    handle = request.form.get('handle2')
    password = request.form.get('pass3')
    user = db_access.get_user_by_handle(handle)
    logged = False
    if user and password == user['password']:
        session['handle'] = handle
        logged = True
        session['log'] = logged
        flash('Login successful! Welcome ', 'success')
        return redirect(url_for('chirps'))
    else:
        flash('Incorrect username or password!', 'danger')
        return render_template('index.html')
Example #8
0
def unfollow_user(user_id):
    db_access.unfollow_user(user_id)
    handle = session['handle']
    user = db_access.get_user_by_handle(handle)
    return redirect(url_for('users'))