def func_on(self, args): if len(args): for a in args: if a == 'home': self._google_user.display_timeline |= MODE_HOME elif a == 'mention': self._google_user.display_timeline |= MODE_MENTION elif a == 'dm': self._google_user.display_timeline |= MODE_DM elif a == 'list': self._google_user.display_timeline |= MODE_LIST s = Session.get_by_key_name(self._google_user.jid) if not s and self._google_user.display_timeline and self._google_user.enabled_user and self._google_user.msg_template.strip( ): try: flag = xmpp.get_presence(self._google_user.jid) except (xmpp.Error, DeadlineExceededError): flag = False if flag: Db.set_datastore( Session(key_name=self._google_user.jid, shard=self._google_user.shard)) modes = [] if self._google_user.display_timeline & MODE_LIST: modes.append('list') if self._google_user.display_timeline & MODE_HOME: modes.append('home') if self._google_user.display_timeline & MODE_MENTION: modes.append('mention') if self._google_user.display_timeline & MODE_DM: modes.append('dm') return _('ON_MODE') % ', '.join(modes)
def func_on(self, args): if len(args): for a in args: if a == "home": self._google_user.display_timeline |= MODE_HOME elif a == "mention": self._google_user.display_timeline |= MODE_MENTION elif a == "dm": self._google_user.display_timeline |= MODE_DM elif a == "list": self._google_user.display_timeline |= MODE_LIST s = Session.get_by_key_name(self._google_user.jid) if ( not s and self._google_user.display_timeline and self._google_user.enabled_user and self._google_user.msg_template.strip() ): try: flag = xmpp.get_presence(self._google_user.jid) except (xmpp.Error, DeadlineExceededError): flag = False if flag: Db.set_datastore(Session(key_name=self._google_user.jid, shard=self._google_user.shard)) modes = [] if self._google_user.display_timeline & MODE_LIST: modes.append("list") if self._google_user.display_timeline & MODE_HOME: modes.append("home") if self._google_user.display_timeline & MODE_MENTION: modes.append("mention") if self._google_user.display_timeline & MODE_DM: modes.append("dm") return _("ON_MODE") % ", ".join(modes)
def bind(self, verifier): s = Session.get_by_key_name(self._jid) if s: token = oauth.OAuthToken.from_string(s.data) consumer = oauth.OAuthConsumer(config.OAUTH_CONSUMER_KEY, config.OAUTH_CONSUMER_SECRET) oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, token=token, verifier=verifier, http_url=config.ACCESS_TOKEN_URL) signature_method_hmac_sha1 = oauth.OAuthSignatureMethod_HMAC_SHA1() oauth_request.sign_request(signature_method_hmac_sha1, consumer, token) try: result = urlfetch.fetch(oauth_request.to_url(), method=oauth_request.http_method) except urlfetch.Error: return 'Network Error!' try: token = oauth.OAuthToken.from_string(result.content) except BaseException: return 'Wrong verifier!' u = User.get_by_key_name(self._jid) if u: u.access_key = token.key u.access_secret = token.secret u.put() else: User(key_name=self._jid, access_key=token.key, access_secret=token.secret).put() s.data = None s.put() return 'Successfully bind your account.'
def oauth(self, mobile=None): consumer = oauth.OAuthConsumer(config.OAUTH_CONSUMER_KEY, config.OAUTH_CONSUMER_SECRET) params = {'xoauth_displayname': 'Gmail2GTalk', 'scope': config.RESOURCE_URL} oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, callback='oob', parameters=params, http_url=config.REQUEST_TOKEN_URL) signature_method_hmac_sha1 = oauth.OAuthSignatureMethod_HMAC_SHA1() oauth_request.sign_request(signature_method_hmac_sha1, consumer, None) try: result = urlfetch.fetch(oauth_request.to_url(), method=oauth_request.http_method) except urlfetch.Error: return 'Network Error!' token = oauth.OAuthToken.from_string(result.content) s = Session.get_by_key_name(self._jid) if not s: Session(key_name=self._jid, data=result.content).put() else: s.data = result.content s.put() if mobile == 'mobile': params = {'btmpl': 'mobile'} else: params = None oauth_request = oauth.OAuthRequest.from_token_and_callback(token, http_url=config.AUTHORIZATION_URL, parameters=params) url = oauth_request.to_url() return 'Please visit following url to authorize:\n%s' % url
def pause(self): u = User.get_by_key_name(self._jid) if u: u.enabled = False u.put() s = Session.get_by_key_name(self._jid) if s: s.delete() return 'Gmail notification is paused.'
def remove(self): u = User.get_by_key_name(self._jid) if u: u.access_key = None u.access_secret = None u.enabled = False u.put() s = Session.get_by_key_name(self._jid) if s: s.delete() return 'Successfully remove your account.'
def post(self): jid = self.request.get("from").split("/")[0] s = Session.get_by_key_name(jid) if not s: u = GoogleUser.get_by_jid(jid) if u and u.enabled_user and u.display_timeline and u.msg_template.strip(): try: Db.set_datastore(Session(key_name=jid, shard=u.shard)) except CapabilityDisabledError: try: xmpp.send_presence(jid, presence_type=xmpp.PRESENCE_SHOW_AWAY) except xmpp.Error: pass
def post(self): jid = self.request.get('from').split('/')[0] s = Session.get_by_key_name(jid) if s: u = GoogleUser.get_by_jid(jid) if u: try: flag = xmpp.get_presence(jid) except xmpp.Error: flag = False if not flag: s.delete() else: s.delete()
def post(self): jid = self.request.get("from").split("/")[0] s = Session.get_by_key_name(jid) if s: u = GoogleUser.get_by_jid(jid) if u: try: flag = xmpp.get_presence(jid) except xmpp.Error: flag = False if not flag: s.delete() else: s.delete()
def post(self): jid = self.request.get('from').split('/')[0] s = Session.get_by_key_name(jid) if s: u = User.get_by_key_name(jid) if u: try: presence = xmpp.get_presence(jid) except xmpp.Error: presence = False if not presence: s.delete() else: s.delete()
def post(self): jid = self.request.get('from').split('/')[0] s = Session.get_by_key_name(jid) if not s: u = GoogleUser.get_by_jid(jid) if u and u.enabled_user and u.display_timeline and u.msg_template.strip( ): try: Db.set_datastore(Session(key_name=jid, shard=u.shard)) except CapabilityDisabledError: try: xmpp.send_presence( jid, presence_type=xmpp.PRESENCE_SHOW_AWAY) except xmpp.Error: pass
def func_msgtpl(self, args): if len(args): tpl = " ".join(args) while tpl[-2::] == r"\n": tpl = tpl[: len(tpl) - 2] + "\n" self._google_user.msg_template = tpl s = Session.get_by_key_name(self._google_user.jid) if not s and tpl.strip() and self._google_user.display_timeline and self._google_user.enabled_user: try: flag = xmpp.get_presence(self._google_user.jid) except (xmpp.Error, DeadlineExceededError): flag = False if flag: Db.set_datastore(Session(key_name=self._google_user.jid, shard=self._google_user.shard)) return _("MSG_TEMPLATE") % self._google_user.msg_template
def func_msgtpl(self, args): if len(args): tpl = ' '.join(args) while tpl[-2::] == r'\n': tpl = tpl[:len(tpl) - 2] + '\n' self._google_user.msg_template = tpl s = Session.get_by_key_name(self._google_user.jid) if not s and tpl.strip( ) and self._google_user.display_timeline and self._google_user.enabled_user: try: flag = xmpp.get_presence(self._google_user.jid) except (xmpp.Error, DeadlineExceededError): flag = False if flag: Db.set_datastore( Session(key_name=self._google_user.jid, shard=self._google_user.shard)) return _('MSG_TEMPLATE') % self._google_user.msg_template