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
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
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
def about(): """About page.""" form = LoginForm(request.form) site_settings = current_app.config['SITE_SETTINGS'] return render_template('public/about.html', site_settings=site_settings, login_form=form)
def render_error(error): """Render error template.""" form = LoginForm(request.form) # If a HTTPException, pull the `code` attribute; default to 500 error_code = getattr(error, 'code', 500) return render_template('{0}.html'.format(error_code), login_form=form), error_code
def dashboard(): """Dashboard.""" 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('dashboard.dashboard')) return redirect(redirect_url) else: flash_errors(form) players = Player.query.all() games = Game.query.all() return render_template('dashboard/dashboard.html', login_form=form, players=players, games=games, episode_stats=Game.episode_stats())
def get_player(player_id): """Get game history and statistics for player.""" 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('public.home') return redirect(redirect_url) else: flash_errors(form) player = Player.get_by_id(player_id) return render_template('dashboard/player.html', player=player, episode_stats=player.episode_stats(), season_stats=player.season_stats(), league_stats=player.league_stats(), login_form=form)
def about(): """About page.""" form = LoginForm(request.form) return render_template('public/about.html', login_form=form)
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