示例#1
0
    def create_action(self, request, serializer):
        session = get_fxa_session(state=serializer.data['state'])
        profile = _fxa_authorize(
            session,
            settings.FXA_CLIENT_SECRET,
            request,
            serializer.data['auth_response'])
        if profile is None:
            raise AuthenticationFailed('No profile.')

        request.user = profile
        request.groups = profile.groups.all()
        # We want to return completely custom data, not the serializer's.
        data = {
            'error': None,
            'token': commonplace_token(request.user.email),
            'settings': {
                'display_name': request.user.display_name,
                'email': request.user.email,
            }
        }
        # Serializers give up if they aren't passed an instance, so we
        # do that here despite PermissionsSerializer not needing one
        # really.
        permissions = PermissionsSerializer(context={'request': request},
                                            instance=True)
        data.update(permissions.data)

        # Add ids of installed/purchased/developed apps.
        data['apps'] = user_relevant_apps(profile)

        return data
示例#2
0
    def create_action(self, request, serializer):
        session = get_fxa_session(state=serializer.data['state'])

        try:
            # Maybe this was a preverified login to migrate a user.
            userid = Signer().unsign(serializer.data['state'])
        except BadSignature:
            userid = None

        profile = _fxa_authorize(session, settings.FXA_CLIENT_SECRET, request,
                                 serializer.data['auth_response'], userid)
        if profile is None:
            raise AuthenticationFailed('No profile.')

        request.user = profile
        request.groups = profile.groups.all()
        # We want to return completely custom data, not the serializer's.
        data = {
            'error': None,
            'token': commonplace_token(request.user.email),
            'settings': {
                'display_name': request.user.display_name,
                'email': request.user.email,
                'source': 'firefox-accounts',
            }
        }
        # Serializers give up if they aren't passed an instance, so we
        # do that here despite PermissionsSerializer not needing one
        # really.
        permissions = PermissionsSerializer(context={'request': request},
                                            instance=True)
        data.update(permissions.data)

        # Add ids of installed/purchased/developed apps.
        data['apps'] = user_relevant_apps(profile)

        return data
示例#3
0
文件: views.py 项目: petercpg/zamboni
    def create_action(self, request, serializer):
        session = get_fxa_session(state=serializer.data["state"])
        profile = _fxa_authorize(session, settings.FXA_CLIENT_SECRET, request, serializer.data["auth_response"])
        if profile is None:
            raise AuthenticationFailed("No profile.")

        request.user, request.amo_user = profile, profile
        request.groups = profile.groups.all()
        # We want to return completely custom data, not the serializer's.
        data = {
            "error": None,
            "token": commonplace_token(request.amo_user.email),
            "settings": {"display_name": request.amo_user.display_name, "email": request.amo_user.email},
        }
        # Serializers give up if they aren't passed an instance, so we
        # do that here despite PermissionsSerializer not needing one
        # really.
        permissions = PermissionsSerializer(context={"request": request}, instance=True)
        data.update(permissions.data)

        # Add ids of installed/purchased/developed apps.
        data["apps"] = user_relevant_apps(profile)

        return data