diff --git a/dash/admin/forms.py b/dash/admin/forms.py index b525f07..341d478 100644 --- a/dash/admin/forms.py +++ b/dash/admin/forms.py @@ -15,6 +15,7 @@ class EditUserAdminForm(Form): full_name = StringField('Full name', validators=[Required(), Length(1, 255)]) role = SelectField('Role', coerce=int) confirmed = BooleanField('Confirmed') + suspended = BooleanField('Suspended') def __init__(self, user, *args, **kwargs): super(EditUserAdminForm, self).__init__(*args, **kwargs) diff --git a/dash/admin/views.py b/dash/admin/views.py index 896099c..b3c1757 100644 --- a/dash/admin/views.py +++ b/dash/admin/views.py @@ -65,6 +65,7 @@ def edit_user_admin(id): user.full_name = form.full_name.data user.role = Role.query.get(form.role.data) user.confirmed = form.confirmed.data + user.suspended = form.suspended.data db.session.add(user) flash('The profile has been updated.') return redirect(url_for('.edit_user_admin', id=user.id)) diff --git a/dash/auth/views.py b/dash/auth/views.py index a20245a..03e177d 100644 --- a/dash/auth/views.py +++ b/dash/auth/views.py @@ -14,8 +14,13 @@ def before_request(): if current_user.is_authenticated \ and not current_user.confirmed \ and request.endpoint[:5] != 'auth.' \ - and request.endpoint != 'static': + and '/static/' not in request.path: return redirect(url_for('auth.unconfirmed')) + if current_user.is_authenticated \ + and current_user.suspended \ + and request.endpoint[:5] != 'auth.' \ + and '/static/' not in request.path: + return redirect(url_for('auth.suspended')) @auth.route('/unconfirmed') def unconfirmed(): @@ -23,6 +28,12 @@ def unconfirmed(): return redirect(url_for('main.index')) return render_template('auth/unconfirmed.html') +@auth.route('/suspended') +def suspended(): + if current_user.is_anonymous or not current_user.suspended: + return redirect(url_for('main.index')) + return render_template('auth/suspended.html') + @auth.route('/login', methods=['GET', 'POST']) def login(): form = LoginForm() diff --git a/dash/models.py b/dash/models.py index 8f187cb..84df808 100644 --- a/dash/models.py +++ b/dash/models.py @@ -35,6 +35,7 @@ class User(UserMixin, db.Model): created_at = db.Column(db.DateTime) role_id = db.Column(db.Integer, db.ForeignKey('roles.id')) confirmed = db.Column(db.Boolean, default=False) + suspended = db.Column(db.Boolean, default=False) @property def password(self): diff --git a/dash/templates/admin/edit_user.html b/dash/templates/admin/edit_user.html index 74a945d..69c2f3d 100644 --- a/dash/templates/admin/edit_user.html +++ b/dash/templates/admin/edit_user.html @@ -66,7 +66,7 @@ {% endif %}
Please contact our support department for details.
+widgets.small_box
widget.