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


Python User.get_by_id方法代码示例

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


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

示例1: _validate_request

# 需要导入模块: from h.accounts.models import User [as 别名]
# 或者: from h.accounts.models.User import get_by_id [as 别名]
def _validate_request(request):
    """
    Check that the passed request is appropriate for proceeding with account
    claim. Asserts that:

    - the 'claim' feature is toggled on
    - no-one is logged in
    - the claim token is provided and authentic
    - the user referred to in the token exists
    - the user referred to in the token has not already claimed their account

    and raises for redirect or 404 otherwise.
    """
    if not request.feature('claim'):
        raise exc.HTTPNotFound()

    # If signed in, redirect to stream
    if request.authenticated_userid is not None:
        _perform_logged_in_redirect(request)

    payload = _validate_token(request)
    if payload is None:
        raise exc.HTTPNotFound()

    user = User.get_by_id(request, payload['userid'])
    if user is None:
        log.warn('got claim token with invalid userid=%r', payload['userid'])
        raise exc.HTTPNotFound()

    # User already has a password? Claimed already.
    if user.password:
        _perform_already_claimed_redirect(request)

    return user
开发者ID:hylhero,项目名称:h,代码行数:36,代码来源:views.py

示例2: edit_profile

# 需要导入模块: from h.accounts.models import User [as 别名]
# 或者: from h.accounts.models.User import get_by_id [as 别名]
    def edit_profile(self):
        """Handle POST payload from profile update form."""
        if self.request.method != 'POST':
            return httpexceptions.HTTPMethodNotAllowed()

        # Nothing to do here for non logged-in users
        if self.request.authenticated_userid is None:
            return httpexceptions.HTTPUnauthorized()

        err, appstruct = validate_form(self.form, self.request.POST.items())
        if err is not None:
            return err

        user = User.get_by_id(self.request, self.request.authenticated_userid)
        response = {'model': {'email': user.email}}

        # We allow updating subscriptions without validating a password
        subscriptions = appstruct.get('subscriptions')
        if subscriptions:
            data = json.loads(subscriptions)
            err = _update_subscription_data(self.request, data)
            if err is not None:
                return err
            return response

        # Any updates to fields below this point require password validation.
        #
        #   `pwd` is the current password
        #   `password` (used below) is optional, and is the new password
        #
        if not User.validate_user(user, appstruct.get('pwd')):
            return {'errors': {'pwd': _('Invalid password')}, 'code': 401}

        email = appstruct.get('email')
        if email:
            email_user = User.get_by_email(email)

            if email_user:
                if email_user.id != user.id:
                    return {
                        'errors': {'pwd': _('That email is already used')},
                    }

            response['model']['email'] = user.email = email

        password = appstruct.get('password')
        if password:
            user.password = password

        return response
开发者ID:hylhero,项目名称:h,代码行数:52,代码来源:views.py

示例3: profile

# 需要导入模块: from h.accounts.models import User [as 别名]
# 或者: from h.accounts.models.User import get_by_id [as 别名]
    def profile(self):
        """
        Return a serialisation of the user's profile.

        For use by the frontend. Includes current email and subscriptions data.
        """
        request = self.request
        userid = request.authenticated_userid
        model = {}
        if userid:
            model["email"] = User.get_by_id(request, userid).email
        if request.feature("notification"):
            model["subscriptions"] = Subscriptions.get_subscriptions_for_uri(userid)
        return {"model": model}
开发者ID:stuk88,项目名称:h,代码行数:16,代码来源:views.py


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