Ejemplo n.º 1
0
def forgotPassword():
    form = ForgotPasswordForm()
    pageTitle = "forgot password"

    if request.method == 'POST':
        if not form.validate():
            return render_template('users/forgotPassword.html',
                                   form=form,
                                   pageTitle=pageTitle)
        else:
            try:
                user = User.get(email=form.email.data.lower().strip())
            except:
                flash("That email does not exist, please try another.")
                return render_template('users/forgotPassword.html',
                                       form=form,
                                       pageTitle=pageTitle)

            # # disallows password reset link to be reused
            # oldhash = user.pwdhash[:10]
            # payload = User.get_password_reset_link(user) + oldhash

            payload = User.get_password_reset_link(user)
            email_password_reset(user, payload)

            flash("Password reset email has been sent. \
                   Link is good for 24 hours.")
            return redirect(url_for('index'))
    elif request.method == 'GET':
        return render_template('users/forgotPassword.html',
                               form=form,
                               pageTitle="Forgot Password")
Ejemplo n.º 2
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
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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')
Ejemplo n.º 6
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)
Ejemplo n.º 7
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)
def forgot_password(request):
    try:
        if user.is_authenticated:
            return HttpResponseRedirect(reverse('index'))
    except:
        pass
    if request.method == "POST":
        form = ForgotPasswordForm(data=request.POST)
        if form.is_valid():
            email = form.cleaned_data.get('email')
            user = User.objects.filter(email = email).first()
            if user:
                new_password = generate_password()
                user.set_password(new_password)
                user.save()
                password_sent(user.id, new_password)
            return HttpResponseRedirect(reverse('forgot_password_confirmation'))
    else:
        form = ForgotPasswordForm()
    return render(request, 'forgot_password.html', {'form':form})
Ejemplo n.º 9
0
def forgot_password(request):
    if request.user.is_authenticated():
        return HttpResponse("Already Logged in")
    if request.POST:
        form = ForgotPasswordForm(data=request.POST, files=request.FILES)
        if form.is_valid():
            form.complete()
            return HttpResponse("Check your mail for a link bruh")
    else:
        form = ForgotPasswordForm()
    return render(request,'forgot_password.html',{'form':form})
Ejemplo n.º 10
0
def forgot_password_request():
    form_forgot_password = ForgotPasswordForm()
    return render_template('forgot_password.html',
                           form=form_forgot_password,
                           title="Reset_Password_Request")