User Suspension

New user suspension function
This commit is contained in:
kelepirci 2016-08-24 23:22:04 +03:00
parent 95df3228fc
commit 9f70e2b843
9 changed files with 93 additions and 3 deletions

View File

@ -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)

View File

@ -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))

View File

@ -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()

View File

@ -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):

View File

@ -66,7 +66,7 @@
{% endif %}
</div>
<div class="row">
<div class="col-xs-8 col-xs-offset-0">
<div class="col-xs-4 col-xs-offset-0">
<div class="checkbox">
<label>
<input type="checkbox" name="confirmed" {% if user.confirmed %} checked {% endif %} > Confirmed?
@ -77,6 +77,17 @@
{% endif %}
</div>
</div>
<div class="col-xs-4 col-xs-offset-0">
<div class="checkbox">
<label>
<input type="checkbox" name="suspended" {% if user.suspended %} checked {% endif %} > Suspended?
</label>
{% if form.suspended.errors %}
<br />
<span class="text-red">{% for error in form.suspended.errors %} {{ error }} {% endfor %}</span>
{% endif %}
</div>
</div>
<!-- /.col -->
<div class="col-xs-4">
<button type="submit" name="submit" class="btn btn-primary btn-block btn-flat" value="Update">Update</button>

View File

@ -0,0 +1,30 @@
{% extends "adminlte/base_without_nav.html" %}
{% block title %}Confirm Account{% endblock %}
{% block description %}Your account has been suspended!{% endblock %}
{% block bodytag %}login-page{% endblock %}
{% block body %}
<div class="login-box">
<div class="login-logo">
<strong>-</strong> stack
</div>
<div class="login-box-body">
{# Display errors (if there are any). #}
{% with messages = get_flashed_messages() %}
{% if messages %}
<ul>
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
<h3>Hello {{ current_user.username }}</h3>
<h4>Your account has been suspended!</h4>
<p>Please contact our support department for details.</p>
</div>
</div>
{% endblock %}

View File

@ -28,6 +28,7 @@
{% block content -%}
<h4 class="page-header">
AdminLTE Small Boxes
{{ current_user.suspended }}
<small>Small boxes are used for viewing statistics. To create a small box use the <code>widgets.small_box</code> widget.</small>
</h4>
<!-- Small boxes (Stat box) -->

View File

@ -64,13 +64,21 @@ Reseller
== Support ==
== Admin Area ==
--User Management--
-Create user
-Delete user
-Edit user
-Suspend user
-Unsuspend user
-List User
-Config page
--Provider Management--
-Create provider
-Edit provider
-Delete provider
-Disable provider
-Enable provider
-List providers
== Reseller ==

View File

@ -0,0 +1,26 @@
"""empty message
Revision ID: 5cc72c718d14
Revises: ad5c9cae2c6d
Create Date: 2016-08-24 22:56:39.588007
"""
# revision identifiers, used by Alembic.
revision = '5cc72c718d14'
down_revision = 'ad5c9cae2c6d'
from alembic import op
import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('users', sa.Column('suspended', sa.Boolean(), nullable=True))
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('users', 'suspended')
### end Alembic commands ###