コード例 #1
0
    def post(self):
        self._require_login("/account/register")
        self._require_registration("/account/register")

        # 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:
            url = self.request.get("url")
            secret_key = self.request.get("secret")
            query = MobileClient.query(
                MobileClient.messaging_id == url, ancestor=ndb.Key(Account, current_user_account_id)
            )
            if query.count() == 0:
                # Webhook doesn't exist, add it
                verification_key = NotificationHelper.verify_webhook(url, secret_key)
                client = MobileClient(
                    parent=self.user_bundle.account.key,
                    user_id=current_user_account_id,
                    messaging_id=url,
                    display_name=self.request.get("name"),
                    secret=secret_key,
                    client_type=ClientType.WEBHOOK,
                    verified=False,
                    verification_code=verification_key,
                )
                client.put()
            else:
                # Webhook already exists. Update the secret
                current = query.fetch()[0]
                current.secret = secret_key
                current.put()
            self.redirect("/account")
        else:
            self.redirect("/")
コード例 #2
0
    def post(self):
        self._require_login()
        self._require_registration()

        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')
            webhook = MobileClient.get_by_id(int(client_id),
                                             parent=ndb.Key(
                                                 Account,
                                                 current_user_account_id))
            if webhook.client_type == ClientType.WEBHOOK and current_user_account_id == webhook.user_id:
                verification_key = NotificationHelper.verify_webhook(
                    webhook.messaging_id, webhook.secret)
                webhook.verification_code = verification_key
                webhook.verified = False
                webhook.put()
                self.redirect('/account')
                return
            else:
                logging.warning("Not webhook, or wrong owner")
        else:
            logging.warning("Users don't match. " + current_user_account_id +
                            "/" + target_account_id)
        self.redirect('/')
コード例 #3
0
    def post(self):
        self._require_login()
        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:
            url = self.request.get('url')
            secret_key = self.request.get('secret')
            query = MobileClient.query(MobileClient.messaging_id == url,
                                       ancestor=ndb.Key(
                                           Account, current_user_account_id))
            if query.count() == 0:
                # Webhook doesn't exist, add it
                verification_key = NotificationHelper.verify_webhook(
                    url, secret_key)
                client = MobileClient(parent=self.user_bundle.account.key,
                                      user_id=current_user_account_id,
                                      messaging_id=url,
                                      display_name=self.request.get('name'),
                                      secret=secret_key,
                                      client_type=ClientType.WEBHOOK,
                                      verified=False,
                                      verification_code=verification_key)
                client.put()
            else:
                # Webhook already exists. Update the secret
                current = query.fetch()[0]
                current.secret = secret_key
                current.put()
            self.redirect('/account')
        else:
            self.redirect('/')
コード例 #4
0
    def post(self):
        self._require_registration()

        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')
            webhook = MobileClient.get_by_id(int(client_id), parent=ndb.Key(Account, current_user_account_id))
            if webhook.client_type == ClientType.WEBHOOK and current_user_account_id == webhook.user_id:
                verification_key = NotificationHelper.verify_webhook(webhook.messaging_id, webhook.secret)
                webhook.verification_code = verification_key
                webhook.verified = False
                webhook.put()
                self.redirect('/account')
                return
            else:
                logging.warning("Not webhook, or wrong owner")
        else:
            logging.warning("Users don't match. "+current_user_account_id+"/"+target_account_id)
        self.redirect('/')