Exemplo n.º 1
0
    def create(cls, substance):
        def _validate(substance):
            if not substance:
                return False
            if not substance.get("author_name"):
                return False
            if not substance.get("mail_address"):
                return False
            if not substance.get("password"):
                return False
            return True

        if not _validate(substance):
            raise IllegalRequestError(None)
        if Author.exists_by_mail_address(substance.get("mail_address")):
            raise AlreadyRegisteredError(None)

        author = Author(
            id=Author.make_author_id_hash(),
            author_name=substance.get("author_name"),
            password=Author.make_password_hash(substance.get("password")),
            mail_address=substance.get("mail_address")
        )
        author.put()
        return True
Exemplo n.º 2
0
    def update_password(cls, substance):
        def _validate(substance):
            if not substance:
                return False
            if not substance.get("author_id"):
                return False
            if not substance.get("password"):
                return False
            return True

        author_id = substance.get("author_id")
        password = substance.get("password")

        if not _validate(substance):
            raise IllegalRequestError(None)

        author = Author.get_by_id(author_id)
        if not author:
            raise NoDataError(None)
        author.password = Author.make_password_hash(password)
        author.put()