def activate_account(token=None): """Handles the account activation process.""" if current_user.is_active or not flaskbb_config["ACTIVATE_ACCOUNT"]: flash(_("This account is already activated."), "info") return redirect(url_for('forum.index')) form = None if token is not None: expired, invalid, user = get_token_status(token, "activate_account") else: form = AccountActivationForm() if form.validate_on_submit(): expired, invalid, user = get_token_status(form.token.data, "activate_account") if invalid: flash(_("Your account activation token is invalid."), "danger") return redirect(url_for("auth.request_email_confirmation")) if expired: flash(_("Your account activation token is expired."), "danger") return redirect(url_for("auth.request_activation_token")) if user: user.activated = True user.save() if current_user != user: logout_user() login_user(user) flash(_("Your account has been activated."), "success") return redirect(url_for("forum.index")) return render_template("auth/account_activation.html", form=form)
def post(self, token=None): expired = invalid = user = None form = self.form() if token is not None: expired, invalid, user = get_token_status(token, "activate_account") elif form.validate_on_submit(): expired, invalid, user = get_token_status(form.token.data, "activate_account") if invalid: flash(_("Your account activation token is invalid."), "danger") return redirect(url_for("auth.request_activation_token")) if expired: flash(_("Your account activation token is expired."), "danger") return redirect(url_for("auth.request_activation_token")) if user: user.activated = True user.save() if current_user != user: logout_user() login_user(user) flash(_("Your account has been activated."), "success") return redirect(url_for("forum.index")) return render_template("auth/account_activation.html", form=form)
def activate_account(token=None): """Handles the account activation process.""" if current_user.is_active or not flaskbb_config["ACTIVATE_ACCOUNT"]: flash(_("This account is already activated."), "info") return redirect(url_for('forum.index')) form = None if token is not None: expired, invalid, user = get_token_status(token, "activate_account") else: form = AccountActivationForm() if form.validate_on_submit(): expired, invalid, user = get_token_status(form.token.data, "activate_account") if invalid: flash(_("Your account activation token is invalid."), "danger") return redirect(url_for("auth.request_email_confirmation")) if expired: flash(_("Your account activation token is expired."), "danger") return redirect(url_for("auth.request_activation_token")) if user: user.activated = datetime.utcnow() user.save() if current_user != user: logout_user() login_user(user) flash(_("Your account has been activated.", "success")) return redirect(url_for("forum.index")) return render_template("auth/account_activation.html", form=form)
def reset_password(token): """Handles the reset password process.""" if not current_user.is_anonymous: return redirect(url_for("forum.index")) form = ResetPasswordForm() if form.validate_on_submit(): expired, invalid, user = get_token_status(form.token.data, "reset_password") if invalid: flash(_("Your password token is invalid."), "danger") return redirect(url_for("auth.forgot_password")) if expired: flash(_("Your password token is expired."), "danger") return redirect(url_for("auth.forgot_password")) if user: user.password = form.password.data user.save() flash(_("Your password has been updated."), "success") return redirect(url_for("auth.login")) form.token.data = token return render_template("auth/reset_password.html", form=form)
def test_valid_token_status(user): token = make_token(user, "valid_test") expired, invalid, token_user = get_token_status(token, "valid_test") assert not expired assert not invalid assert token_user == user
def test_invalid_token_status(user): token = "this-is-not-a-token" expired, invalid, token_user, data = \ get_token_status(token, "invalid_test", return_data=True) assert invalid assert not expired assert not token_user assert data is None
def post(self, token): form = self.form() if form.validate_on_submit(): expired, invalid, user = get_token_status(form.token.data, "reset_password") if invalid: flash(_("Your password token is invalid."), "danger") return redirect(url_for("auth.forgot_password")) if expired: flash(_("Your password token is expired."), "danger") return redirect(url_for("auth.forgot_password")) if user: user.password = form.password.data user.save() flash(_("Your password has been updated."), "success") return redirect(url_for("auth.login")) form.token.data = token return render_template("auth/reset_password.html", form=form)
def test_expired_token_status(user): token = make_token(user, "expired_test", -1) expired, invalid, token_user = get_token_status(token, "expired_test") assert expired assert not invalid assert not token_user
def test_token_operation(user): token = make_token(user, "operation_test") expired, invalid, token_user = get_token_status(token, "invalid_op") assert invalid assert not expired assert not token_user
def test_token_status_with_data(user): token = make_token(user, "test_data") expired, invalid, token_user, data = \ get_token_status(token, "test_data", return_data=True) assert user.id == data["id"] assert "test_data" == data["op"]