def miner_register(config, wallet_address, email, pass_code): wallet_address = utils.valid_addr(wallet_address) assert wallet_address, "invalid wallet address" email = utils.valid_email(email) assert email, "invalid email" # 0. verify pass code success, msg = tools.verify_token(pass_code, action="verify_pass_code", email=email) if not success: raise Exception(msg) exist = miner.Miner.get(wallet_address=wallet_address) assert not exist, "wallet address exists already" new_miner = miner.Miner.get_or_create( wallet_address, "default_worker", email=email, ) if not new_miner.email_verified: ext_data = { "miner_address": new_miner.wallet_address, } # send verification mail to user tools.send_email_verification(config, email, "miner", ext_data=ext_data) return new_miner
def miner_register(config, wallet_address, email, nick_name=""): wallet_address = utils.valid_addr(wallet_address) assert wallet_address, "invalid wallet address" email = utils.valid_email(email) assert email, "invalid email" exist = miner.Miner.get(wallet_address=wallet_address) assert not exist, "wallet address exists already" new_miner = miner.Miner.get_or_create( wallet_address, "default_worker", nick_name=nick_name, email=email, ) if not new_miner.email_verified: ext_data = { "miner_address": new_miner.wallet_address, } # send verification mail to user tools.send_email_verification(config, email, "miner", ext_data=ext_data) return new_miner
def node_register(config, pub_key: str, email: str, pass_code: str): email = utils.valid_email(email) assert email, "invalid email" pub_keys = [key for key in pub_key.split(",")] for i in range(len(pub_keys)): key = pub_keys[i] valid_key = utils.valid_pub_key(key) if not valid_key: raise Exception(f"invalid public key {key}") pub_keys[i] = valid_key if not pub_keys: raise Exception("no public key") # 0. verify pass code success, msg = tools.verify_token(pass_code, action="verify_pass_code", email=email) if not success: raise Exception(msg) # 1. get or create node owner owner = zilnode.ZilNodeOwner.get_one(email=email) if not owner: owner = zilnode.ZilNodeOwner.create(email=email) if not owner: raise Exception("failed to create node owner") if not owner.email_verified: # 1.1 send verification mail to user tools.send_email_verification(config, email, "owner") # 2. register public keys for key in pub_keys: exist = zilnode.ZilNode.get_by_pub_key(key, authorized=None) if exist: raise Exception(f"public key exists already, {key}") for key in pub_keys: owner.register_node(key) # 3. send auth required mail to admin tools.send_approve_require_email(config, email, pub_keys) return True