Exemplo 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()
Exemplo n.º 2
0
    def read(cls, substance):
        author_id = substance.get("author_id")

        if not author_id:
            raise IllegalRequestError(None)

        author = Author.get_by_id(author_id)
        if not author:
            raise NoDataError(None)
        return author.to_hash()
Exemplo n.º 3
0
    def release_provisional(cls, substance):
        author_id = substance.get("author_id")

        if not author_id:
            raise IllegalRequestError(None)

        author = Author.get_by_id(author_id)
        if not author:
            raise NoDataError(None)
        author.provisional = False
        author.put()
Exemplo n.º 4
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()