本文整理汇总了Python中models.mobile_client.MobileClient.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python MobileClient.get_by_id方法的具体用法?Python MobileClient.get_by_id怎么用?Python MobileClient.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.mobile_client.MobileClient
的用法示例。
在下文中一共展示了MobileClient.get_by_id方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models.mobile_client import MobileClient [as 别名]
# 或者: from models.mobile_client.MobileClient import get_by_id [as 别名]
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: post
# 需要导入模块: from models.mobile_client import MobileClient [as 别名]
# 或者: from models.mobile_client.MobileClient import get_by_id [as 别名]
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
if client.client_type == ClientType.WEBHOOK:
keys = {client.client_type: [(client.messaging_id, client.secret)]}
else:
keys = {client.client_type: [client.messaging_id]}
notification = PingNotification()
notification.send(keys)
self.redirect('/account')
else:
self.redirect('/')
示例3: post
# 需要导入模块: from models.mobile_client import MobileClient [as 别名]
# 或者: from models.mobile_client.MobileClient import get_by_id [as 别名]
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('/')
示例4: post
# 需要导入模块: from models.mobile_client import MobileClient [as 别名]
# 或者: from models.mobile_client.MobileClient import get_by_id [as 别名]
def post(self, client_id):
self._require_registration()
self._require_request_user_is_bundle_user()
current_user_account_id = self.user_bundle.account.key.id()
if not current_user_account_id:
return self.redirect('/')
verification = self.request.get('code')
if not verification:
return self.redirect('/webhooks/verify/{}?error=1'.format(webhook.key.id()))
webhook = MobileClient.get_by_id(int(client_id), parent=ndb.Key(Account, current_user_account_id))
if not webhook or webhook.client_type != ClientType.WEBHOOK or current_user_account_id != webhook.user_id:
return self.redirect('/')
if verification == webhook.verification_code:
webhook.verified = True
webhook.put()
return self.redirect('/account?webhook_verification_success=1')
else:
# Redirect back to the verification page
return self.redirect('/webhooks/verify/{}?error=1'.format(webhook.key.id()))