def enter_as_user(self, answers): self.session['role'] = constants.USER_ROLE login = str(answers['login']).strip() me = User.load(self.redis, login) if not me: me = User(login, 'admin' if login.endswith('admin') else 'user', self.redis) me.save() if login.endswith('admin'): self.thread = self.chat.listen_events({ '%s:%s' % (constants.EVENT_MESSAGE_CREATED, login): self.handle_message_created, '%s:%s' % (constants.EVENT_INCOMING_MESSAGE, login): self.handle_incoming_message, '%s:%s' % (constants.EVENT_MESSAGE_APPROVED, login): self.handle_message_approve, '%s:%s' % (constants.EVENT_MESSAGE_BLOCKED, login): self.handle_message_block, '%s:*' % constants.EVENT_MESSAGE_CREATED: self.handle_else_message_created, '%s:*' % constants.EVENT_INCOMING_MESSAGE: self.handle_else_incoming_message, '%s:*' % constants.EVENT_MESSAGE_APPROVED: self.handle_else_message_approve, '%s:*' % constants.EVENT_MESSAGE_BLOCKED: self.handle_else_message_block, }) else: self.thread = self.chat.listen_events({ '%s:%s' % (constants.EVENT_MESSAGE_CREATED, login): self.handle_message_created, '%s:%s' % (constants.EVENT_INCOMING_MESSAGE, login): self.handle_incoming_message, '%s:%s' % (constants.EVENT_MESSAGE_APPROVED, login): self.handle_message_approve, '%s:%s' % (constants.EVENT_MESSAGE_BLOCKED, login): self.handle_message_block, }) self.session['me'] = me UserActionsScene(self.session, self.redis).enter()
def enter_as_user(self, answers): self.session["role"] = Role.USER login = str(answers["login"]).strip() me = User.load(self.redis, login) if not me: me = User(login, "admin" if login.endswith("admin") else "user", self.redis) me.save() if login.endswith("admin"): self.thread = self.chat.listen_events( { "%s:%s" % (MessageEvent.CREATED, login): self.handle_message_created, "%s:%s" % (MessageEvent.PENDING, login): self.handle_pending_message, "%s:%s" % (MessageEvent.CONFIRMED, login): self.handle_message_confirm, "%s:%s" % (MessageEvent.BANNED, login): self.handle_message_ban, "%s:*" % MessageEvent.CREATED: self.handle_else_message_created, "%s:*" % MessageEvent.PENDING: self.handle_else_pending_message, "%s:*" % MessageEvent.CONFIRMED: self.handle_else_message_confirm, "%s:*" % MessageEvent.BANNED: self.handle_else_message_ban, } ) else: self.thread = self.chat.listen_events( { "%s:%s" % (MessageEvent.CREATED, login): self.handle_message_created, "%s:%s" % (MessageEvent.PENDING, login): self.handle_pending_message, "%s:%s" % (MessageEvent.CONFIRMED, login): self.handle_message_confirm, "%s:%s" % (MessageEvent.BANNED, login): self.handle_message_ban, } ) self.session["me"] = me UserActionsScene(self.session, self.redis).enter()