def post(self): user_jid = self.request.body template_variables = [] path= os.path.join(os.path.dirname(__file__), 'templates/send_invite.html') if user_jid is None or user_jid == '': template_variables = {'success_code':'need to provide jid'} self.response.out.write(template.render(path,template_variables)) return logging.info('sending invite to: %s' % user_jid ) msg = "Welcome to [email protected]. You can track domains that are of your interest. \n\nFor more info type:\n/help" #TODO what about other protocols ? im = db.IM('xmpp',user_jid) xmpp.send_invite(user_jid) status_code = xmpp.send_message(im.address, msg) if status_code == xmpp.INVALID_JID or status_code == xmpp.OTHER_ERROR: template_variables = {'success_code':'error occured while sending xmpp message'} self.response.out.write(template.render(path,template_variables)) return chat_send = ( status_code != xmpp.NO_ERROR) if not chat_send: mail.send_mail(sender="Instapaper Firefox Addon<*****@*****.**>",to=user_jid,subject="Instaright over XMPP", body=msg) logging.info('mail has been sent instead of welcome message') logging.info('----%s----' % status_code) invite = IMInvite() invite.im=user_jid invite.subscribed = False invite.put() template_variables = {'success_code':'success'} self.response.out.write(template.render(path,template_variables))
def subscribe_command(self, message=None): subscriber_mail = self.user_mail(message.sender) logging.info('subscribing user: %s' % subscriber_mail) im_from = db.IM('xmpp', message.sender) domain = RequestUtils.getDomain(message.arg) if message.arg == 'all': domain = 'all' if not domain: message.reply('You must provide valide domain for subscription. \'%s\' is not valid domain. Make sure that domain starts with http://' %message.arg) return existingSubscription = Subscription.gql('WHERE subscriber_mail = :1 and domain = :2 and active = True', subscriber_mail, domain).get() if existingSubscription is not None: message.reply('You have already subscribed for this domain %s. Remember?' % domain) return subscription = Subscription(subscriber = im_from, subscriber_mail = subscriber_mail, domain = domain, activationDate = datetime.datetime.now(), active = True, mute = False) invite = IMInvite.gql('WHERE jid = :1 ', subscriber_mail) subscription.put() if invite: invite.subscribed = True invite.put() message.reply('Subscription added.')