Skip to content

Instantly share code, notes, and snippets.

@stanruss
Last active July 26, 2025 14:32
Show Gist options
  • Select an option

  • Save stanruss/c4032e72d0638632e2340237a69d92d2 to your computer and use it in GitHub Desktop.

Select an option

Save stanruss/c4032e72d0638632e2340237a69d92d2 to your computer and use it in GitHub Desktop.
flask shell
user = User.query.filter_by(email="[email protected]").first()
user.is_admin = True
user.is_superadmin = True # если хочешь сделать супер-админом
db.session.commit() Мануально добавить роли пользователю
exit()
или
from app.extensions import db
from app.models import User, Role
user = User.query.filter_by(email='[email protected]').first()
role = Role.query.filter_by(name='superadmin').first()
user.roles.append(role)
db.session.commit()
print('Готово!')
---------------------------------------------------------------------------------------------------------------------------
DELETE FROM user;
INSERT INTO user (
id, username, email, password, image_file, confirmed, confirmed_on,
failed_login_attempts, last_failed_login, is_locked, last_login,
use_google_2fa, two_factor_secret, two_factor_enabled,
two_factor_email_enabled, two_factor_email_token, two_factor_email_token_expiry
) VALUES
(
1, 'Deleted User', '[email protected]',
'pbkdf2:sha256:600000$bPjiVbin3Eg9al94$2e8ed2701e4f70524766803577980c1d0c48b67ec43414ef908d56c9e06adff8',
'default.jpg', 0, NULL, 0, NULL, 0, NULL,
0, NULL, 0, 0, NULL, NULL
),
(
2, 'Admin', '[email protected]',
'pbkdf2:sha256:600000$yAuZiyk23G09SN4y$2d0afc3de7ff42bfd68347ade1ea4445ff5648c9c2d3810e3f405e7f037f9e43',
'ad88158ce4ff8895.JPG', 1, '2025-07-26 12:51:12.421788', 0, NULL, 0, '2025-07-26 13:13:29.689924',
0, NULL, 0, 0, NULL, NULL
),
(
3, 'stanruss', '[email protected]',
'pbkdf2:sha256:600000$mfCf3GY2DclKNfJ0$fc0a5a34f7a02fc1d4a45ed9279dc3c8e7772249915aad99670e7aea77b78e4b',
'default.jpg', 1, '2025-07-26 13:12:52.353474', 0, NULL, 0, '2025-07-26 13:13:07.402760',
0, NULL, 0, 0, NULL, NULL
);
---------------------------------------------------------------------------------------------------------------------------
{% extends "base.html" %}
{% endblock %} открыть блок с html
---------------------------------------------------------------------------------------------------------------------------
{% block title %}Личный кабинет{% endblock %} вставить титл в html
---------------------------------------------------------------------------------------------------------------------------
{% if current_user.is_authenticated %}
показать блок если авторизован
{% else %}
показать блок если не авторизован
{% endif %}
---------------------------------------------------------------------------------------------------------------------------
{{ current_user.username }} вывод имени зарегистрированного пользователя
---------------------------------------------------------------------------------------------------------------------------
<a href="{{ url_for('logout') }}">Выйти</a> ссылка для выхода из авторизации
---------------------------------------------------------------------------------------------------------------------------
<a href="{{ url_for('login') }}">войдите</a> ссылка для входа для авторизации
---------------------------------------------------------------------------------------------------------------------------
<a href="{{ url_for('register') }}">Регистрация</a> ссылка для регистрации пользователя
---------------------------------------------------------------------------------------------------------------------------
<a href="{{ url_for('reset_request') }}">Forgot Password?</a> ссылка на забыли пароль
---------------------------------------------------------------------------------------------------------------------------
<a href="{{ url_for('account') }}">Личный кабинет</a> ссылка на личный кабинет (account.html)
---------------------------------------------------------------------------------------------------------------------------
<a class="nav-link" href="{{ url_for('new_post') }}">Добавить запись</a> добавить новый пост
---------------------------------------------------------------------------------------------------------------------------
<!-- Блок для всплывающих сообщений -->
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
{% if category != 'success' %}
<div class="alert alert-{{ category }} alert-dismissible fade show" role="alert">
{{ message }}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Закрыть"></button>
</div>
{% endif %}
{% endfor %}
{% endif %}
{% endwith %} блок всплывающих аллертов без категории success
---------------------------------------------------------------------------------------------------------------------------
<!-- Блок для всплывающих сообщений -->
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="alert alert-{{ category }} alert-dismissible fade show" role="alert">
{{ message }}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Закрыть"></button>
</div>
{% endfor %}
{% endif %}
{% endwith %} блок всплывающих аллертов со всеми категориями аллертов
---------------------------------------------------------------------------------------------------------------------------
<form method="POST">
{{ form.hidden_tag() }}
<div class="mb-3">
{{ form.username.label(class="form-label") }}
{{ form.username(class="form-control") }}
</div>
<div class="mb-3">
{{ form.email.label(class="form-label") }}
{{ form.email(class="form-control") }}
</div>
<div class="mb-3">
{{ form.password.label(class="form-label") }}
{{ form.password(class="form-control") }}
</div>
<div class="mb-3">
{{ form.confirm_password.label(class="form-label") }}
{{ form.confirm_password(class="form-control") }}
</div>
<div class="mb-3">
{{ form.submit(class="btn btn-primary") }}
</div>
</form> форма регистрации пользователя
---------------------------------------------------------------------------------------------------------------------------
<form method="POST">
{{ form.hidden_tag() }}
<div class="mb-3">
{{ form.email.label(class="form-label") }}
{{ form.email(class="form-control") }}
</div>
<div class="mb-3">
{{ form.password.label(class="form-label") }}
{{ form.password(class="form-control") }}
</div>
<button type="submit" class="btn btn-primary">{{ form.submit.label.text }}</button>
</form> форма логина пользователя
---------------------------------------------------------------------------------------------------------------------------
<script>
setTimeout(function() {
const alerts = document.querySelectorAll('.alert');
alerts.forEach(function(alert) {
// Плавное скрытие
alert.classList.remove('show');
alert.classList.add('fade');
setTimeout(() => alert.remove(), 500); // полностью удалить после анимации
});
}, 5000); // 5 секунд
</script> скрипт для скрытия аллеров бутстрап через определенное время (5сек)
---------------------------------------------------------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment