当前位置: 首页>>代码示例>>Python>>正文


Python LoginManager.anonymous_user方法代码示例

本文整理汇总了Python中flaskext.login.LoginManager.anonymous_user方法的典型用法代码示例。如果您正苦于以下问题:Python LoginManager.anonymous_user方法的具体用法?Python LoginManager.anonymous_user怎么用?Python LoginManager.anonymous_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flaskext.login.LoginManager的用法示例。


在下文中一共展示了LoginManager.anonymous_user方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: init_app

# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import anonymous_user [as 别名]
    def init_app(self, app):
        if app is None:
            return

        blueprint = Blueprint(AUTH_CONFIG_KEY.lower(), __name__)

        config = default_config.copy()
        try:
            config.update(app.config.get(AUTH_CONFIG_KEY, {}))
        except:
            pass
        app.config[AUTH_CONFIG_KEY] = config

        app.logger.debug("Auth Configuration: %s" % config)

        # setup the login manager extension
        login_manager = LoginManager()
        login_manager.anonymous_user = Anonymous
        login_manager.login_view = config[LOGIN_VIEW_KEY]
        login_manager.setup_app(app)

        # get some things form the config
        Provider = get_class_from_config(AUTH_PROVIDER_KEY, config)
        Encryptor = get_class_from_config(PASSWORD_ENCRYPTOR_KEY, config)
        Form = get_class_from_config(LOGIN_FORM_CLASS_KEY, config)

        # create the service and auth provider and add it to the app
        # so it can be referenced elsewhere
        app.login_manager = login_manager
        app.password_encryptor = Encryptor(config[SALT_KEY])
        app.auth_provider = Provider(Form)

        DEBUG_LOGIN = "User %s logged in. Redirecting to: %s"
        ERROR_LOGIN = "Unsuccessful auth attempt: %s. Redirecting to: %s"
        DEBUG_LOGOUT = "User logged out, redirecting to: %s"
        FLASH_INACTIVE = "Inactive user"

        @login_manager.user_loader
        def load_user(id):
            try:
                return user_service.get_user_with_id(id)
            except Exception, e:
                current_app.logger.error("Error getting user: %s" % e)
                return None
开发者ID:AltisCorp,项目名称:Civil-Debate-Wall,代码行数:46,代码来源:__init__.py

示例2: User

# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import anonymous_user [as 别名]
USERS = {1: User(u"Notch", 1), 2: User(u"Steve", 2), 3: User(u"Creeper", 3, False)}

USER_NAMES = dict((u.name, u) for u in USERS.itervalues())


app = Flask(__name__)

SECRET_KEY = "yeah, not actually a secret"
DEBUG = True

app.config.from_object(__name__)

login_manager = LoginManager()

login_manager.anonymous_user = Anonymous
login_manager.login_view = "login"
login_manager.login_message = u"Please log in to access this page."
login_manager.refresh_view = "reauth"


@login_manager.user_loader
def load_user(id):
    return USERS.get(int(id))


login_manager.setup_app(app)


@app.route("/")
def index():
开发者ID:paul-w,项目名称:azeroth,代码行数:32,代码来源:login-example.py

示例3: load_user

# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import anonymous_user [as 别名]
import pwdmanager
from pwdmanager import LmfdbUser, LmfdbAnonymousUser

# TODO update this url, needed for the user login token
base_url = "http://www.l-functions.org"

@login_manager.user_loader
def load_user(userid):
  from pwdmanager import LmfdbUser
  return LmfdbUser(userid) 

login_manager.login_view = "users.info"

# this anonymous user has the is_admin() method
login_manager.anonymous_user = LmfdbAnonymousUser

# globally define the user and username
@app.context_processor
def ctx_proc_userdata():
  userdata = {}
  userdata['username'] = 'Anonymous' if current_user.is_anonymous() else current_user.name
  userdata['user_is_authenticated'] =  current_user.is_authenticated()
  userdata['user_is_admin'] = current_user.is_admin()
  return userdata

# blueprint specific definition of the body_class variable
@login_page.context_processor
def body_class():
  return { 'body_class' : 'login' }
开发者ID:swisherh,项目名称:swisherh-logo,代码行数:31,代码来源:main.py


注:本文中的flaskext.login.LoginManager.anonymous_user方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。