Добавил в панель админа возможность бана пользователей

This commit is contained in:
Andrei 2023-03-09 22:05:17 +05:00
parent 7a739abbfd
commit 2c1119a7ae
4 changed files with 19 additions and 7 deletions

View File

@ -26,6 +26,7 @@ class User(SqlAlchemyBase, UserMixin):
activity = sqlalchemy.Column(sqlalchemy.DateTime, nullable=True)
birthday = sqlalchemy.Column(sqlalchemy.Date, nullable=True)
activated = sqlalchemy.Column(sqlalchemy.Boolean, nullable=False, default=False)
banned = sqlalchemy.Column(sqlalchemy.Boolean, nullable=False, default=False)
def check_password(self, password):
return check_password_hash(self.password, password)

19
main.py
View File

@ -74,12 +74,14 @@ def admin():
data_form = list(map(lambda x: (x[0], x[1]), data_form.items()))
list(
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:
if user.id not in list_id:
user.activated = 0
else:
user.activated = 1
user.activated = 0 if user.id not in activ_id else 1
for user in users:
user.banned = 0 if user.id not in banned_id else 1
data_session.commit()
return render_template('admin.html', title='Панель админа', roles=roles, users=users, form=form)
abort(404)
@ -622,10 +624,15 @@ def login():
if not user:
user = data_session.query(User).filter(User.login == form.login.data).first()
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)
logging.info(f'{user.login} logged in')
return redirect('/projects')
elif user.banned:
return render_template('login.html',
message="Ваш аккаунт заблокирован, обратитесь в поддержку: inepted@yandex.ru",
danger=True,
form=form)
else:
return render_template('login.html',
message="Ваша почта не подтверждена",

View File

@ -90,6 +90,6 @@
flex-direction: column;
align-items: center;
}
.user_active {
.user_active, .user_banned {
margin-left: 1vw;
}

View File

@ -23,6 +23,10 @@
<label class="active_label">Активирован</label>
<input class="choose_active" name="active_{{user.id}}" type="checkbox" value="y" {% if user.activated == 1 %}checked="yes"{% endif %}>
</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>
{% endfor %}
</div>