Exemplo n.º 1
0
def forgotten_password():
    """
    Method to verify email and send password reset link to email
    """
    form = ForgotPasswordForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=request.form['email']).first()
        token = user.encode_auth_token()
        password_reset_url = \
            "http://*****:*****@andela.com",
                  [form.email.data], email_body)

        response = jsonify({'MSG': 'Password Reset Email sucessfully sent!'})
        response.status_code = 200
    else:
        response = jsonify({'ERR': str(form.errors)})
        response.status_code = 422
    return response
Exemplo n.º 2
0
def forgot_password():
    form = ForgotPasswordForm()

    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data)
        if not user:
            flash("usuário não encontrado", "danger")
            return redirect(url_for(".forgot_password"))

        send_email(user.email, "recuperar senha", "forgot", user=user)

    return render_template("forgot-password.html", form=form)
Exemplo n.º 3
0
def forgot_password():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    forgot_password_form = ForgotPasswordForm()
    if forgot_password_form.validate_on_submit():
        user = User.query.filter_by(
            user_email=forgot_password_form.user_email.data).first()
        if user:
            send_email_reset_password.apply_async(args=(user.user_id, ),
                                                  countdown=2)
        flash('check your email for the link to reset your password')
        return redirect(url_for('login'))
    return render_template('forgot_password.html',
                           title='forgot password',
                           forgot_password_form=forgot_password_form)
Exemplo n.º 4
0
def forgot_password():
    ''' 忘记密码'''
    if current_user.is_authenticated:
        return redirect(request.args.get('next') or url_for('home.index'))
    form = ForgotPasswordForm()
    if form.validate_on_submit():
        email = form['email'].data
        user = User.query.filter_by(email=email).first()
        if user:
            send_reset_password_mail(email)
            message = _('密码重置邮件已发送。')  #一个反馈信息
            status = True
        else:
            message = _('此邮件地址尚未被注册。')
            status = False
        return render_template('feedback.html', status=status, message=message)
    return render_template('forgot-password.html')
Exemplo n.º 5
0
def forgot_password():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = ForgotPasswordForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user is not None:
            new_password = user.forgot_password_generate()
            user.set_password(new_password)
            flash('New password is {}. Change it as soon as possible'.format(
                new_password))
            db.session.commit()
        else:
            flash('That user does not exists. Check the username')
        return redirect(url_for('index'))
    return render_template('forgot_password.html',
                           title='Forgot password',
                           form=form)
Exemplo n.º 6
0
def forgot_password():
    if not current_user.is_anonymous:
        logout_user()
    form = ForgotPasswordForm()
    if form.validate_on_submit():
        email = form.email.data
        user = User.from_email(email)
        if user.exists():
            token = current_app.ts.dumps(user.email, salt='recover-key')
            recover_url = url_for('pages.reset_password',
                                  token=token,
                                  _external=True)
            app.send_email('Password Reset', email, recover_url)
            print(recover_url)
        flash(
            'Please check your inbox for your password reset link. (It may take a couple minutes.)'
        )
    return render_template('forgot_password.html', form=form)