def _perform(self): session = self._app.db.session() user = self.get_user() if user is None: return BusinessResponse.response_unauthorized({"message": "You are not logged in"}) contacts = session.query(Contact).filter_by(owner_id=user.id).all() return BusinessResponse.response_ok(contacts)
def _perform(self, username, password): session = self._app.db.session() user = session.query(User).filter_by(username=username).first() if user is None: new_user = User(username=username) new_user.set_password(password) session.add(new_user) return BusinessResponse.response_ok({}) else: return BusinessResponse.response_invalid_data({'message': 'User with this name already exists'})
def _perform(self, username, password): session = self._app.db.session() user = session.query(User).filter_by(username=username).first() if user is not None and user.check_password(password): _id = uuid4().get_hex() user_session = Session(sid=_id, user=user, data="{}", expire=None) session.add(user_session) return BusinessResponse.response_ok({'sid': _id}) else: return BusinessResponse.response_invalid_data({'message': 'invalid username or password'})
def _perform(self, **kwargs): session = self._app.db.session() user = self.get_user() if user is None: return BusinessResponse.response_unauthorized({"message": "You are not logged in"}) contact_name = kwargs["username"] account = self._app.component_registry["account"] contact_user = account.user_from_name(contact_name) if contact_user is None: return BusinessResponse.response_not_found({"message": "Contact not found"}) contact = Contact(user_id=user.id, contact_id=contact_user.id) session.add(contact) return BusinessResponse.response_ok([contact])
def do_call(self, message): action = message.get_action().lower() if action not in self.ACTIONS: return BusinessResponse.response_invalid_action(action) method_factory = self._actions[action] return method_factory(message)