Пример #1
0
def resend_confirmation():
    form = SendConfirmEmailForm(request.form)
    if request.method == "POST":
        user_email = form.data['email']
        user = User.query.filter_by(email=user_email).first()
        if user:
            if not user.email_confirmed:
                ts = URLSafeTimedSerializer(current_app.config["SECRET_KEY"])
                user_confirmation_token = ts.dumps(user_email,
                                                   salt="confirm-email")
                # Have Flask generate an external link
                confirm_url = url_for('users.confirm_email',
                                      token=user_confirmation_token,
                                      _external=True)
                html = render_template('users/mail/confirm_email.html',
                                       confirm_url=confirm_url,
                                       user=user)
                send_email("Please confirm your email",
                           recipients=[user_email],
                           html=html)
                flash('Successfully resent account confirmation email.')
                return redirect(url_for('users.login'))
            else:
                flash('Email already confirmed.')
        else:
            flash('This email is not associated with an account.')
    return render_template('users/resend_confirmation.html', form=form)
Пример #2
0
def register():
    form = UserForm(request.form)
    if request.method == "POST" and form.validate():
        try:
            new_user = User(full_name=form.data['full_name'],
                            preferred_name=form.data['preferred_name'],
                            email=form.data['email'],
                            password=form.data['password'])
            db.session.add(new_user)
            db.session.commit()
            # Log user in after registration
            login_user(new_user)
            # Confirm user email
            user_email = form.data['email']
            ts = URLSafeTimedSerializer(current_app.config["SECRET_KEY"])
            user_confirmation_token = ts.dumps(user_email,
                                               salt="confirm-email")
            # Have Flask generate an external link
            confirm_url = url_for('users.confirm_email',
                                  token=user_confirmation_token,
                                  _external=True)
            html = render_template('users/mail/confirm_email.html',
                                   confirm_url=confirm_url,
                                   user=new_user)
            send_email("Please confirm your email",
                       recipients=[user_email],
                       html=html)
        except IntegrityError as e:
            flash("Email address already in use.")
            return render_template('users/register.html', form=form)
        flash('Successfully created account.')
        return redirect(url_for('main.dashboard'))
    return render_template('users/register.html', form=form)
Пример #3
0
def send_password_reset_email(user):
    token = user.get_reset_password_token()
    send_email('Reset Your Password',
               sender=current_app.config['ADMINS'][0],
               recipients=[user.email],
               text_body=render_template('email/reset_password.txt',
                                         user=user,
                                         token=token),
               html_body=render_template('email/reset_password.html',
                                         user=user,
                                         token=token))
Пример #4
0
def reset_password():
    form = SendResetEmailForm(request.form)
    if request.method == "POST":
        user_email = form.data['email']
        user = User.query.filter_by(email=user_email).first()
        if user:
            ts = URLSafeTimedSerializer(current_app.config["SECRET_KEY"])
            user_reset_token = ts.dumps(user_email, salt="reset-password")
            # Have Flask generate an external link
            confirm_url = url_for('users.reset_password_token',
                                  token=user_reset_token,
                                  _external=True)
            html = render_template('users/mail/reset_password.html',
                                   confirm_url=confirm_url,
                                   user=user)
            send_email("Password reset request",
                       recipients=[user_email],
                       html=html)
            flash('Successfully sent password reset email.')
            return redirect(url_for('users.login'))
        else:
            flash('This email is not associated with an account.')
    return render_template('users/reset_password.html', form=form)
Пример #5
0
def resend(uid):
    actuser = RegisteredUser.quer.filter(RegisteredUser.id == uid).first()
    if actuser is None:
        flash("No such user.")
        return redirect('/')
    mail = """From: [email protected]\r\nTo: %s\r\nSubject: CSH 5K Email Confirmation\r\n\r\nWelcome to the CSH 5K for charity: water!

To confirm your email address, please click here:
http://5k.csh.rit.edu/verify?key=%s&user=%s""" % (actuser.email, actuser.reg_uuid, urllib.quote(actuser.email))
    if send_email(actuser.email, mail):
        flash("Email successfully resent.")
    else:
        flash("Something went wrong sending your email. Please contact [email protected].")
    return redirect('/')
Пример #6
0
def resend(uid):
    actuser = RegisteredUser.quer.filter(RegisteredUser.id == uid).first()
    if actuser is None:
        flash("No such user.")
        return redirect('/')
    mail = """From: [email protected]\r\nTo: %s\r\nSubject: CSH 5K Email Confirmation\r\n\r\nWelcome to the CSH 5K for charity: water!

To confirm your email address, please click here:
http://5k.csh.rit.edu/verify?key=%s&user=%s""" % (
        actuser.email, actuser.reg_uuid, urllib.quote(actuser.email))
    if send_email(actuser.email, mail):
        flash("Email successfully resent.")
    else:
        flash(
            "Something went wrong sending your email. Please contact [email protected]."
        )
    return redirect('/')