def post(self, key): self.constructor(key, login_arguments, metric=self.METRICS['post']) user = yield GoogleUser.load(key) user_to_logout = None pushtoken = self.args['_pushtoken'] if user is None: if pushtoken: user_to_logout = yield GoogleUser.load(pushtoken=pushtoken) elif user.connected: if user.jid != self.args['_jid']: user_to_logout = user if not user_to_logout is None: if user is None: self.log.info('WEB_HANDLER_LOGOUT %s with the same pushtoken', user_to_logout.userid) else: self.log.info('WEB_HANDLER_LOGOUT %s with other jid: %s->%s', key, user.jid, self.args['_jid']) if user_to_logout.connected: yield API(key, queue=user_to_logout.worker, synchronous_call=True).logout(user_to_logout.userid) else: yield GoogleUser.remove(user_to_logout.userid) user = None try: response_data = {'success': False, 'reason': 'Already logged'} if user is None or not user.connected: if user and not user.connected: yield GoogleUser.remove(user.userid, flush_messages=False) user = GoogleUser(_userid=key, _version=self.user_agent.version, _iosversion=self.user_agent.iosVersion, _hwmodel=self.user_agent.hwmodel, **self.args) yield API(key).login(user) response_data = {'success': True, 'reason': 'ok'} except XMPPUserAlreadyLogged: pass if self.FAKE_PURCHASE_ENABLED: self.perform_fakepurchase(userid=user.jid, deviceid=user.userid) response_data.update( dict(background_time=conf.XMPP_BACKGROUND_TIME, resource_prefix=conf.XMPP_RESOURCE, gtalk_priority=conf.XMPP_GTALK_PRIORITY, ads_gift=self.FAKE_PURCHASE_ENABLED)) self._response_json(response_data)
def delete(self, key): self.constructor(key, metric=self.METRICS['delete']) user = yield GoogleUser.load(key) if user is None: raise cyclone.web.HTTPError(404) if user.connected: yield API(key, queue=user.worker).logout(key) else: yield user.remove(user.userid) self._response_json({'success': True, 'reason': 'ok'})
def get(self, key): self.constructor(key, metric=self.METRICS['get']) user = yield GoogleUser.load(key) if user is None or not user.connected: raise cyclone.web.HTTPError(404) response_data = { 'success': True, 'reason': 'ok', 'resource_connected': not user.away } self._response_json(response_data)
def put(self, key): self.constructor(key, contact_arguments, metric=self.METRICS['put']) user = yield GoogleUser.load(key) if user is None or not user.connected: raise cyclone.web.HTTPError(404) jid = self.args.pop('jid') try: yield API(key, queue=user.worker).update_contact( user.userid, jid, **self.args) except XMPPUserNotLogged as e: raise cyclone.web.HTTPError(500, str(e)) self._response_json({'success': True, 'reason': 'ok'})
def get(self, key): self.constructor(key, metric=self.METRICS['get']) user = yield GoogleUser.load(key) if user is None: raise cyclone.web.HTTPError(404) messages = yield GoogleMessage.getMessages(key) self._response_json({ 'current_time': Timer().isoformat(), 'success': True, 'messages': messages, 'len': len(messages), 'reason': 'ok', 'connected': user.connected })
def delete(self, key): self.constructor(key, metric=self.METRICS['delete']) user = yield GoogleUser.load(key) if user is None: raise cyclone.web.HTTPError(404) #Remove messages from database (pending to implement) #update badgenumber try: yield GoogleMessage.flushMessages(key) if user.connected: yield API(key, queue=user.worker).update(key, **{'badgenumber': 0}) self._response_json({'success': True, 'reason': 'ok'}) except XMPPUserNotLogged as e: raise cyclone.web.HTTPError(500, str(e))
def put(self, key): self.constructor(key, update_arguments, metric=self.METRICS['put']) user = yield GoogleUser.load(key) if user is None or not user.connected: raise cyclone.web.HTTPError(404) try: yield API(key, queue=user.worker).update( key, _version=self.user_agent.version, _iosversion=self.user_agent.iosVersion, _hwmodel=self.user_agent.hwmodel, **self.args) self._response_json({ 'success': True, 'reason': 'ok', 'background_time': conf.XMPP_BACKGROUND_TIME, 'resource_prefix': conf.XMPP_RESOURCE, 'gtalk_priority': conf.XMPP_GTALK_PRIORITY, 'ads_gift': self.FAKE_PURCHASE_ENABLED }) except XMPPUserNotLogged as e: raise cyclone.web.HTTPError(500, str(e))