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


Python flask_principal.Identity方法代码示例

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


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

示例1: _check_token

# 需要导入模块: import flask_principal [as 别名]
# 或者: from flask_principal import Identity [as 别名]
def _check_token():
    # N.B. this isn't great Flask-Login 0.5.0 made this protected
    # Issue https://github.com/maxcountryman/flask-login/issues/471
    # was filed to restore public access. We want to call this via
    # login_manager in case someone has overridden the login_manager which we
    # allow.
    if hasattr(_security.login_manager, "request_callback"):
        # Pre 0.5.0
        user = _security.login_manager.request_callback(request)
    else:
        user = _security.login_manager._request_callback(request)

    if user and user.is_authenticated:
        app = current_app._get_current_object()
        _request_ctx_stack.top.user = user
        identity_changed.send(app, identity=Identity(user.fs_uniquifier))
        return True

    return False 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:21,代码来源:decorators.py

示例2: configure_auth

# 需要导入模块: import flask_principal [as 别名]
# 或者: from flask_principal import Identity [as 别名]
def configure_auth():
    from zou.app.services import persons_service

    @jwt.token_in_blacklist_loader
    def check_if_token_is_revoked(decrypted_token):
        return auth_tokens_store.is_revoked(decrypted_token)

    @jwt.user_loader_callback_loader
    def add_permissions(callback):
        try:
            user = persons_service.get_current_user()
            if user is not None:
                identity_changed.send(
                    current_app._get_current_object(),
                    identity=Identity(user["id"]),
                )
            return user
        except PersonNotFoundException:
            return None 
开发者ID:cgwire,项目名称:zou,代码行数:21,代码来源:__init__.py

示例3: login

# 需要导入模块: import flask_principal [as 别名]
# 或者: from flask_principal import Identity [as 别名]
def login():
    """GET|POST /login: login form handler
    """
    form = LoginForm()
    if form.validate_on_submit():
        # login user
        u = User.query.filter(User.email == form.email.data).first()
        login_user(u, remember=form.remember_me.data)

        # tell flask-principal the identity changed
        identity_changed.send(current_app._get_current_object(),
                              identity=Identity(u.id))

        return redirect(request.args.get('next') or url_for('content.home'))

    return render_template('/auth/login.html', form=form) 
开发者ID:muicss,项目名称:flaskapp,代码行数:18,代码来源:auth.py

示例4: create_account

# 需要导入模块: import flask_principal [as 别名]
# 或者: from flask_principal import Identity [as 别名]
def create_account():
    """GET|POST /create-account: create account form handler
    """
    form = CreateAccountForm()
    if form.validate_on_submit():
        # add user to database
        u = User(email=form.email.data,
                 password=generate_password_hash(form.password.data))
        db.session.add(u)
        db.session.flush()

        # send verification email
        send_verification_email(u)

        # login user
        login_user(u, remember=True)
        identity_changed.send(current_app._get_current_object(),
                              identity=Identity(u.id))

        return redirect(request.args.get('next') or url_for('content.home'))

    return render_template('/auth/create-account.html', form=form) 
开发者ID:muicss,项目名称:flaskapp,代码行数:24,代码来源:auth.py

示例5: identity

# 需要导入模块: import flask_principal [as 别名]
# 或者: from flask_principal import Identity [as 别名]
def identity(self):
        """
        Returns the identity for the auth context.
        """
        if self.oauthtoken:
            scope_set = scopes_from_scope_string(self.oauthtoken.scope)
            return QuayDeferredPermissionUser.for_user(self.oauthtoken.authorized_user, scope_set)

        if self.authed_user:
            return QuayDeferredPermissionUser.for_user(self.authed_user)

        if self.token:
            return Identity(self.token.get_code(), "token")

        if self.signed_data:
            identity = Identity(None, "signed_grant")
            identity.provides.update(self.signed_data["grants"])
            return identity

        return None 
开发者ID:quay,项目名称:quay,代码行数:22,代码来源:auth_context_type.py

示例6: post

# 需要导入模块: import flask_principal [as 别名]
# 或者: from flask_principal import Identity [as 别名]
def post(self):
        if request.form.get('login_github'):
            session['oauth_callback_type'] = 'login'
            return github_auth.github_auth()
            # return 'login_github'

        form = forms.LoginForm(obj=request.form)
        if form.validate():
            try:
                user = models.User.objects.get(username=form.username.data)
            except models.User.DoesNotExist:
                user = None

            if user and user.verify_password(form.password.data):
                login_user(user, form.remember_me.data)
                user.last_login = datetime.datetime.now
                user.save()
                identity_changed.send(current_app._get_current_object(), identity=Identity(user.username))
                return redirect(request.args.get('next') or url_for('main.index'))
            flash('Invalid username or password', 'danger')
        return self.get(form=form) 
开发者ID:GitMarkTeam,项目名称:gitmark,代码行数:23,代码来源:views.py

示例7: api_auth_required

# 需要导入模块: import flask_principal [as 别名]
# 或者: from flask_principal import Identity [as 别名]
def api_auth_required(f):
    @wraps(f)
    def wrapper(*args, **kwargs):
        if request.authorization and request.authorization.type == "basic":
            user = user_datastore.find_user(api_key=request.authorization.username)
            if user and user.has_role("developer"):
                _request_ctx_stack.top.user = user
                identity_changed.send(
                    current_app._get_current_object(), identity=Identity(user.id)
                )
                return f(*args, **kwargs)
        abort(401)

    return wrapper 
开发者ID:SynoCommunity,项目名称:spkrepo,代码行数:16,代码来源:api.py

示例8: _check_http_auth

# 需要导入模块: import flask_principal [as 别名]
# 或者: from flask_principal import Identity [as 别名]
def _check_http_auth():
    auth = request.authorization or BasicAuth(username=None, password=None)
    if not auth.username:
        return False
    user = find_user(auth.username)

    if user and user.verify_and_update_password(auth.password):
        _security.datastore.commit()
        app = current_app._get_current_object()
        _request_ctx_stack.top.user = user
        identity_changed.send(app, identity=Identity(user.fs_uniquifier))
        return True

    return False 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:16,代码来源:decorators.py

示例9: _

# 需要导入模块: import flask_principal [as 别名]
# 或者: from flask_principal import Identity [as 别名]
def _(translate):
    """Identity function to mark strings for translation."""
    return translate 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:5,代码来源:utils.py

示例10: _identity_loader

# 需要导入模块: import flask_principal [as 别名]
# 或者: from flask_principal import Identity [as 别名]
def _identity_loader():
    if not isinstance(current_user._get_current_object(), AnonymousUserMixin):
        identity = Identity(current_user.fs_uniquifier)
        return identity 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:6,代码来源:core.py

示例11: reset_password

# 需要导入模块: import flask_principal [as 别名]
# 或者: from flask_principal import Identity [as 别名]
def reset_password():
    """GET /reset-password: choose new password
    """
    # get password-reset entry
    f = (PasswordResetRequest.key == request.args.get('key'),
         User.email == request.args.get('email'))
    r = PasswordResetRequest.query.filter(*f).first()

    # return error response if link doesn't exist or wrong email
    if r == None or r.user.email != request.args['email']:
        return render_template('/auth/reset-password-error.html'), 400

    # expired if older than 1 day
    delta = datetime.datetime.utcnow() - r.create_ts
    if delta.days > 0:
        db.session.delete(r)
        db.session.flush()
        return render_template('/auth/reset-password-error.html'), 400

    # handle form
    form = ResetPasswordForm()
    if form.validate_on_submit():
        # save new password
        u = r.user
        u.password = generate_password_hash(form.password.data)
        db.session.add(u)

        # login user
        login_user(u, remember=True)
        identity_changed.send(current_app._get_current_object(),
                              identity=Identity(u.id))

        # delete password reset
        db.session.delete(r)
        db.session.flush()

        return render_template('/auth/reset-password-followup.html')

    return render_template('/auth/reset-password.html', form=form) 
开发者ID:muicss,项目名称:flaskapp,代码行数:41,代码来源:auth.py

示例12: request_reissue

# 需要导入模块: import flask_principal [as 别名]
# 或者: from flask_principal import Identity [as 别名]
def request_reissue(certificate, commit):
    """
    Reissuing certificate and handles any exceptions.
    :param certificate:
    :param commit:
    :return:
    """
    status = FAILURE_METRIC_STATUS
    try:
        print("[+] {0} is eligible for re-issuance".format(certificate.name))

        # set the lemur identity for all cli commands
        identity_changed.send(current_app._get_current_object(), identity=Identity(1))

        details = get_certificate_primitives(certificate)
        print_certificate_details(details)

        if commit:
            new_cert = reissue_certificate(certificate, replace=True)
            print("[+] New certificate named: {0}".format(new_cert.name))

        status = SUCCESS_METRIC_STATUS

    except Exception as e:
        sentry.captureException(extra={"certificate_name": str(certificate.name)})
        current_app.logger.exception(
            f"Error reissuing certificate: {certificate.name}", exc_info=True
        )
        print(f"[!] Failed to reissue certificate: {certificate.name}. Reason: {e}")

    metrics.send(
        "certificate_reissue",
        "counter",
        1,
        metric_tags={"status": status, "certificate": certificate.name},
    ) 
开发者ID:Netflix,项目名称:lemur,代码行数:38,代码来源:cli.py

示例13: logged_in_user

# 需要导入模块: import flask_principal [as 别名]
# 或者: from flask_principal import Identity [as 别名]
def logged_in_user(session, app):
    with app.test_request_context():
        identity_changed.send(current_app._get_current_object(), identity=Identity(1))
        yield 
开发者ID:Netflix,项目名称:lemur,代码行数:6,代码来源:conftest.py

示例14: _check_token

# 需要导入模块: import flask_principal [as 别名]
# 或者: from flask_principal import Identity [as 别名]
def _check_token():
    user = security.login_manager._request_callback(request)

    if user and user.is_authenticated:
        _request_ctx_stack.top.user = user
        identity_changed.send(current_app._get_current_object(),
                              identity=Identity(user.id))
        return True

    return False 
开发者ID:briancappello,项目名称:flask-unchained,代码行数:12,代码来源:auth_required.py

示例15: _identity_loader

# 需要导入模块: import flask_principal [as 别名]
# 或者: from flask_principal import Identity [as 别名]
def _identity_loader(self) -> Union[Identity, None]:
        """
        Identity loading function to be passed to be assigned to the Principal
        instance returned by :meth:`_get_principal`.
        """
        if not isinstance(current_user._get_current_object(), AnonymousUser):
            return Identity(current_user.id) 
开发者ID:briancappello,项目名称:flask-unchained,代码行数:9,代码来源:security.py


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