def login(): """Logs the user in.""" if current_user is not None and current_user.is_authenticated: return redirect_or_next(url_for("forum.index")) current_limit = getattr(g, 'view_rate_limit', None) login_recaptcha = False if current_limit is not None: window_stats = limiter.limiter.get_window_stats(*current_limit) stats_diff = flaskbb_config["AUTH_REQUESTS"] - window_stats[1] login_recaptcha = stats_diff >= flaskbb_config["LOGIN_RECAPTCHA"] form = LoginForm() if login_recaptcha and flaskbb_config["RECAPTCHA_ENABLED"]: form = LoginRecaptchaForm() if form.validate_on_submit(): try: user = User.authenticate(form.login.data, form.password.data) if not login_user(user, remember=form.remember_me.data): flash( _("In order to use your account you have to activate it " "through the link we have sent to your email " "address."), "danger") return redirect_or_next(url_for("forum.index")) except AuthenticationError: flash(_("Wrong username or password."), "danger") return render_template("auth/login.html", form=form, login_recaptcha=login_recaptcha)
def form(self): if enforce_recaptcha(limiter): return LoginRecaptchaForm() return LoginForm()