def authorize_nodes(self, authorized=True):
        from .zilnode import ZilNode
        from zilpool.web.tools import send_auth_notification_email

        user_email = self.ext_data.get("email", "")
        pub_keys = self.ext_data["pub_keys"]
        if not pub_keys:
            raise Exception("no public keys to approve")

        messages = [f"Node Registers from {user_email}"]

        for key in pub_keys:
            node = ZilNode.get_by_pub_key(key, authorized=None)
            if not node:
                messages.append(f"{key}, not found ")
                continue
            if not node.update(authorized=authorized):
                messages.append(f"{key}, database error")
                continue
            res = "approved" if node.authorized else "rejected"
            messages.append(f"{key}, {res}")

        self.set_token_done()
        messages = "\n".join(messages)

        send_auth_notification_email(user_email, messages)

        return True, messages
示例#2
0
def admin_auth_node(pub_key, approve):
    from zilpool.web import tools

    node = ZilNode.get_by_pub_key(pub_key, authorized=None)
    assert node, "Node not found"

    if approve != node.authorized:
        node = node.update(authorized=approve)
        assert node, "failed to update database"

        action = "Approved" if approve else "Revoked"
        messages = f"Node Register {action}: {node.pub_key}"

        logging.info(messages)

        if node.email:
            tools.send_auth_notification_email(node.email, messages=messages)

    return node