Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, render_template, redirect, url_for
- from flask_sqlalchemy import SQLAlchemy
- from flask_login import LoginManager
- app = Flask(__name__)
- db = SQLAlchemy(app)
- db.init_app(app)
- login_manager = LoginManager()
- login_manager.session_protection = 'strong'
- login_manager.login_view = 'auth.singin'
- login_manager.init_app(app)
- # Добавления файла конфигурации
- app.config.from_object('config')
- @app.errorhandler(404)
- def not_found(error):
- return render_template('404.html'), 404
- from app.home.controllers import home as home_module
- from app.auth.controllers import auth as auth_module
- app.register_blueprint(home_module)
- app.register_blueprint(auth_module)
- # Импорт моделей
- from app.models import user
- auth = Blueprint('auth', __name__, url_prefix='/auth')
- @auth.route('/signin/',methods=['GET','POST'])
- def signin():
- form = LoginForm()
- if form.validate_on_submit():
- user = User.query.filter_by(email=form.email.data).first()
- if user is not None and user.password == form.password.data:
- print(user.password)
- login_user(user, form.remember_me.data)
- return redirect(request.args.get('next') or url_for('home.index'))
- flash('Invalid username or password.')
- return render_template('auth/signin.html', form=form)
- home = Blueprint('home', __name__,)
- @home.route('/')
- @home.route('/home')
- @home.route('/index.html')
- @decorators.login_required
- def index():
- return render_template('home/index.html')
- def login_required(f):
- @wraps(f)
- def decorated_function(*args, **kwargs):
- if 'username' not in session:
- return redirect(url_for('auth.signin'))
- return f(*args, **kwargs)
- return decorated_function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement