Ejemplo n.º 1
0
def unsubscribe():
    if request.method == 'POST':
        email = request.form.get('email')
        DBHandler.remove_email(DB_PATH, email)
        return f'unsubscribed {email}. You may now close this page.'
    else:
        return render_template('unsubscribe.html')
Ejemplo n.º 2
0
def verify_email(email, verify_key):
    try:
        person = DBHandler.get_person_by_email_unverified(DB_PATH, email)
        if person[4] == verify_key:
            # Key is correct
            try:
                DBHandler.verify_email(DB_PATH, email)
                return f'{email} verified. You may now close this page.'
            except EmailNotFoundError:
                return 'already verified'
        else:
            # Key is incorrect
            return 'incorrect key'
    except EmailNotFoundError:
        return 'already verified'
Ejemplo n.º 3
0
def add_user():
    if request.method == 'GET':
        # GET request
        return render_template('subscribe.html')
    else:
        # POST request
        first_name = request.form.get('first_name')
        last_name = request.form.get('last_name')
        email = request.form.get('email')
        if '' in (first_name, last_name, email):
            return 'invalid credentials'
        if re.findall(r'[^@]+@[^@]+\.[^@]+', email) == []:
            return "invalid email"
        verify_key = uuid.uuid4().hex
        DBHandler.add_unverified_email(DB_PATH, first_name, last_name, email, verify_key)
        Emailer.send_verification_email(DB_PATH, email)
        return redirect(url_for('home'))
Ejemplo n.º 4
0
def send_verification_email(db_name, email):
    try:
        person = DBHandler.get_person_by_email_unverified(db_name, email)
    except EmailNotFoundError:
        return False

    verification_link = f'https://www.cheneycreations.com/daily-cat/verify/{person[3]}/{person[4]}'
    # verification_link = "http://www.realpython.com"
    subject = f"DailyCat Verification Email"
    html = f"""<html>
          <body>
          <p>Thank you for subscribing to DailyCat!<p>
          <p>To start receiving your daily dose of cute and cuddly cats, you must verify your email. Either click this link, or copy and paste it into your favorite browser:<br/>
          <a href="{verification_link}">{verification_link}</a></p>
          <p>If you did not subscribe to DailyCat, you may ignore this email.</p>
          </body>
          </html>"""

    receiver_email = person[3]
    message = MIMEMultipart("alternative")
    message["From"] = SENDER_EMAIL
    message["Subject"] = subject
    message["To"] = receiver_email

    # Add body to email
    part1 = MIMEText(html, "html")

    message.attach(part1)

    context = ssl.create_default_context()

    s = smtplib.SMTP('cheneycreations.com')
    s.ehlo()
    s.login(SENDER_EMAIL, EMAIL_PASSWORD)
    s.login(SENDER_EMAIL, EMAIL_PASSWORD)
    text = message.as_string()
    s.sendmail(SENDER_EMAIL, receiver_email, text)
    s.quit()
    print(f'sent confirmation email to {receiver_email}')
    return True
Ejemplo n.º 5
0
def home():
    print(DB_PATH)
    all_emails = DBHandler.get_all_emails(DB_PATH)
    return render_template('index.html', all_emails=all_emails)