def promote_user(self, from_jid, nick): ji_ref = api.actor_lookup_im(api.ROOT, from_jid.base()) if jid_ref: # TODO(tyler): Should we tell the user who they are? raise exception.ValidationError( "You already have an account and are signed in.") if not NICK_RE.match(nick): raise exception.ValidationError( "Invalid screen name, can only use letters or numbers, 3 to 16 " "characters") # Create the user. (user_create will check to see if the account has # already been created.) password = util.generate_uuid()[:8] # TODO(termie): Must have a first/last name. :( actor = api.user_create(api.ROOT, nick=nick, password=password, given_name=nick, family_name=nick) # link this im account to the user's account (equivalent of SIGN IN) self.sign_in(from_jid, nick, password) # Inform the user of their new password welcome = '\n'.join([HELP_WELCOME_NICK % nick, HELP_PASSWORD % password, HELP_POST, HELP_CHANNEL_POST, HELP_COMMENT, HELP_FOLLOW, HELP_STOP, HELP_MORE, HELP_FOOTER]) self.send_message([from_jid], welcome)
def promote_user(self, from_jid, nick): ji_ref = api.actor_lookup_im(api.ROOT, from_jid.base()) if jid_ref: # TODO(tyler): Should we tell the user who they are? raise exception.ValidationError( "You already have an account and are signed in.") if not NICK_RE.match(nick): raise exception.ValidationError( "Invalid screen name, can only use letters or numbers, 3 to 16 " "characters") # Create the user. (user_create will check to see if the account has # already been created.) password = util.generate_uuid()[:8] # TODO(termie): Must have a first/last name. :( actor = api.user_create(api.ROOT, nick=nick, password=password, given_name=nick, family_name=nick) # link this im account to the user's account (equivalent of SIGN IN) self.sign_in(from_jid, nick, password) # Inform the user of their new password welcome = '\n'.join([ HELP_WELCOME_NICK % nick, HELP_PASSWORD % password, HELP_POST, HELP_CHANNEL_POST, HELP_COMMENT, HELP_FOLLOW, HELP_STOP, HELP_MORE, HELP_FOOTER ]) self.send_message([from_jid], welcome)
def stop_notifications(self, from_jid): jid_ref = api.actor_lookup_im(api.ROOT, from_jid.base()) if not jid_ref: raise exception.ValidationError("You are not signed in.") actor_ref = api.settings_change_notify(api.ROOT, jid_ref.nick, im=False) self.send_message([from_jid], HELP_STOP_NOTIFICATIONS)
def start_notifications(self, from_jid): jid_ref = api.actor_lookup_im(api.ROOT, from_jid.base()) if not jid_ref: raise exception.ValidationError("You are not signed in.") actor_ref = api.settings_change_notify(api.ROOT, jid_ref.nick, im=True) self.send_message([from_jid], HELP_START_NOTIFICATIONS)
def sign_out(self, from_jid): jid_ref = api.actor_lookup_im(api.ROOT, from_jid.base()) if not jid_ref: raise exception.ValidationError("You are not signed in.") im_ref = api.im_disassociate(api.ROOT, jid_ref.nick, from_jid.base()) self.send_message([from_jid], "signed out")
def channel_post(self, from_jid, channel_nick, message): jid_ref = api.actor_lookup_im(api.ROOT, from_jid.base()) if not jid_ref: raise exception.ValidationError( "You must be signed in to post, please SIGN IN") comment_ref = api.channel_post(jid_ref, message=message, nick=jid_ref.nick, channel=channel_nick)
def channel_post(self, from_jid, channel_nick, message): jid_ref = api.actor_lookup_im(api.ROOT, from_jid.base()) if not jid_ref: raise exception.ValidationError( "You must be signed in to post, please SIGN IN") comment_ref = api.channel_post( jid_ref, message=message, nick=jid_ref.nick, channel=channel_nick )
def actor_remove_contact(self, from_jid, nick): jid_ref = api.actor_lookup_im(api.ROOT, from_jid.base()) if not jid_ref: raise exception.ValidationError( "You must be signed in to post, please SIGN IN") nick = clean.nick(nick) try: api.actor_remove_contact(jid_ref, jid_ref.nick, nick) self.send_message((from_jid, ), "%s stopped following %s" % (jid_ref.nick, nick)) except: self.send_message((from_jid, ), "Leave FAILED: %s" % nick)
def channel_join(self, from_jid, nick): jid_ref = api.actor_lookup_im(api.ROOT, from_jid.base()) if not jid_ref: raise exception.ValidationError( "You must be signed in to join a channel, please SIGN IN") channel = clean.channel(nick) try: api.channel_join(jid_ref, jid_ref.nick, channel) self.send_message((from_jid, ), "%s joined %s" % (jid_ref.nick, channel)) except: self.send_message((from_jid, ), "Join FAILED: %s" % channel)
def actor_remove_contact(self, from_jid, nick): jid_ref = api.actor_lookup_im(api.ROOT, from_jid.base()) if not jid_ref: raise exception.ValidationError( "You must be signed in to post, please SIGN IN") nick = clean.nick(nick) try: api.actor_remove_contact(jid_ref, jid_ref.nick, nick) self.send_message((from_jid,), "%s stopped following %s" % (jid_ref.nick, nick)) except: self.send_message((from_jid,), "Leave FAILED: %s" % nick)
def channel_join(self, from_jid, nick): jid_ref = api.actor_lookup_im(api.ROOT, from_jid.base()) if not jid_ref: raise exception.ValidationError( "You must be signed in to join a channel, please SIGN IN") channel = clean.channel(nick) try: api.channel_join(jid_ref, jid_ref.nick, channel) self.send_message((from_jid,), "%s joined %s" % (jid_ref.nick, channel)) except: self.send_message((from_jid,), "Join FAILED: %s" % channel)
def sign_in(self, from_jid): jid_ref = api.actor_lookup_im(api.ROOT, from_jid.base()) if jid_ref: raise exception.ValidationError( "You are already signed in, please SIGN OUT first") user_ref = api.actor_lookup_email(api.ROOT, from_jid.base()) im_ref = api.im_associate(api.ROOT, user_ref.nick, from_jid.base()) welcome = '\n'.join([HELP_WELCOME_NICK % user_ref.display_nick(), HELP_POST, HELP_CHANNEL_POST, HELP_COMMENT, HELP_FOLLOW, HELP_STOP, HELP_MORE, HELP_FOOTER]) self.send_message([from_jid], welcome)
def sign_in(self, from_jid, nick, password): jid_ref = api.actor_lookup_im(api.ROOT, from_jid.base()) if jid_ref: raise exception.ValidationError( "You are already signed in, please SIGN OUT first") user_ref = user.authenticate_user_login(nick, password) if not user_ref: raise exception.ValidationError( "Username or password is incorrect") im_ref = api.im_associate(api.ROOT, user_ref.nick, from_jid.base()) welcome = '\n'.join([ HELP_WELCOME_NICK % user_ref.display_nick(), HELP_POST, HELP_CHANNEL_POST, HELP_COMMENT, HELP_FOLLOW, HELP_STOP, HELP_MORE, HELP_FOOTER ]) self.send_message([from_jid], welcome)
def add_comment(self, from_jid, nick, message): jid_ref = api.actor_lookup_im(api.ROOT, from_jid.base()) if not jid_ref: raise exception.ValidationError( "You must be signed in to post, please SIGN IN") logging.debug("comment: %s %s %s", nick, jid_ref.nick, message) nick = clean.nick(nick) stream_entry = api.reply_get_cache(sender=nick, target=jid_ref.nick, service='im') if not stream_entry: # Well, or memcache timed it out... Or we crashed... Or... Or... raise exception.ValidationError( 'The message to which you tried to respond doesn\'t exist') api.entry_add_comment(jid_ref, entry=stream_entry.keyname(), content=message, nick=jid_ref.nick, stream=stream_entry.stream)
def post(self, from_jid, message): jid_ref = api.actor_lookup_im(api.ROOT, from_jid.base()) if not jid_ref: raise exception.ValidationError( "You must be signed in to post, please SIGN IN") entry_ref = api.post(jid_ref, nick=jid_ref.nick, message=message)