예제 #1
0
파일: views.py 프로젝트: overad/flaskbb
    def post(self):
        form = self.form()
        if form.validate_on_submit():
            user = form.save()

            if flaskbb_config["ACTIVATE_ACCOUNT"]:
                # Any call to an expired model requires a database hit, so
                # accessing user.id would cause an DetachedInstanceError.
                # This happens because the `user`'s session does no longer exist.
                # So we just fire up another query to make sure that the session
                # for the newly created user is fresh.
                # PS: `db.session.merge(user)` did not work for me.
                user = User.query.filter_by(email=user.email).first()
                send_activation_token.delay(user)
                flash(
                    _("An account activation email has been sent to %(email)s", email=user.email),
                    "success"
                )
            else:
                login_user(user)
                flash(_("Thanks for registering."), "success")

            return redirect_or_next(url_for('forum.index'))

        return render_template("auth/register.html", form=form)
예제 #2
0
def register():
    """Register a new user."""
    if current_user is not None and current_user.is_authenticated:
        return redirect_or_next(url_for("forum.index"))

    if not flaskbb_config["REGISTRATION_ENABLED"]:
        flash(_("The registration has been disabled."), "info")
        return redirect_or_next(url_for("forum.index"))

    form = RegisterForm(request.form)

    form.language.choices = available_languages()
    form.language.default = flaskbb_config['DEFAULT_LANGUAGE']
    form.process(request.form)  # needed because a default is overriden

    if form.validate_on_submit():
        user = form.save()

        if flaskbb_config["ACTIVATE_ACCOUNT"]:
            send_activation_token.delay(user)
            flash(
                _("An account activation email has been sent to %(email)s",
                  email=user.email), "success")
        else:
            login_user(user)
            flash(_("Thanks for registering."), "success")

        return redirect_or_next(url_for('forum.index'))

    return render_template("auth/register.html", form=form)
예제 #3
0
파일: views.py 프로젝트: overad/flaskbb
    def post(self):
        form = self.form()
        if form.validate_on_submit():
            user = User.query.filter_by(email=form.email.data).first()
            send_activation_token.delay(user)
            flash(
                _("A new account activation token has been sent to "
                  "your email address."), "success"
            )
            return redirect(url_for("auth.activate_account"))

        return render_template("auth/request_account_activation.html", form=form)
예제 #4
0
파일: views.py 프로젝트: djsilcock/flaskbb
def request_activation_token(token=None):
    """Requests a new account activation token."""
    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 = RequestActivationForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        send_activation_token.delay(user)
        flash(_("A new account activation token has been sent to "
                "your email address."), "success")
        return redirect(url_for("auth.activate_account"))

    return render_template("auth/request_account_activation.html", form=form)
예제 #5
0
파일: views.py 프로젝트: JackieyQi/flaskbb
def request_activation_token(token=None):
    """Requests a new account activation token."""
    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 = RequestActivationForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        send_activation_token.delay(user)
        flash(_("A new account activation token has been sent to "
                "your email address."), "success")
        return redirect(url_for("auth.activate_account"))

    return render_template("auth/request_account_activation.html", form=form)
예제 #6
0
def register():
    """Register a new user."""
    if current_user is not None and current_user.is_authenticated:
        return redirect_or_next(url_for("forum.index"))

    if not flaskbb_config["REGISTRATION_ENABLED"]:
        flash(_("The registration has been disabled."), "info")
        return redirect_or_next(url_for("forum.index"))

    form = RegisterForm(request.form)

    form.language.choices = get_available_languages()
    form.language.default = flaskbb_config['DEFAULT_LANGUAGE']
    form.process(request.form)  # needed because a default is overriden

    if form.validate_on_submit():
        user = form.save()

        if flaskbb_config["ACTIVATE_ACCOUNT"]:
            # Any call to an expired model requires a database hit, so
            # accessing user.id would cause an DetachedInstanceError.
            # This happens because the `user`'s session does no longer exist.
            # So we just fire up another query to make sure that the session
            # for the newly created user is fresh.
            # PS: `db.session.merge(user)` did not work for me.
            user = User.query.filter_by(email=user.email).first()
            send_activation_token.delay(user)
            flash(
                _("An account activation email has been sent to %(email)s",
                  email=user.email), "success")
        else:
            login_user(user)
            flash(_("Thanks for registering."), "success")

        return redirect_or_next(url_for('forum.index'))

    return render_template("auth/register.html", form=form)
예제 #7
0
파일: views.py 프로젝트: djsilcock/flaskbb
def register():
    """Register a new user."""
    if current_user is not None and current_user.is_authenticated:
        return redirect_or_next(url_for("forum.index"))

    if not flaskbb_config["REGISTRATION_ENABLED"]:
        flash(_("The registration has been disabled."), "info")
        return redirect_or_next(url_for("forum.index"))

    form = RegisterForm(request.form)

    form.language.choices = available_languages()
    form.language.default = flaskbb_config['DEFAULT_LANGUAGE']
    form.process(request.form)  # needed because a default is overriden

    if form.validate_on_submit():
        user = form.save()

        if flaskbb_config["ACTIVATE_ACCOUNT"]:
            # Any call to an expired model requires a database hit, so
            # accessing user.id would cause an DetachedInstanceError.
            # This happens because the `user`'s session does no longer exist.
            # So we just fire up another query to make sure that the session
            # for the newly created user is fresh.
            # PS: `db.session.merge(user)` did not work for me.
            user = User.query.filter_by(email=user.email).first()
            send_activation_token.delay(user)
            flash(_("An account activation email has been sent to %(email)s",
                    email=user.email), "success")
        else:
            login_user(user)
            flash(_("Thanks for registering."), "success")

        return redirect_or_next(url_for('forum.index'))

    return render_template("auth/register.html", form=form)