示例#1
0
from werkzeug.security import check_password_hash
from werkzeug.utils import redirect



auth_api = Blueprint("auth_api", __name__, url_prefix='/api')



#Flask-Login 모듈
login_manager = LoginManager()  # 로그인/로그아웃 관련 세션을 관리해주는 flask-login 모듈 객체 생성
login_manager.init_app(app)     # flask객체와 연동

#인증되지 않은 사용자가 @login_required 페이지 접속을 시도할 시 redirect할 페이지 설정
login_manager.login_view = 'auth_view.login'    
login_manager.login_message = "로그인이 필요합니다."

@login_manager.user_loader      # 세션에 저장된 ID에 해당하는 user객체를 반환하는 callback 메소드, 유효하지 않은 ID일 경우 None을 반환한다.
@db_exception
def load_user(id):
        logger.info("load_user(), session:"+str(session))

        cursor = db.get_conn().cursor()
        cursor.callproc('get_user_by_id', (id,))  # argument 1개일 때도 ,하나 붙여줘야 제대로 인식함.
        r = cursor.fetchall()
        cursor.close()

        if r : #id가 존재
            return User(id, name=r[0][2], auth=True)
        else:
            return None
示例#2
0
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)
示例#3
0
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)
示例#4
0
文件: extensions.py 项目: Gourds/csdb
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)
示例#5
0
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>/')

rest_api.add_resource(ItemAPI, '/api/destination/',
示例#6
0
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)
        mail.init_app(app)