Esempio n. 1
0
def route_list():
    questions = data_manager.get_questions()
    if request.method == 'GET':
        return render_template('list.html', questions=reversed(questions))

    elif request.method == 'POST':
        user_input_username = request.form['user_input_username']
        user_input_password = request.form['user_input_password']
        user_database_password = data_manager.get_password(user_input_username)

        for dict in user_database_password:
            for key, value in dict.items():
                if pwhashing.verify_password(user_input_password, value):

                    session['user_id'] = data_manager.get_user_id_and_name(
                        user_input_username)
                    is_logged_in = "true"
                    message = "Hi " + user_input_username + "!"
                    return render_template('list.html',
                                           questions=reversed(questions),
                                           is_logged_in=is_logged_in,
                                           message=message,
                                           user_id_and_name=session['user_id'])

                else:
                    message = "Invalid username or password!"
                    is_logged_in = "false"
                    return render_template('list.html',
                                           questions=reversed(questions),
                                           is_logged_in=is_logged_in,
                                           message=message)
Esempio n. 2
0
def login():
    if 'id' in session:
        return redirect(url_for('route_main'))
    if request.method == 'POST':
        req = request.form
        try:
            if not util.verify_password(req['password'], data_manager.get_password(req['username'])[0]['password']):
                flash('Incorrect password or username!')
                return redirect(request.url)
            else:
                session['id'] = data_manager.get_user_id(req['username'])[0]['id']
                session['username'] = req['username']
                return redirect(url_for('route_main'))
        except IndexError:
            flash('Incorrect Username!')
            return redirect(request.url)
    return render_template('login.html')
Esempio n. 3
0
def login():
    if request.method == "POST":
        username = request.form["username"]
        password = request.form["password"]
        if data_manager.get_usernames(username) is False:
            reg_password = data_manager.get_password(username)
            is_matching = util.verify_password(password, reg_password)
            if is_matching:
                session['username'] = request.form['username']
                print(session)
                return redirect(url_for('display_list'))
            else:
                message = "Wrong e-mail or password!"
                return render_template('login_fail.html', message=message)
        else:
            message = "Wrong e-mail or password!"
            return render_template('login_fail.html', message=message)
    return render_template('login.html')
Esempio n. 4
0
def login():
    if request.method == "POST":
        email = request.form["email"]
        password = request.form["password"]
        if data_manager.get_usernames(email) is False:
            psw = util.hash_password(password)
            reg_password = data_manager.get_password(email)
            is_matching = util.verify_password(password, reg_password)
            if is_matching:
                session['email'] = request.form['email']
                return redirect(url_for('main_page'))
            else:
                message = "Wrong e-mail or password!"
                return render_template('login_fail.html', message=message)
        else:
            message = "Wrong e-mail or password!"
            return render_template('login_fail.html', message=message)
    return render_template('login.html')
Esempio n. 5
0
def login():
    label_0 = 'Log in'
    error_message = 'Incorrect username or password'
    if request.method == 'GET':
        return render_template('reg_log.html', label_0=label_0)
    input_password = request.form.get('password')
    input_username = request.form.get('username')
    password = data_manager.get_password(input_username)
    try:
        password = password[0].get('password')
    except IndexError:
        return render_template('reg_log.html',
                               error_message=error_message,
                               label_0=label_0)
    verification = pass_hash.verify_password(input_password, password)
    if verification:
        session['username'] = request.form['username']
        session['password'] = request.form['password']
        return redirect(url_for('homepage'))
    else:
        return render_template('reg_log.html',
                               error_message=error_message,
                               label_0=label_0)