после авторизации под правильными или не правильными данными страница просто перезагружается
from sqlite3.dbapi2 import Cursor, SQLITE_SELECT
from flask import Flask, render_template, redirect, request, sessions, url_for, flash
import sqlite3
import os
from flask_login.config import SESSION_KEYS
from flask_login.utils import login_user
import telebot
from UserLogin import UserLogin
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager, login_manager, login_required, current_user
app = Flask(__name__)
app.config.from_object(__name__)
app.config.update(dict(DATABASE=os.path.join(app.root_path,'data.db')))
bot = telebot.TeleBot('1725350616:AAGYRJ2QbqxewDMxnCBSzRw-_8m47YIM-DU')
DATABASE = '/tmp/data.db'
login_manager = LoginManager(app)
login_manager.login_view = 'login'
login_manager.login_message = "Авторизуйтесь для доступа к закрытым страницам"
login_manager.login_message_category = "success"
app.secret_key = 'а'
app.config['SESSION_TYPE'] = 'filesystem'
def getUser(self, login):
try:
self.cursor.execute(f"SELECT * FROM user WHERE login = {login} LIMIT 1")
res = self.cursor.fetchone()
if not res:
print("Пользователь не найден")
return False
return res
except sqlite3.Error as e:
print("Ошибка получения данных из БД "+str(e))
return False
@login_manager.user_loader
def load_user():
print("load_user")
return UserLogin()
@app.route('/login', methods=['POST', 'GET'])
def login():
error=None
if current_user.is_authenticated:
return redirect(url_for('links'))
conn = sqlite3.connect("data.db")
cursor = conn.cursor()
if request == "POST":
user = getUser(request.form['login'])
if user and (user['password'], request.form['password']):
userlogin = UserLogin().create(user)
login_user(userlogin, remember=True)
cursor.close()
return redirect(request.args.get("next") or url_for("admin"))
flash("Неверный логин или пароль", "eror")
return render_template("login.html", error=error)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Авторизация</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous" />
<link rel="stylesheet" href="{{ url_for('static', filename= 'css/auth.css') }}">
</head>
<body style="background-color: #343a40;">
<div class="wrapper">
<div class="form">
<div class="form__body">
<div class="form__header" style="padding-left: 20px;">Авторизация</div>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
<ul class=flashes>
{% for category, message in messages %}
<li class="{{ category }}">{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
<form method="POST" action="">
<div class="form__auth">
<input required type="text" class="form__input" value="{{request.form.username }}" placeholder="Логин" name="login" >
<input required type="password" class="form__input" value="{{request.form.password }}" placeholder="Пароль" name="password">
<input id="submitButton" type="submit" class="form-button btn" value="Войти">
</div>
</form>
</div>
</div>
</div>
</body>