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


Python PushHelper.user_email_to_id方法代码示例

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


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

示例1: add_subscription

# 需要导入模块: from helpers.push_helper import PushHelper [as 别名]
# 或者: from helpers.push_helper.PushHelper import user_email_to_id [as 别名]
    def add_subscription(self, request):
        current_user = endpoints.get_current_user()
        if current_user is None:
            return BaseResponse(code=401, message="Unauthorized to add subscription")
        userId = PushHelper.user_email_to_id(current_user.email())
        modelKey = request.model_key

        sub = Subscription.query( Subscription.user_id == userId, Subscription.model_key == modelKey).get()
        if sub is None:
            # Subscription doesn't exist, add it
            Subscription( user_id = userId, model_key = modelKey, notification_types = PushHelper.notification_enums_from_string(request.notifications)).put()
            if request.device_key:
                # Send updates to user's other devices
                GCMMessageHelper.send_subscription_update(userId, request.device_key)
            return BaseResponse(code=200, message="Subscription added")
        else:
            if sub.notification_types == PushHelper.notification_enums_from_string(request.notifications):
                # Subscription already exists. Don't add it again
                return BaseResponse(code=304, message="Subscription already exists")
            else:
                # We're updating the settings
                sub.notification_types = PushHelper.notification_enums_from_string(request.notifications)
                sub.put()
                if request.device_key:
                    # Send updates to user's other devices
                    GCMMessageHelper.send_subscription_update(userId, request.device_key)
                return BaseResponse(code=200, message="Subscription updated")
开发者ID:dewdn2,项目名称:the-blue-alliance,代码行数:29,代码来源:mobile_main.py

示例2: suggest_team_media

# 需要导入模块: from helpers.push_helper import PushHelper [as 别名]
# 或者: from helpers.push_helper.PushHelper import user_email_to_id [as 别名]
    def suggest_team_media(self, request):
        current_user = endpoints.get_current_user()
        if current_user is None:
            return BaseResponse(code=401, message="Unauthorized to make suggestions")
        user_id = PushHelper.user_email_to_id(current_user.email())

        # For now, only allow team media suggestions
        if request.reference_type != "team":
            # Trying to suggest a media for an invalid model type
            return BaseResponse(code=400, message="Bad model type")

        # Need to split deletehash out into its own private dict. Don't want that to be exposed via API...
        private_details_json = None
        if request.details_json:
            incoming_details = json.loads(request.details_json)
            private_details = None
            if 'deletehash' in incoming_details:
                private_details = {'deletehash': incoming_details.pop('deletehash')}
            private_details_json = json.dumps(private_details) if private_details else None

        status = SuggestionCreator.createTeamMediaSuggestion(
            author_account_key=ndb.Key(Account, user_id),
            media_url=request.media_url,
            team_key=request.reference_key,
            year_str=str(request.year),
            private_details_json=private_details_json)

        if status != 'bad_url':
            if status == 'success':
                return BaseResponse(code=200, message="Suggestion added")
            else:
                return BaseResponse(code=304, message="Suggestion already exists")
        else:
            return BaseResponse(code=400, message="Bad suggestion url")
开发者ID:umer936,项目名称:the-blue-alliance,代码行数:36,代码来源:mobile_main.py

示例3: ping_client

# 需要导入模块: from helpers.push_helper import PushHelper [as 别名]
# 或者: from helpers.push_helper.PushHelper import user_email_to_id [as 别名]
    def ping_client(self, request):
        current_user = endpoints.get_current_user()
        if current_user is None:
            return BaseResponse(code=401, message="Unauthorized to ping client")

        user_id = PushHelper.user_email_to_id(current_user.email())
        gcm_id = request.mobile_id

        # Find a Client for the current user with the passed GCM ID
        clients = MobileClient.query(MobileClient.messaging_id == gcm_id, ancestor=ndb.Key(Account, user_id)).fetch(1)
        if len(clients) == 0:
            # No Client for user with that push token - bailing
            return BaseResponse(code=404, message="Invalid push token for user")
        else:
            client = clients[0]
            response = NotificationHelper.send_ping(client)
            # If we got a response from the send_ping method, it was sent via TBANS
            # We'll bubble up any errors we got back
            if response:
                if response.code == 200:
                    return BaseResponse(code=200, message="Ping sent")
                else:
                    return BaseResponse(code=response.code, message="Error pinging client - {}".format(response.message))
            else:
                return BaseResponse(code=200, message="Ping sent")
开发者ID:ZachOrr,项目名称:the-blue-alliance,代码行数:27,代码来源:mobile_main.py

示例4: list_favorites

# 需要导入模块: from helpers.push_helper import PushHelper [as 别名]
# 或者: from helpers.push_helper.PushHelper import user_email_to_id [as 别名]
    def list_favorites(self, request):
        current_user = endpoints.get_current_user()
        if current_user is None:
            return FavoriteCollection(favorites=[])
        user_id = PushHelper.user_email_to_id(current_user.email())

        favorites = Favorite.query(ancestor=ndb.Key(Account, user_id)).fetch()
        output = []
        for favorite in favorites:
            output.append(FavoriteMessage(model_key=favorite.model_key, model_type=favorite.model_type))
        return FavoriteCollection(favorites=output)
开发者ID:csteward24,项目名称:the-blue-alliance,代码行数:13,代码来源:mobile_main.py

示例5: list_subscriptions

# 需要导入模块: from helpers.push_helper import PushHelper [as 别名]
# 或者: from helpers.push_helper.PushHelper import user_email_to_id [as 别名]
    def list_subscriptions(self, request):
        current_user = endpoints.get_current_user()
        if current_user is None:
            return SubscriptionCollection(subscriptions = [])
        userId = PushHelper.user_email_to_id(current_user.email())

        subscriptions = Subscription.query( Subscription.user_id == userId ).fetch()
        output = []
        for subscription in subscriptions:
            output.append(SubscriptionMessage(model_key = subscription.model_key, notifications = PushHelper.notification_string_from_enums(subscription.notification_types)))
        return SubscriptionCollection(subscriptions = output)
开发者ID:dewdn2,项目名称:the-blue-alliance,代码行数:13,代码来源:mobile_main.py

示例6: unregister_client

# 需要导入模块: from helpers.push_helper import PushHelper [as 别名]
# 或者: from helpers.push_helper.PushHelper import user_email_to_id [as 别名]
 def unregister_client(self, request):
     current_user = endpoints.get_current_user()
     if current_user is None:
         return BaseResponse(code=401, message="Unauthorized to unregister")
     userID = PushHelper.user_email_to_id(current_user.email())
     gcmId = request.mobile_id
     query = MobileClient.query(MobileClient.messaging_id == gcmId, MobileClient.user_id == userID).fetch(keys_only=True)
     if len(query) == 0:
         # Record doesn't exist, so we can't remove it
         return BaseResponse(code=404, message="User doesn't exist. Can't remove it")
     else:
         ndb.delete_multi(query)
         return BaseResponse(code=200, message="User deleted")
开发者ID:dewdn2,项目名称:the-blue-alliance,代码行数:15,代码来源:mobile_main.py

示例7: get_current_user_id

# 需要导入模块: from helpers.push_helper import PushHelper [as 别名]
# 或者: from helpers.push_helper.PushHelper import user_email_to_id [as 别名]
def get_current_user_id(headers):
    auth = headers.get('Authorization')
    if not auth:
        return None

    id_token = auth.split(' ').pop()
    try:
        claims = google.oauth2.id_token.verify_firebase_token(id_token, HTTP_REQUEST)
    except ValueError:
        return None

    if not claims:
        return None
    else:
        return PushHelper.user_email_to_id(claims['email'])
开发者ID:ZachOrr,项目名称:the-blue-alliance,代码行数:17,代码来源:clientapi_service.py

示例8: register_client

# 需要导入模块: from helpers.push_helper import PushHelper [as 别名]
# 或者: from helpers.push_helper.PushHelper import user_email_to_id [as 别名]
 def register_client(self, request):
     current_user = endpoints.get_current_user()
     if current_user is None:
         return BaseResponse(code=401, message="Unauthorized to register")
     userId = PushHelper.user_email_to_id(current_user.email())
     gcmId = request.mobile_id
     os = ClientType.enums[request.operating_system]
     if MobileClient.query( MobileClient.messaging_id==gcmId ).count() == 0:
         # Record doesn't exist yet, so add it
         MobileClient(   messaging_id = gcmId,
                         user_id = userId,
                         client_type = os ).put()
         return BaseResponse(code=200, message="Registration successful")
     else:
         # Record already exists, don't bother updating it again
         return BaseResponse(code=304, message="Client already exists")
开发者ID:dewdn2,项目名称:the-blue-alliance,代码行数:18,代码来源:mobile_main.py

示例9: remove_subscription

# 需要导入模块: from helpers.push_helper import PushHelper [as 别名]
# 或者: from helpers.push_helper.PushHelper import user_email_to_id [as 别名]
    def remove_subscription(self, request):
        current_user = endpoints.get_current_user()
        if current_user is None:
            return BaseResponse(code=401, message="Unauthorized to remove subscription")
        userId = PushHelper.user_email_to_id(current_user.email())
        modelKey = request.model_key

        to_delete = Subscription.query( Subscription.user_id == userId, Subscription.model_key == modelKey).fetch(keys_only=True)
        if len(to_delete) > 0:
            ndb.delete_multi(to_delete)
            if request.device_key:
                # Send updates to user's other devices
                GCMMessageHelper.send_subscription_update(userId, request.device_key)
            return BaseResponse(code=200, message="Subscriptions deleted")
        else:
            # Subscription doesn't exist. Can't delete it
            return BaseResponse(code=404, message="Subscription not found")
开发者ID:dewdn2,项目名称:the-blue-alliance,代码行数:19,代码来源:mobile_main.py

示例10: add_favorite

# 需要导入模块: from helpers.push_helper import PushHelper [as 别名]
# 或者: from helpers.push_helper.PushHelper import user_email_to_id [as 别名]
    def add_favorite(self, request):
        current_user = endpoints.get_current_user()
        if current_user is None:
            return BaseResponse(code=401, message="Unauthorized to add favorite")
        userId = PushHelper.user_email_to_id(current_user.email())
        modelKey = request.model_key

        if Favorite.query( Favorite.user_id == userId, Favorite.model_key == modelKey).count() == 0:
            # Favorite doesn't exist, add it
            Favorite( user_id = userId, model_key = modelKey).put()
            if request.device_key:
                # Send updates to user's other devices
                logging.info("Sending favorite update to user other devices")
                GCMMessageHelper.send_favorite_update(userId, request.device_key)
            return BaseResponse(code=200, message="Favorite added")
        else:
            # Favorite already exists. Don't add it again
            return BaseResponse(code=304, message="Favorite already exists")
开发者ID:dewdn2,项目名称:the-blue-alliance,代码行数:20,代码来源:mobile_main.py

示例11: suggest_team_media

# 需要导入模块: from helpers.push_helper import PushHelper [as 别名]
# 或者: from helpers.push_helper.PushHelper import user_email_to_id [as 别名]
    def suggest_team_media(self, request):
        current_user = endpoints.get_current_user()
        if current_user is None:
            return BaseResponse(code=401, message="Unauthorized to make suggestions")
        user_id = PushHelper.user_email_to_id(current_user.email())

        # For now, only allow team media suggestions
        if request.reference_type != "team":
            # Trying to suggest a media for an invalid model type
            return BaseResponse(code=400, message="Bad model type")

        media_dict = MediaParser.partial_media_dict_from_url(request.media_url.strip())
        if media_dict is not None:
            existing_media = Media.get_by_id(
                    Media.render_key_name(media_dict['media_type_enum'], media_dict['foreign_key']))
            if existing_media is None \
                    or request.reference_key not in [reference.id() for reference in existing_media.references]:
                media_dict['year'] = request.year
                media_dict['reference_type'] = request.reference_type
                media_dict['reference_key'] = request.reference_key

                # Need to split deletehash out into its own private dict. Don't want that to be exposed via API...
                if request.details_json:
                    incoming_details = json.loads(request.details_json)
                    private_details = None
                    if 'deletehash' in incoming_details:
                        private_details = {'deletehash': incoming_details.pop('deletehash')}

                    media_dict['private_details_json'] = json.dumps(private_details) if private_details else None
                    media_dict['details_json'] = json.dumps(incoming_details)

                suggestion = Suggestion(
                    author=ndb.Key(Account, user_id),
                    target_model="media"
                )
                suggestion.contents = media_dict
                suggestion.put()

                return BaseResponse(code=200, message="Suggestion added")
            else:
                return BaseResponse(code=304, message="Suggestion already exists")
        else:
            return BaseResponse(code=400, message="Bad suggestion url")
开发者ID:csteward24,项目名称:the-blue-alliance,代码行数:45,代码来源:mobile_main.py

示例12: register_client

# 需要导入模块: from helpers.push_helper import PushHelper [as 别名]
# 或者: from helpers.push_helper.PushHelper import user_email_to_id [as 别名]
    def register_client(self, request):
        current_user = endpoints.get_current_user()
        if current_user is None:
            return BaseResponse(code=401, message="Unauthorized to register")
        user_id = PushHelper.user_email_to_id(current_user.email())
        gcm_id = request.mobile_id
        os = ClientType.enums[request.operating_system]
        name = request.name
        uuid = request.device_uuid

        query = MobileClient.query(
                MobileClient.user_id == user_id,
                MobileClient.device_uuid == uuid,
                MobileClient.client_type == os)
        # trying to figure out an elusive dupe bug
        logging.info("DEBUGGING")
        logging.info("User ID: {}".format(user_id))
        logging.info("UUID: {}".format(uuid))
        logging.info("Count: {}".format(query.count()))
        if query.count() == 0:
            # Record doesn't exist yet, so add it
            MobileClient(
                parent=ndb.Key(Account, user_id),
                user_id=user_id,
                messaging_id=gcm_id,
                client_type=os,
                device_uuid=uuid,
                display_name=name).put()
            return BaseResponse(code=200, message="Registration successful")
        else:
            # Record already exists, update it
            client = query.fetch(1)[0]
            client.messaging_id = gcm_id
            client.display_name = name
            client.put()
            return BaseResponse(code=304, message="Client already exists")
开发者ID:csteward24,项目名称:the-blue-alliance,代码行数:38,代码来源:mobile_main.py

示例13: update_model_preferences

# 需要导入模块: from helpers.push_helper import PushHelper [as 别名]
# 或者: from helpers.push_helper.PushHelper import user_email_to_id [as 别名]
    def update_model_preferences(self, request):
        current_user = endpoints.get_current_user()
        if current_user is None:
            return BaseResponse(code=401, message="Unauthorized to update model preferences")
        user_id = PushHelper.user_email_to_id(current_user.email())
        model_key = request.model_key
        output = {}
        code = 0

        if request.favorite:
            fav = Favorite(
                parent=ndb.Key(Account, user_id),
                user_id=user_id,
                model_key=model_key,
                model_type=request.model_type
            )
            result = MyTBAHelper.add_favorite(fav, request.device_key)
            if result == 200:
                output['favorite'] = {"code":    200,
                                      "message": "Favorite added"}
                code += 100
            elif result == 304:
                output['favorite'] = {"code":    304,
                                      "message": "Favorite already exists"}
                code += 304
            else:
                output['favorite'] = {"code":    500,
                                      "message": "Unknown error adding favorite"}
                code += 500
        else:
            result = MyTBAHelper.remove_favorite(user_id, model_key, request.device_key)
            if result == 200:
                output['favorite'] = {"code":    200,
                                      "message": "Favorite deleted"}
                code += 100
            elif result == 404:
                output['favorite'] = {"code":    404,
                                      "message": "Favorite not found"}
                code += 404
            else:
                output['favorite'] = {"code":    500,
                                      "message": "Unknown error removing favorite"}
                code += 500

        if request.notifications:
            sub = Subscription(
                parent=ndb.Key(Account, user_id),
                user_id=user_id,
                model_key=model_key,
                model_type=request.model_type,
                notification_types=PushHelper.notification_enums_from_string(request.notifications)
            )
            result = MyTBAHelper.add_subscription(sub, request.device_key)
            if result == 200:
                output['subscription'] = {"code":    200,
                                          "message": "Subscription updated"}
                code += 100
            elif result == 304:
                output['subscription'] = {"code":    304,
                                          "message": "Subscription already exists"}
                code += 304
            else:
                output['subscription'] = {"code":    500,
                                          "message": "Unknown error adding favorite"}
                code += 500
        else:
            result = MyTBAHelper.remove_subscription(user_id, model_key, request.device_key)
            if result == 200:
                output['subscription'] = {"code":    200,
                                          "message": "Subscription removed"}
                code += 100
            elif result == 404:
                output['subscription'] = {"code":    404,
                                          "message": "Subscription not found"}
                code += 404
            else:
                output['subscription'] = {"code":    500,
                                          "message": "Unknown error removing subscription"}
                code += 500

        return BaseResponse(code=code, message=json.dumps(output))
开发者ID:csteward24,项目名称:the-blue-alliance,代码行数:83,代码来源:mobile_main.py


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