Beispiel #1
0
def send_email_verification(config, user_email, rule, ext_data=None):
    subject = "Verify your email address"
    site_title = config["pool"]["title"]

    action = f"verify_{rule}_email"
    expire_secs = 24 * 3600
    if ext_data is None:
        ext_data = {}
    ext_data.update({"email": user_email})

    token = ziladmin.ZilAdminToken.create_token(action,
                                                ext_data=ext_data,
                                                expire_secs=expire_secs)
    if not token:
        logging.warning(f"failed to create {action} token")
        return False

    email_verify_link = verify_url_for(config, action, token)

    body = f"Thanks for joining {site_title}, " \
           f"please verify your email address {user_email}" \
           f" by clicking\n{email_verify_link}"

    EmailClient.send_admin_mail(to_addrs=user_email, subject=subject, msg=body)
    return True
Beispiel #2
0
def init_admin(config):
    from . import ziladmin
    from zilpool.pyzil import crypto
    from zilpool.common.mail import EmailClient

    EmailClient.set_config(config)

    admin_emails = config["pool"]["admins"]

    for email in admin_emails:
        admin = ziladmin.ZilAdmin.get_one(email=email)

        if not admin:
            logging.critical("init admin database")
            password = crypto.rand_string(8)
            admin = ziladmin.ZilAdmin.create(email, password)
            if not admin:
                raise RuntimeError("Failed to create admin database")
            print(f"generate admin password: {password}")
            print(f"send mail to {email}")

            EmailClient.send_admin_mail(
                email,
                subject="password generated",
                msg=f"admin email: {email}\npassword: {password}")
def send_pass_code(config, user_email, pass_code):
    site_title = config["pool"]["title"]
    subject = f"Pass Code on {site_title}"
    messages = f"Your pass code is: {pass_code}.\n" \
               f"It will be expired in 30 minutes."
    EmailClient.send_admin_mail(
        to_addrs=user_email, subject=subject, msg=messages
    )
Beispiel #4
0
def send_approve_require_email(config, user_email, pub_keys):
    if not pub_keys:
        logging.warning(f"no public key to approve")
        return False

    owner = zilnode.ZilNodeOwner.get_one(email=user_email)
    if not owner:
        logging.warning(f"{user_email} not exists")
        return False

    subject = "Node Register Request"
    admin_emails = config["pool"]["admins"]
    site_title = config["pool"]["title"]

    approve_action = "approve_nodes"
    reject_action = "reject_nodes"
    expire_secs = 48 * 3600
    ext_data = {
        "email": user_email,
        "pub_keys": pub_keys,
    }

    # create temp token for admin
    approve_token = ziladmin.ZilAdminToken.create_token(
        approve_action, ext_data=ext_data, expire_secs=expire_secs)
    if not approve_token:
        logging.warning(f"failed to create {approve_action} token")
        return False
    approve_link = verify_url_for(config, approve_action, approve_token)

    reject_token = ziladmin.ZilAdminToken.create_token(reject_action,
                                                       ext_data=ext_data,
                                                       expire_secs=expire_secs)
    if not approve_token:
        logging.warning(f"failed to create {reject_action} token")
        return False
    reject_link = verify_url_for(config, reject_action, reject_token)

    body = f"{user_email} requests {len(pub_keys)} " \
           f"Nodes to join {site_title}." \
           f"\n\nApprove by clicking\n{approve_link}" \
           f"\n\nReject by clicking\n{reject_link}" \
           f"\n\nNodes Public Keys:\n"

    body += "\n".join(pub_keys)

    EmailClient.send_admin_mail(to_addrs=admin_emails,
                                subject=subject,
                                msg=body)
    return True
    async def admin_generate_password(request, email: str):
        admin = ZilAdmin.get_one(email=email)
        if not admin:
            return False

        password = crypto.rand_string(8)
        if not admin.change_password(password=password):
            return False

        logging.critical(f"Re-generate admin password for {admin.email}: {password}")
        logging.critical(f"send mail to {admin.email}")

        EmailClient.set_config(config)
        EmailClient.send_admin_mail(
            admin.email,
            subject="password generated",
            msg=f"admin email: {admin.email}\npassword: {password}"
        )

        return True
Beispiel #6
0
def send_auth_notification_email(user_email, messages):
    subject = "Zilliqa Nodes Register Notification"
    EmailClient.send_admin_mail(to_addrs=user_email,
                                subject=subject,
                                msg=messages)