Esempio n. 1
0
    def update(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
            return True

        author_id = substance.get("author_id")
        author_name = substance.get("author_name")
        mail_address = substance.get("mail_address")
        valid = substance.get("valid")

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

        author = Author.get_by_id(author_id)
        if not author:
            raise NoDataError(None)
        if author.mail_address != mail_address:
            if Author.exists_by_mail_address(substance.get("mail_address")):
                raise AlreadyRegisteredError(None)

        author.author_name = author_name
        author.mail_address = mail_address
        author.valid = valid
        author.put()
Esempio n. 2
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