Добавил в панель админа возможность бана пользователей
This commit is contained in:
parent
7a739abbfd
commit
2c1119a7ae
@ -26,6 +26,7 @@ class User(SqlAlchemyBase, UserMixin):
|
|||||||
activity = sqlalchemy.Column(sqlalchemy.DateTime, nullable=True)
|
activity = sqlalchemy.Column(sqlalchemy.DateTime, nullable=True)
|
||||||
birthday = sqlalchemy.Column(sqlalchemy.Date, nullable=True)
|
birthday = sqlalchemy.Column(sqlalchemy.Date, nullable=True)
|
||||||
activated = sqlalchemy.Column(sqlalchemy.Boolean, nullable=False, default=False)
|
activated = sqlalchemy.Column(sqlalchemy.Boolean, nullable=False, default=False)
|
||||||
|
banned = sqlalchemy.Column(sqlalchemy.Boolean, nullable=False, default=False)
|
||||||
|
|
||||||
def check_password(self, password):
|
def check_password(self, password):
|
||||||
return check_password_hash(self.password, password)
|
return check_password_hash(self.password, password)
|
||||||
|
|||||||
19
main.py
19
main.py
@ -74,12 +74,14 @@ def admin():
|
|||||||
data_form = list(map(lambda x: (x[0], x[1]), data_form.items()))
|
data_form = list(map(lambda x: (x[0], x[1]), data_form.items()))
|
||||||
list(
|
list(
|
||||||
map(lambda x: save_admin_data(x, data_session), list(filter(lambda x: 'role_' in x[0], data_form))))
|
map(lambda x: save_admin_data(x, data_session), list(filter(lambda x: 'role_' in x[0], data_form))))
|
||||||
list_id = list(map(lambda user: int(user[0].split('_')[-1]), list(filter(lambda x: 'active_' in x[0], data_form))))
|
activ_id = list(
|
||||||
|
map(lambda user: int(user[0].split('_')[-1]), list(filter(lambda x: 'active_' in x[0], data_form))))
|
||||||
|
banned_id = list(
|
||||||
|
map(lambda user: int(user[0].split('_')[-1]), list(filter(lambda x: 'banned_' in x[0], data_form))))
|
||||||
for user in users:
|
for user in users:
|
||||||
if user.id not in list_id:
|
user.activated = 0 if user.id not in activ_id else 1
|
||||||
user.activated = 0
|
for user in users:
|
||||||
else:
|
user.banned = 0 if user.id not in banned_id else 1
|
||||||
user.activated = 1
|
|
||||||
data_session.commit()
|
data_session.commit()
|
||||||
return render_template('admin.html', title='Панель админа', roles=roles, users=users, form=form)
|
return render_template('admin.html', title='Панель админа', roles=roles, users=users, form=form)
|
||||||
abort(404)
|
abort(404)
|
||||||
@ -622,10 +624,15 @@ def login():
|
|||||||
if not user:
|
if not user:
|
||||||
user = data_session.query(User).filter(User.login == form.login.data).first()
|
user = data_session.query(User).filter(User.login == form.login.data).first()
|
||||||
if user and user.check_password(form.password.data):
|
if user and user.check_password(form.password.data):
|
||||||
if user.activated:
|
if user.activated and not user.banned:
|
||||||
login_user(user, remember=form.remember_me.data)
|
login_user(user, remember=form.remember_me.data)
|
||||||
logging.info(f'{user.login} logged in')
|
logging.info(f'{user.login} logged in')
|
||||||
return redirect('/projects')
|
return redirect('/projects')
|
||||||
|
elif user.banned:
|
||||||
|
return render_template('login.html',
|
||||||
|
message="Ваш аккаунт заблокирован, обратитесь в поддержку: inepted@yandex.ru",
|
||||||
|
danger=True,
|
||||||
|
form=form)
|
||||||
else:
|
else:
|
||||||
return render_template('login.html',
|
return render_template('login.html',
|
||||||
message="Ваша почта не подтверждена",
|
message="Ваша почта не подтверждена",
|
||||||
|
|||||||
@ -90,6 +90,6 @@
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
.user_active {
|
.user_active, .user_banned {
|
||||||
margin-left: 1vw;
|
margin-left: 1vw;
|
||||||
}
|
}
|
||||||
@ -23,6 +23,10 @@
|
|||||||
<label class="active_label">Активирован</label>
|
<label class="active_label">Активирован</label>
|
||||||
<input class="choose_active" name="active_{{user.id}}" type="checkbox" value="y" {% if user.activated == 1 %}checked="yes"{% endif %}>
|
<input class="choose_active" name="active_{{user.id}}" type="checkbox" value="y" {% if user.activated == 1 %}checked="yes"{% endif %}>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="user_banned">
|
||||||
|
<label class="banned_label">Бан</label>
|
||||||
|
<input class="choose_banned" name="banned_{{user.id}}" type="checkbox" value="y" {% if user.banned == 1 %}checked="yes"{% endif %}>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user