本文整理汇总了Python中models.mobile_client.MobileClient类的典型用法代码示例。如果您正苦于以下问题:Python MobileClient类的具体用法?Python MobileClient怎么用?Python MobileClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MobileClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: post
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("/")
开发者ID:cmlicata,项目名称:the-blue-alliance,代码行数:35,代码来源:webhook_controller.py
示例2: post
def post(self):
if not self.user_bundle.user:
self.response.set_status(401)
return
user_id = self.user_bundle.user.user_id()
fcm_token = self.request.get('fcm_token')
uuid = self.request.get('uuid')
display_name = self.request.get('display_name')
client_type = ClientType.WEB
query = MobileClient.query(
MobileClient.user_id == user_id,
MobileClient.device_uuid == uuid,
MobileClient.client_type == client_type)
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=fcm_token,
client_type=client_type,
device_uuid=uuid,
display_name=display_name).put()
else:
# Record already exists, update it
client = query.fetch(1)[0]
client.messaging_id = fcm_token
client.display_name = display_name
client.put()
开发者ID:CarlColglazier,项目名称:the-blue-alliance,代码行数:30,代码来源:ajax_controller.py
示例3: ping_client
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,代码行数:25,代码来源:mobile_main.py
示例4: get_client_ids_for_users
def get_client_ids_for_users(cls, os_type, user_list):
output = []
for user in user_list:
client_list = MobileClient.query(MobileClient.user_id == user, MobileClient.client_type == ClientType.enums[os_type]).fetch()
for client in client_list:
output.append(client.messaging_id)
return output
开发者ID:dewdn2,项目名称:the-blue-alliance,代码行数:7,代码来源:push_helper.py
示例5: register_client
def register_client(self, request):
user_id = get_current_user_id(self.headers)
if user_id is None:
return BaseResponse(code=401, message="Unauthorized to register")
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:ZachOrr,项目名称:the-blue-alliance,代码行数:35,代码来源:clientapi_service.py
示例6: get
def get(self):
self._require_admin()
all_clients = MobileClient.query()
android = all_clients.filter(MobileClient.client_type == ClientType.OS_ANDROID).count()
ios = all_clients.filter(MobileClient.client_type == ClientType.OS_IOS).count()
webhook = all_clients.filter(MobileClient.client_type == ClientType.WEBHOOK).count()
var = Sitevar.get_by_id('notifications.enable')
if var is None or not var.values_json == "true":
push_enabled = False
else:
push_enabled = True
self.template_values.update({
'mobile_users': all_clients.count(),
'android_users': android,
'ios_users': ios,
'webhooks': webhook,
'broadcast_success': self.request.get('broadcast_success'),
'push_enabled': push_enabled,
})
path = os.path.join(os.path.dirname(__file__), '../../templates/admin/mobile_dashboard.html')
self.response.out.write(template.render(path, self.template_values))
开发者ID:brycematsuda,项目名称:the-blue-alliance,代码行数:25,代码来源:admin_mobile_controller.py
示例7: get_all_mobile_clients
def get_all_mobile_clients(cls, client_types=[]):
output = []
if client_types == []:
return output
clients = MobileClient.query(MobileClient.client_type.IN(client_types))
for user in clients:
output.append(user.user_id)
return output
开发者ID:BowlesCR,项目名称:the-blue-alliance,代码行数:8,代码来源:push_helper.py
示例8: get_client_ids_for_users
def get_client_ids_for_users(cls, user_list, os_types=None):
if os_types is None:
os_types = ClientType.names.keys()
output = defaultdict(list)
clients = MobileClient.query(MobileClient.user_id.IN(user_list), MobileClient.client_type.IN(os_types), MobileClient.verified == True).fetch()
for client in clients:
if client.client_type == ClientType.WEBHOOK:
output[client.client_type].append((client.messaging_id, client.secret))
else:
output[client.client_type].append(client.messaging_id)
return output
开发者ID:BowlesCR,项目名称:the-blue-alliance,代码行数:11,代码来源:push_helper.py
示例9: post
def post(self):
self._require_registration()
self._require_request_user_is_bundle_user()
# Name and URL must be non-None
url = self.request.get('url', None)
name = self.request.get('name', None)
if not url or not name:
return self.redirect('/webhooks/add?error=1')
# Secret may be none - but we'll generate a secret for the user
secret = self.request.get('secret', None)
if not secret:
import uuid
secret = uuid.uuid4().hex
current_user_account_id = self.user_bundle.account.key.id()
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
from helpers.tbans_helper import TBANSHelper
response = TBANSHelper.verify_webhook(url, secret)
client = MobileClient(
parent=self.user_bundle.account.key,
user_id=current_user_account_id,
messaging_id=url,
display_name=name,
secret=secret,
client_type=ClientType.WEBHOOK,
verified=False,
verification_code=response.verification_key)
client.put()
else:
# Webhook already exists. Update the secret
current = query.fetch()[0]
current.secret = secret
current.put()
self.redirect('/account')
开发者ID:ZachOrr,项目名称:the-blue-alliance,代码行数:40,代码来源:webhook_controller.py
示例10: unregister_client
def unregister_client(self, request):
user_id = get_current_user_id(self.headers)
if user_id is None:
return BaseResponse(code=401, message="Unauthorized to unregister")
gcm_id = request.mobile_id
query = MobileClient.query(MobileClient.messaging_id == gcm_id, ancestor=ndb.Key(Account, user_id))\
.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:ZachOrr,项目名称:the-blue-alliance,代码行数:13,代码来源:clientapi_service.py
示例11: unregister_client
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,代码行数:13,代码来源:mobile_main.py
示例12: post
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('/')
开发者ID:ZachOrr,项目名称:the-blue-alliance,代码行数:14,代码来源:notification_controller.py
示例13: register_client
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,代码行数:16,代码来源:mobile_main.py
示例14: get
def get(self):
webhooks = MobileClient.query(MobileClient.client_type == ClientType.WEBHOOK).fetch()
failures = []
for client in webhooks:
response = TBANSHelper.ping_webhook(client)
if not response.code == 200:
failures.append(client.key)
count = len(failures)
if failures:
ndb.delete_multi(failures)
logging.info("Deleted {} broken webhooks".format(count))
template_values = {'count': count}
path = os.path.join(os.path.dirname(__file__), '../../templates/admin/webhooks_clear_do.html')
self.response.out.write(template.render(path, template_values))
开发者ID:ZachOrr,项目名称:the-blue-alliance,代码行数:17,代码来源:admin_cron_controller.py
示例15: get
def get(self):
webhooks = MobileClient.query(MobileClient.client_type == ClientType.WEBHOOK).fetch()
failures = []
notification = PingNotification()._render_webhook()
for key in webhooks:
if not NotificationSender.send_webhook(notification, [(key.messaging_id, key.secret)]):
failures.append(key.key)
count = len(failures)
if failures:
ndb.delete_multi(failures)
logging.info("Deleted {} broken webhooks".format(count))
template_values = {'count': count}
path = os.path.join(os.path.dirname(__file__), '../../templates/admin/webhooks_clear_do.html')
self.response.out.write(template.render(path, template_values))
开发者ID:MC42,项目名称:the-blue-alliance,代码行数:18,代码来源:admin_cron_controller.py
示例16: post
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('/')
开发者ID:CarlColglazier,项目名称:the-blue-alliance,代码行数:20,代码来源:notification_controller.py
示例17: post
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('/')
开发者ID:CarlColglazier,项目名称:the-blue-alliance,代码行数:20,代码来源:webhook_controller.py
示例18: mobile_clients
def mobile_clients(self):
user_id = self.user.user_id()
return MobileClient.query(ancestor=ndb.Key(Account, user_id)).fetch()
开发者ID:CarlColglazier,项目名称:the-blue-alliance,代码行数:3,代码来源:user_bundle.py
示例19: update_token
def update_token(cls, old, new):
to_update = MobileClient.query(MobileClient.messaging_id == old).fetch()
for model in to_update:
model.messaging_id = new
model.put()
开发者ID:BowlesCR,项目名称:the-blue-alliance,代码行数:5,代码来源:push_helper.py
示例20: delete_bad_gcm_token
def delete_bad_gcm_token(cls, key):
logging.info("removing bad GCM token: "+key)
to_delete = MobileClient.query(MobileClient.messaging_id == key).fetch(keys_only=True)
ndb.delete_multi(to_delete)
开发者ID:dewdn2,项目名称:the-blue-alliance,代码行数:4,代码来源:push_helper.py
注:本文中的models.mobile_client.MobileClient类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论