예제 #1
0
def resend_verification(email=None):
    conn_mgr = BRConnection()
    users = conn_mgr.users

    user = users.find_one({'email': email})

    if email is None:
        abort(404)

    if user is None:
        abort(404)

    content = '''
      <h1>Account verification</h1>
      <p>In order to use your Bukkit Repo account, you need to verify your email address. The good news is that it's easy. Just click the link below!</p>
      http://bukkitrepo.me/account/verification/verify/{0}
    '''.format(user['verification_key'])

    subject = 'Verify your bukkitrepo account'
    from_email = '*****@*****.**'
    from_name = 'Bukkit Repo Staff'
    to_email = email
    to_name = user['name']

    email = Message(subject, content, from_email, from_name, to_email, to_name)

    if not user['verified']:
        email.send()
        return render_template('page.html', page_content='<h3>Resend Verification</h3><p>I\'ve sent another verification email to {0}.</p>'.format(email))
    else:
        return render_template('page.html', page_content='<h3>Resend Verification</h3><p>Your email address is already verified, silly!</p>')
예제 #2
0
def forgot():
    if '_id' in session:
        return redirect_to_home()

    if request.method == "POST":
        conn_mgr = BRConnection()
        reset_keys = conn_mgr.reset_keys

        email = request.form['email']
        errors = []

        if not email:
            errors.append('Please enter an email address!')

        user = get_user(get_id(email))
        if not user:
            errors.append('The email address you entered did not match any accounts.')

        if errors:
            return render_template('forgot.html', errors=errors)

        key = ''.join(random.choice(string.ascii_lowercase + string.digits) for i in range(32))
        reset_key = ResetKey(user['_id'], key)

        reset_keys.insert(reset_key.data)

        content = '''
        <h1>Reset password</h1>
        <p>Bukkit Repo has recieved a request to reset the password of the Bukkit Repo account under this email address. If you did not make this request, you can disregard this email. To reset your password, please click the link below.</p>
        http://bukkitrepo.me/account/forgot/reset/{0}
        '''.format(key)

        subject = 'Reset your bukkitrepo password'
        from_email = '*****@*****.**'
        from_name = 'Bukkit Repo Staff'
        to_email = user['email']
        to_name = user['name']

        email = Message(subject, content, from_email, from_name, to_email, to_name)

        email.send()

        return render_template('page.html', page_content='A link that can be used to reset the password for this account has been sent to your email address.')
    else:
        return render_template('forgot.html')