예제 #1
0
 def test_validate_invalid_password(self, user):
     """Invalid password."""
     user.set_password('example')
     user.save()
     form = LoginForm(username=user.username, password='******')
     assert form.validate() is False
     assert 'Invalid password' in form.password.errors
예제 #2
0
 def test_validate_success(self, user):
     """Login successful."""
     user.set_password('example')
     user.save()
     form = LoginForm(username=user.username, password='******')
     assert form.validate() is True
     assert form.user == user
예제 #3
0
 def test_validate_inactive_user(self, user):
     """Inactive user."""
     user.active = False
     user.set_password('example')
     user.save()
     # Correct username and password, but user is not activated
     form = LoginForm(username=user.username, password='******')
     assert form.validate() is False
     assert 'User not activated' in form.username.errors
예제 #4
0
def home():
    """Home page."""
    form = LoginForm(request.form)
    # Handle logging in
    if request.method == 'POST':
        if form.validate_on_submit():
            login_user(form.user)
            flash('You are logged in.', 'success')
            redirect_url = request.args.get('next') or url_for('user.members')
            return redirect(redirect_url)
        else:
            flash_errors(form)
    return render_template('public/home.html', form=form)
예제 #5
0
def login():
    """login."""
    form = LoginForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            login_user(form.user)
            flash('You are logged in.', 'success')
            redirect_url = request.args.get('next') or url_for('user.members')
            return redirect(redirect_url)
        else:
            flash_errors(form)

    return dict(form=form)
예제 #6
0
 def test_validate_unknown_username(self, db):
     """Unknown username."""
     form = LoginForm(username='******', password='******')
     assert form.validate() is False
     assert 'Unknown username' in form.username.errors
     assert form.user is None
예제 #7
0
def about():
    """About page."""
    form = LoginForm(request.form)
    return render_template('public/about.html', form=form)
예제 #8
0
def about():
    """About page."""
    form = LoginForm(request.form)
    return dict(form=form)
예제 #9
0
 def test_validate_unknown_username(self, db):
     """Unknown username."""
     form = LoginForm(username="******", password="******")
     assert form.validate() is False
     assert "Unknown username" in form.username.errors
     assert form.user is None