Gate registration behind the site setting; land on dashboard after login
This commit is contained in:
1 parent
aafdaa5045
commit
23d6a45584
1 file changed
+10
-1
+10
-1
@@ -2,6 +2,7 @@ from flask import Blueprint, render_template, redirect, url_for, flash, request
|
|||||||
from flask_login import login_user, logout_user, login_required, current_user
|
from flask_login import login_user, logout_user, login_required, current_user
|
||||||
from app import db
|
from app import db
|
||||||
from app.models.user import User
|
from app.models.user import User
|
||||||
|
from app.models.site_setting import SiteSetting
|
||||||
|
|
||||||
auth_bp = Blueprint('auth', __name__, url_prefix='/auth')
|
auth_bp = Blueprint('auth', __name__, url_prefix='/auth')
|
||||||
|
|
||||||
@@ -12,6 +13,14 @@ def register():
|
|||||||
if current_user.is_authenticated:
|
if current_user.is_authenticated:
|
||||||
return redirect(url_for('main.index'))
|
return redirect(url_for('main.index'))
|
||||||
|
|
||||||
|
# Admins can close signups from Site Settings. The very first account is
|
||||||
|
# always allowed through, otherwise a fresh install locks itself out.
|
||||||
|
if not SiteSetting.get_bool('allow_registration', True) and \
|
||||||
|
User.query.first() is not None:
|
||||||
|
flash('Registration is currently closed. Ask an administrator for an account.',
|
||||||
|
'warning')
|
||||||
|
return redirect(url_for('auth.login'))
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
username = request.form.get('username')
|
username = request.form.get('username')
|
||||||
email = request.form.get('email')
|
email = request.form.get('email')
|
||||||
@@ -74,7 +83,7 @@ def login():
|
|||||||
login_user(user, remember=bool(remember))
|
login_user(user, remember=bool(remember))
|
||||||
next_page = request.args.get('next')
|
next_page = request.args.get('next')
|
||||||
flash(f'Welcome back, {user.username}!', 'success')
|
flash(f'Welcome back, {user.username}!', 'success')
|
||||||
return redirect(next_page) if next_page else redirect(url_for('main.index'))
|
return redirect(next_page) if next_page else redirect(url_for('main.dashboard'))
|
||||||
else:
|
else:
|
||||||
flash('Invalid username or password.', 'danger')
|
flash('Invalid username or password.', 'danger')
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user