from flask import Flask, render_template, request, session, redirect, url_for, flash import re import flask_login # Фласк логин для сессий import mysql.connector as connector from mysql_db import MySQL # Импортим класс общения с DB from collections import Counter import hashlib app = Flask(__name__) application = app app.config.from_pyfile('config.py') # Берем конфиг для DB из файла mysql = MySQL(app) # Инициализируем объект класса DB import auth # Импорт в модуль авторизации @app.route('/') def hello_world(): cursor = mysql.connection().cursor(named_tuple=True) cursor.execute("Select * From ReE_main") users = cursor.fetchall() cursor.close() return render_template('index.html', users=users) def load_status(): cursor = mysql.connection().cursor(named_tuple=True) cursor.execute("select * from ReE_status;") status = cursor.fetchall() cursor.close() return status
from flask import Flask, render_template, request, url_for, make_response, session, redirect, flash from flask_login import LoginManager, UserMixin, login_user, logout_user, login_required from mysql_db import MySQL import mysql.connector as connector login_manager = LoginManager() app = Flask(__name__) application = app app.config.from_pyfile('config.py') mysql = MySQL(app) login_manager.init_app(app) login_manager.login_view = 'login' login_manager.login_message = 'Для доступа необходимо пройти процедуру аутентификации.' login_manager.login_message_category = 'warning' class User(UserMixin): def __init__(self, user_id, login): super().__init__() self.id = user_id self.login = login @login_manager.user_loader def load_user(user_id): cursor = mysql.connection.cursor(named_tuple=True) cursor.execute('SELECT * FROM users WHERE id = %s;', (user_id,))
import mysql from flask import Flask, render_template, request, abort, redirect, flash, url_for from flask_login import login_required from collections import namedtuple from mysql_db import MySQL import mysql.connector import flask_login import hashlib app = Flask(__name__) app.secret_key = 'asjdfbajSLDFBhjasbfd' app.config.from_pyfile('config.py') db = MySQL(app) login_manager = flask_login.LoginManager() login_manager.init_app(app) class User(flask_login.UserMixin): pass @login_manager.user_loader def user_loader(login): cursor = db.db.cursor(named_tuple=True) cursor.execute('select id, login from users where id = %s', (login,)) user_db = cursor.fetchone() if user_db: user = User() user.id = user_db.id user.login = user_db.login return user