コード例 #1
0
    def post(self):
        self._require_registration()

        # Check to make sure that they aren't trying to edit another user
        current_user_account_id = self.user_bundle.account.key.id()
        target_account_id = self.request.get('account_id')
        if target_account_id == current_user_account_id:
            client_id = self.request.get('client_id')
            client = MobileClient.get_by_id(int(client_id), parent=ndb.Key(Account, current_user_account_id))
            if client is not None:
                # This makes sure that the client actually exists and that this user owns it
                NotificationHelper.send_ping(client)
                return self.redirect('/account?ping_sent=1')
        self.redirect('/')
コード例 #2
0
    def ping_client(self, request):
        user_id = get_current_user_id(self.headers)
        if user_id is None:
            return BaseResponse(code=401,
                                message="Unauthorized to ping client")

        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")
コード例 #3
0
    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")
コード例 #4
0
    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]
            NotificationHelper.send_ping(client)
            return BaseResponse(code=200, message="Ping sent")
コード例 #5
0
    def post(self):
        self._require_registration()

        # Check to make sure that they aren't trying to edit another user
        current_user_account_id = self.user_bundle.account.key.id()
        target_account_id = self.request.get('account_id')
        if target_account_id == current_user_account_id:
            client_id = self.request.get('client_id')
            client = MobileClient.get_by_id(int(client_id),
                                            parent=ndb.Key(
                                                Account,
                                                current_user_account_id))
            if client is not None:
                # This makes sure that the client actually exists and that this user owns it
                NotificationHelper.send_ping(client)
                return self.redirect('/account?ping_sent=1')
        self.redirect('/')