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


Python User.objects方法代码示例

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


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

示例1: get

# 需要导入模块: from api.models import User [as 别名]
# 或者: from api.models.User import objects [as 别名]
    def get(self, username=None):
        response = {}
        if username:
            user = User.objects(username__iexact=username).first()

            if not user:
                abort(404, message="Username does not exist.")

            response = {
                'username': user.username,
                'email': user.email,
                'type': user.user_type,
                'created_at': str(user.created_at),
                'updated_at': str(user.updated_at)
            }
        else:
            users = User.objects()

            for index, user in enumerate(users):
                response[index + 1] = {
                    'username': user.username,
                    'email': user.email,
                    'type': user.user_type,
                    'created_at': str(user.created_at),
                    'updated_at': str(user.updated_at)
                }

        return response
开发者ID:dita-dev-team,项目名称:MemoApi,代码行数:30,代码来源:userapi.py

示例2: post

# 需要导入模块: from api.models import User [as 别名]
# 或者: from api.models.User import objects [as 别名]
    def post(self):
        args = parser.parse_args()

        user = User.objects(username__iexact=args['username']).first()
        if user:
            abort(409, message="Username already exists.")

        user = User(username=args['username'])
        user.password = bcrypt.generate_password_hash(args['password'])

        if args['type'] == 'individual':
            user.user_type = args['type']
            user.user_profile = Individual()
        elif args['type'] == 'group':
            user.user_type = args['type']
            user.user_profile = Group()

        user.save()

        response = {
            'username': user.username,
            'email': user.email,
            'type': user.user_type,
            'created_at': str(user.created_at),
            'updated_at': str(user.updated_at)
        }

        return response
开发者ID:dita-dev-team,项目名称:MemoApi,代码行数:30,代码来源:userapi.py

示例3: delete

# 需要导入模块: from api.models import User [as 别名]
# 或者: from api.models.User import objects [as 别名]
    def delete(self, username):
        if not username:
            abort(404, message="A username is required.")

        user = User.objects(username__iexact=username).first()
        if not user:
            abort(404, message="Username does not exist.")

        user.delete()

        response = {'message': 'deleted'}

        return response
开发者ID:dita-dev-team,项目名称:MemoApi,代码行数:15,代码来源:userapi.py

示例4: put

# 需要导入模块: from api.models import User [as 别名]
# 或者: from api.models.User import objects [as 别名]
    def put(self, username):
        if not username:
            abort(404, message="A username is required.")

        args = auth_parser.parse_args()
        user = User.objects(username__iexact=username).first()

        if not user:
            abort(404, message="Username does not exist.")

        user.password = bcrypt.generate_password_hash(args['password'])

        user.save()

        response = {
            'username': user.username,
            'email': user.email,
            'type': user.user_type,
            'created_at': str(user.created_at),
            'updated_at': str(user.updated_at)
        }

        return response
开发者ID:dita-dev-team,项目名称:MemoApi,代码行数:25,代码来源:userapi.py

示例5: google

# 需要导入模块: from api.models import User [as 别名]
# 或者: from api.models.User import objects [as 别名]
def google(request):
    """API authentication using Google OAuth2"""
    serializer = GoogleAuthSerializer(data=request.data)
    serializer.is_valid(raise_exception=True)

    access_token_url = 'https://accounts.google.com/o/oauth2/token'
    userinfo_url = 'https://www.googleapis.com/oauth2/v2/userinfo'
    payload = {
        'client_id': serializer.validated_data['client_id'],
        'redirect_uri': serializer.validated_data['redirect_uri'],
        'client_secret': settings.GOOGLE_SECRET,
        'code': serializer.validated_data['code'],
        'grant_type': 'authorization_code'
    }

    # Step 1. Exchange authorization code for access token.
    r = requests.post(access_token_url, data=payload)
    token = json.loads(r.text)
    try:
        headers = {'Authorization': 'Bearer {0}'.format(token['access_token'])}
    except KeyError:
        raise AuthenticationError(token['error'])

    # Step 2. Retrieve information about the current user.
    r = requests.get(userinfo_url, headers=headers)
    profile = json.loads(r.text)
    user = User.objects(google=profile['id']).first()
    if user:
        token = create_token(user)
        return Response({'token': token})

    u = User(email=profile['email'], google=profile['id'],
             display_name=profile['name'])
    u.save()
    token = create_token(u)
    return Response({'token': token})
开发者ID:tv-notify,项目名称:tv-notify-server,代码行数:38,代码来源:views.py


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