Example #1
0
def login():
    """Log in to MonkeyBook."""
    form = LoginForm(request.form)

    if request.method == 'POST' and form.validate():
        # Find a monkey with a matching email in the database:
        monkey = dba.get_monkey_by_email(form['email'].data)

        # If such monkey is found, compare the password:
        if monkey is not None and monkey.password == form['password'].data:
            # If matches, log in:
            next = session.get('next')
            session.clear()
            session['id'] = monkey.id
        else:
            # Assuming that we don't want the user to know which part
            # of the input was wrong:
            form.email.errors.append('Invalid e-mail address or password')

    # If logged in, redirect to index, othwerwise show login form:
    if 'id' in session:
        return redirect(next or url_for('index'))
    else:
        return render_template('login.html', form=form)
Example #2
0
def login():
    """Log in to MonkeyBook."""
    form = LoginForm(request.form)

    if request.method == 'POST' and form.validate():
        # Find a monkey with a matching email in the database:
        monkey = dba.get_monkey_by_email(form['email'].data)

        # If such monkey is found, compare the password:
        if monkey is not None and monkey.password == form['password'].data:
            # If matches, log in:
            next = session.get('next')
            session.clear()
            session['id'] = monkey.id
        else:
            # Assuming that we don't want the user to know which part
            # of the input was wrong:
            form.email.errors.append('Invalid e-mail address or password')

    # If logged in, redirect to index, othwerwise show login form:
    if 'id' in session:
        return redirect(next or url_for('index'))
    else:
        return render_template('login.html', form=form)
Example #3
0
 def test_get_monkey_by_email(self, test_monkey):
     """Test get_monkey_by_email()."""
     monkey = test_monkey
     same_monkey = dba.get_monkey_by_email(monkey.email)
     assert isinstance(same_monkey, Monkey)
     assert same_monkey.email == monkey.email