def execute(self, request, presenter): """ :param request: :param presenter: :return: """ username = request['username'] password = request['password'] response = {'user_created': False, 'username': username, 'errors': {}} is_valid, errors = validation.validate( {'username': username}, self._validation_schema ) if errors: response['errors'] = errors elif context.user_repo.exists(username): LOGGER.info("create_user: user '{}' already exists".format(username)) response['errors'] = {'username': ['That username is taken']} else: user = User(username) user.password_hash = create_password_hash(password) context.user_repo.save(user) response['user_created'] = True presenter.present(response)
def get(self, user_id): docs = [doc for doc in self._data if doc['id'] == user_id] if docs: user = User(docs[0]['id']) user.password_hash = docs[0]['password_hash'] return user return NullUser()
def to_entity(self, doc): user = User(doc['_id']) user.password_hash = doc['password_hash'] return user