예제 #1
0
def site_admin_view():
    if not current_user.is_admin:
        abort(403)

    registration_enabled = registrations_allowed()

    form = SiteAdminForm(request.form)
    if request.method == 'POST' and form.validate():
        SiteAdmin.user_registration(
            allowed=form.registration_enabled.data,
        )

        if form.registration_enabled.data:
            message = "User registrations allowed!"
        else:
            message = "User registrations prohibited!"

        flash(
            message,
            'success',
        )
        return redirect(url_for('home'))
    else:
        form.registration_enabled.default = registration_enabled
        return render_turkey("site_admin.html", form=form)
예제 #2
0
파일: auth.py 프로젝트: geokala/quizify
def register_view():
    if current_user and not current_user.is_anonymous:
        flash(
            'You already have an account!',
            'warning',
        )
        return redirect(url_for('home'))

    if not registrations_allowed():
        abort(403)

    form = RegisterForm(request.form)
    if request.method == 'POST' and form.validate():
        new_user = User.create(
            name=form.username.data,
            email=form.email.data,
            password=form.password.data,
        )

        if new_user is None:
            # TODO: Put the error on the form validation instead
            # TODO: Make this still give a message afterwards, but link it to
            # the forgotten email password reset thing?
            flash('That username or email is in use.', 'danger')
            return redirect(url_for('register'))
        else:
            login_user(new_user)
            flash('Welcome to the Turkey, %s!' % form.username.data, 'success')
            validation_message = ' '.join([
                'Your email account %s will receive a validation mail.',
                'Please click the link in that mail to validate your mail.',
            ]) % form.email.data
            flash(validation_message, 'info')

            # If this is the first ever user, they're an admin
            all_users = User.query.all()
            if len(all_users) == 1:
                new_user.promote_admin()

            # TODO: Redirect to /me (current user's account page)?
            return redirect(url_for('home'))
    else:
        return render_turkey("register.html", form=form)
예제 #3
0
파일: auth.py 프로젝트: geokala/turkey
def register_view():
    if current_user and not current_user.is_anonymous:
        flash("You already have an account!", "warning")
        return redirect(url_for("home"))

    if not registrations_allowed():
        abort(403)

    form = RegisterForm(request.form)
    if request.method == "POST" and form.validate():
        new_user = User.create(name=form.username.data, email=form.email.data, password=form.password.data)

        if new_user is None:
            # TODO: Put the error on the form validation instead
            # TODO: Make this still give a message afterwards, but link it to
            # the forgotten email password reset thing?
            flash("That username or email is in use.", "danger")
            return redirect(url_for("register"))
        else:
            login_user(new_user)
            flash("Welcome to the Turkey, %s!" % form.username.data, "success")
            validation_message = (
                " ".join(
                    [
                        "Your email account %s will receive a validation mail.",
                        "Please click the link in that mail to validate your mail.",
                    ]
                )
                % form.email.data
            )
            flash(validation_message, "info")

            # If this is the first ever user, they're an admin
            all_users = User.query.all()
            if len(all_users) == 1:
                new_user.promote_admin()

            # TODO: Redirect to /me (current user's account page)?
            return redirect(url_for("home"))
    else:
        return render_turkey("register.html", form=form)