from flask import Flask, request, current_app from app.config import Config from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate from flask_login.login_manager import LoginManager from app.log import logging_module from flask_mail import Mail from flask_bootstrap import Bootstrap from flask_moment import Moment from flask_babel import Babel, lazy_gettext as _l login = LoginManager() login.login_view = 'login' login.login_message = _l('Please log in to access this page.') db = SQLAlchemy() migrate = Migrate() # 邮件 mail = Mail() # css框架Bootstrap bootstrap = Bootstrap() # 日期和时间处理 moment = Moment() # 语言翻译 babel = Babel() def create_app(config_class=Config): app = Flask(__name__) app.config.from_object(Config)
from flask import redirect from flask_login import logout_user from flask import url_for from flask_login import UserMixin from werkzeug.security import check_password_hash from web_content.src.blogYY.blogYY_login_service import search_user_by_username from web_content.src.blogYY.blogYY_login_service import search_user_by_uuid_str # use login manager to manage session # 维护用户的会话,关键就在于这个LoginManager对象 # 必须实现load_user callback函数,用于reload user object # 当密码验证通过后,使用login_user函数来登录用户, # 这时用户在会话中的状态就是登录状态了 login_manager = LoginManager() login_manager.session_protection = 'strong' login_manager.login_view = 'blogYY_page_user_login' login_manager.init_app(app) class User(UserMixin): def __init__(self, uuid_str: str): self.uuid_str = uuid_str self.username = search_user_by_uuid_str(uuid_str)['username'] def get_id(self): return self.uuid_str # 这个callback函数用于reload User object,根据session中存储的user id @login_manager.user_loader def user_loader(user_id):
def init(**kwargs): for k, v in kwargs.items(): setattr(Config, k, v) app = Flask(__name__) db.init_db() sms = AliyunSms(app) Config.sms = sms Config.app = app app.add_template_global(str, 'str') app.secret_key = Config.secret_key app.wsgi_app = ProxyFix(app.wsgi_app) login_manager = LoginManager() login_manager.init_app(app) login_manager.login_view = 'authentication.login' if app.debug: stream_handle = logging.StreamHandler() stream_handle.setFormatter(logging.Formatter(Config.logging_fmt)) stream_handle.setLevel(logging.INFO) app.logger.addHandler(stream_handle) file_handle = logging.FileHandler(Config.logging_path) file_handle.setFormatter(logging.Formatter(Config.logging_fmt)) file_handle.setLevel(logging.WARNING) app.logger.addHandler(file_handle) @login_manager.user_loader def load_user(user_id): return db.User.query.filter_by(id=int(user_id)).first() @app.errorhandler(404) @monitor def not_found(error): Dangerous.add() return render_template("404.html"), 404 @app.errorhandler(400) @monitor def not_found(error): Dangerous.add() return "贪玩", 400 @app.before_request def load_current_user(): g.user = current_user @app.teardown_request def remove_db_session(exception): db.db_session.remove() @app.route('/image/<imagep>') def get_image(imagep): try: path = str(Config.path / "sharh-static" / "static" / "images" / imagep) with open(path, 'rb') as image: return Response(image.read(), content_type="image/{}".format("png" if ".png" in imagep else "jpeg" if ".jpg" in imagep else "gif" if ".gif" in imagep else "")) except Exception as e: logging.log(logging.WARNING, e) return Response(render_template('404.html')) from rx_sharh.service.view import attendance from rx_sharh.service.view import group from rx_sharh.service.view import authentication from rx_sharh.service.view import schedule from rx_sharh.service.view import profile from rx_sharh.service.view import index app.register_blueprint(attendance.mod) app.register_blueprint(group.mod) app.register_blueprint(authentication.mod) app.register_blueprint(schedule.mod) app.register_blueprint(profile.mod)
from flask_migrate import Migrate from flask_login.login_manager import LoginManager import logging from logging.handlers import SMTPHandler, RotatingFileHandler import os from flask_mail import Mail from flask_bootstrap import Bootstrap from flask_moment import Moment from flask_babel import Babel, lazy_gettext as _l microblogapp = Flask(__name__) microblogapp.config.from_object(Config) db = SQLAlchemy(microblogapp) migrate = Migrate(microblogapp, db) login = LoginManager(microblogapp) login.login_view = 'login' #view function that handles login and is redirected to whenever the request is unauthenticated login.login_message = _l('Please login to access this page') mail = Mail(microblogapp) bootstrap = Bootstrap(microblogapp) moment = Moment(microblogapp) babel = Babel(microblogapp) if not microblogapp.debug: #mail configuration if microblogapp.config['MAIL_SERVER']: auth = None if microblogapp.config['MAIL_USERNAME'] or microblogapp.config[ 'MAIL_PASSWORD']: auth = (microblogapp.config['MAIL_USERNAME'], microblogapp.config['MAIL_PASSWORD']) secure = None
from flask_sqlalchemy import SQLAlchemy from flask_bootstrap import Bootstrap from flask_wtf import CSRFProtect from flask_login.login_manager import LoginManager from csdb.modle.ldap_user import LdapUser bootstrap = Bootstrap() db = SQLAlchemy() csrf = CSRFProtect() #login login_manager = LoginManager() login_manager.login_view = 'login.login' login_manager.login_message = '你必须登陆后才能访问该页面' login_manager.login_message_category = "info" @login_manager.user_loader def load_user(userid): return LdapUser.get_user(userid)
from flask import Flask from flask_bcrypt import Bcrypt from flask_login.login_manager import LoginManager from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate # DETACHED EXTENSIONS db = SQLAlchemy() # Authentication manager and System setup login_manager = LoginManager() login_manager.login_view = 'users.login' # password encryption bcrypt = Bcrypt() def create_app(config_file=None): app = Flask(__name__, instance_relative_config=True) app.config.from_pyfile(config_file) initialize_extensions(app) register_blueprints(app) return app def initialize_extensions(app): # bind extensions to the flask app db.init_app(app) Migrate(app, db) login_manager.init_app(app) bcrypt.init_app(app)
from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_bootstrap import Bootstrap from config import config from flask_login.login_manager import LoginManager bootstrap = Bootstrap() db = SQLAlchemy() login_manager = LoginManager() login_manager.session_protection = 'strong' login_manager.login_view = 'page.login' def create_app(config_name): app = Flask(__name__) app.config.from_object(config[config_name]) config[config_name].init_app(app) bootstrap.init_app(app) with app.app_context(): db.init_app(app) from app.main import page as page_blueprint app.register_blueprint(page_blueprint) login_manager.init_app(app) from app.models import User @login_manager.user_loader def load_user(id):
from flask.helpers import url_for, flash, make_response from flask_login.login_manager import LoginManager from flask_login.utils import login_user, current_user, logout_user, login_required from werkzeug.security import check_password_hash from werkzeug.utils import redirect from mylogger import logger from db.user import User from recruit_base import app, try_except, dao auth_api = Blueprint("auth_api", __name__, url_prefix='/api') #Flask-Loing 모듈 login_manager = LoginManager() login_manager.init_app(app) login_manager.login_view = 'auth_view.login_form' login_manager.login_message = "로그인이 필요합니다." @login_manager.user_loader @try_except def load_user(email): logger.info("load_user(%s)" % (email)) cursor = dao.get_conn().cursor() cursor.execute("select * from recruit_user where user_email like '%s'" % (email)) result = cursor.fetchone() if result[1] == email: return User(email, name=result[2], auth=True, no=result[0]) else:
from passlib.apps import custom_app_context as pwd_context from datetime import timedelta from flask_login.utils import login_required from classes import UserList, User from system_requirements_checker import SystemRequirementsChecker app = Flask(__name__) app.register_blueprint(link1) app.register_blueprint(link2) app.register_blueprint(link3) app.register_blueprint(link4) app.register_blueprint(link5) app.secret_key = 'gallifrey' login_manager = LoginManager() login_manager.init_app(app) login_manager.login_view = 'link1.home_page' login_manager.fresh_view = 'link1.home_page' @login_manager.user_loader def load_user(user_id): return User("zzz", "zzz", "zzz").get_user(user_id) @login_manager.unauthorized_handler def unauthorized(): flash("Unauthorized Access. Please Sign In or Sign Up!") return redirect(url_for('link1.home_page')) @app.route('/initdb')
from flask_login.login_manager import LoginManager from flask_principal import Principal, Permission, RoleNeed from flask_restful import Api from itemCatalog.models import User from itemCatalog.rest.api import CategoryAPI, ItemAPI # What does this file do? # - creates and configures the extensions the app uses principals = Principal() admin_permission = Permission(RoleNeed('admin')) default_user_permission = Permission(RoleNeed('user')) login_manager = LoginManager() login_manager.login_view = "login" login_manager.login_message = "Please, login to access this page" login_manager.login_message_category = "info" login_manager.session_protection = "strong" @login_manager.user_loader def load_user(userId): return User.query.get(userId) rest_api = Api() rest_api.add_resource(CategoryAPI, '/api/category/', '/api/category/<int:category_id>/')
# -*- encoding: utf-8 -*- from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_socketio import SocketIO from flask_login.login_manager import LoginManager app = Flask(__name__) app.config.from_object('app.configuration') lm = LoginManager(app) db = SQLAlchemy(app) # flask-sqlalchemy socketio = SocketIO(app, message_queue=app.config['REDIS_URI']) from app import views, models lm.login_view = 'login'
from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_login.login_manager import LoginManager from flask_mail import Mail from config import Config app = Flask(__name__) app.config.from_object(Config) db = SQLAlchemy(app) lm = LoginManager(app) lm.session_protection = 'strong' lm.login_view = '/login' mail = Mail(app) mail.init_app(app) from routes import * if __name__ == '__main__': remove_captcha() app.run(host='0.0.0.0', port=8080)
from flask_sqlalchemy import SQLAlchemy from flask_bcrypt import Bcrypt from flask_moment import Moment from flask_login.login_manager import LoginManager from flask_mail import Mail from app.config import config from flask_wtf.csrf import CSRFProtect import os mail = Mail() database = SQLAlchemy() moment = Moment() bcrypt = Bcrypt() csrf = CSRFProtect() login_manager = LoginManager() login_manager.login_view = "users.login" login_manager.login_message = "You must be signed in to view that page!" login_manager.login_message_category = "danger" login_manager.refresh_view = login_manager.login_view login_manager.needs_refresh_message = "To protect your account, please re-authenticate to access this page!" login_manager.needs_refresh_message_category = "danger" def create_app(): app = Flask(__name__) app.config.from_object(config[os.environ.get("APP_SETTINGS")]) with app.app_context(): database.init_app(app) bcrypt.init_app(app) login_manager.init_app(app)
from flask import Flask, request, current_app from app.config import Config from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate from flask_login.login_manager import LoginManager from app.log import logging_module from flask_mail import Mail from flask_bootstrap import Bootstrap from flask_moment import Moment from flask_babel import Babel, lazy_gettext as _l from elasticsearch import Elasticsearch login = LoginManager() login.login_view = 'auth.login' login.login_message = _l('Please log in to access this page.') db = SQLAlchemy() migrate = Migrate() # 邮件 mail = Mail() # css框架Bootstrap bootstrap = Bootstrap() # 日期和时间处理 moment = Moment() # 语言翻译 babel = Babel() def create_app(config_class=Config): app = Flask(__name__)
from flask import Flask, logging from flask_pymongo import PyMongo from flask_login.login_manager import LoginManager from flask_restful import Api from setting import Config app = Flask(__name__, static_folder='view/static', template_folder='view/templates') app.config.from_object(Config) logger = logging.create_logger(app) mongo = PyMongo(app) login_manager = LoginManager() login_manager.login_view = '/login' login_manager.login_message = '请先登录。' login_manager.session_protection = 'strong' login_manager.init_app(app) api = Api(app)
from server.services import logger from server.constants import * app = Flask(__name__) app.secret_key = SEC_KEY app.SESSION_COOKIE_SECURE = True if IS_DEVELOPMENT: app.config["debug"] = True else: app.config["debug"] = False loginmanager = LoginManager() loginmanager.init_app(app) loginmanager.login_view = "/login" ROOT_PATH = os.path.join(os.path.split(__file__)[0], "..") CSS_PATH = os.path.join(ROOT_PATH, "static", "css") JS_PATH = os.path.join(ROOT_PATH, "static", "js") IMAGES_PATH = os.path.join(ROOT_PATH, "static", "images") FONT_PATH = os.path.join(ROOT_PATH, "static", "font") DOCS_PATH = os.path.join(ROOT_PATH, "templates", "docs") unauthtemplates = ["/login/login.html"] TEMPLATE_PATH = [("/", "/login/login.html"), ("/infolist/login", "/login/login.html"), ("/infolist/index", "/home/index.html"), ("/infolist/mail-conf", "/mail-configuration-client/mail-configuration-client.html"),
from flask_login.login_manager import LoginManager from flask_login import login_user, logout_user, login_required, current_user from flask.blueprints import Blueprint from flask import request, render_template, flash, redirect, url_for from werkzeug.security import generate_password_hash, check_password_hash from .db import User, engine from .form import LoginForm, SignUpForm, ChangePasswordForm login_manager = LoginManager() login_manager.login_view = 'auth.login' bp = Blueprint("auth", __name__, url_prefix="/auth") @login_manager.user_loader def load_user(user_id): return User.query.get(int(user_id)) @bp.route("/login", methods=("GET", "POST")) def login(): login_form = LoginForm() if login_form.validate_on_submit(): email = request.form.get("email") password = request.form.get("password") remember_me = True if request.form.get("remember_me") else False user = User.query.filter_by(email=email).first() if not user: flash("bad login") return render_template("auth/login.html", form=login_form)
from flask_login import logout_user, current_user from flask_login.mixins import UserMixin logging.basicConfig(level=logging.DEBUG) # Create Flask App app = Flask(__name__) app.debug = DEBUG app.secret_key = SECRET_KEY app.config[SQLALCHEMY_DATABASE] = SQLALCHEMY_DATABASE_URI app.config[SQLALCHEMY_DATABASE_NOTIF] = False # Create database to hold user data db = SQLAlchemy(app) lm = LoginManager(app) lm.login_view = 'index' # Call Factory function to create OAuth App. # This can be enhanced to take a custom hostname(github, facebook, etc.) oauthflaskapp = get_oauth_app('github', app.logger) @app.route('/') def index(): """ First page view of web service :return: index html """ return render_template('index.html') @app.route('/login')