def test_validate_email(self, db):
     """validate_email raises ValidationError if address not in db."""
     user = create_dummy_user()
     db.session.add(user)
     db.session.commit()
     form = ResetPasswordRequestForm()
     form.email.data = '*****@*****.**'
     with pytest.raises(ValidationError):
         form.validate_email(form.email)
Exemplo n.º 2
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email(user)
        flash(
            _('Check your email for the instructions to reset your password'))
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html',
                           title=_('Reset Password'), form=form)
Exemplo n.º 3
0
def reset_password_request():
    if not current_user.is_anonymous:
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            token = user.generate_reset_token()
            send_email(user.email, 'Reset Your Password', 'auth/email/reset_password',
                       user=user, token=token, next=request.args.get('next'))
            flash('An email with instructions to reset your password has been sent ot you.')
            return redirect(url_for('auth.login'))
        else:
            return redirect(url_for('main.index'))

    return render_template('auth/reset_password.html', form=form)
Exemplo n.º 4
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is None:
            render_template('auth/reset_password_request.html',
                            title='Reset your Password - Echo',
                            form=form)
        else:
            send_password_reset_email(user)
            flash(
                'Check your email for the instructions to reset your password')
            return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html',
                           title='Reset your Password - Echo',
                           form=form)
Exemplo n.º 5
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    pform = ResetPasswordRequestForm()
    if pform.validate_on_submit():
        user = User.query.filter_by(email=pform.email.data).first()
        if user:
            send_password_reset_email(user)
            print(user)
        flash('Check your email for the instructions to reset your password')
        return redirect(url_for('auth.login'))

    return render_template('auth/reset_password_request.html',
                           title='Sign In',
                           form=LoginForm(),
                           rform=RegistrationForm(),
                           pform=pform,
                           mode='reset')
Exemplo n.º 6
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for("auth.login"))

    form = ResetPasswordRequestForm()

    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()

        if user:
            send_password_reset_email(user)

        flash("Check your email for the instructions to reset your password", "info")
        return redirect(url_for("auth.login"))

    return render_template(
        "auth/reset_password_request.html", title="Reset Password", form=form
    )
Exemplo n.º 7
0
def reset_password_request():
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        validemail = validate_email(form.email.data)
        if not validemail:
            return redirect(url_for("auth.reset_password_request"))
        user = User.get_reset_token(validemail)
        if user:
            send_auth_email(user.email, user.password_reset_token, "reset")
        db.session.commit()
        flash("Check your email for the instructions to reset your password",
              "info")
        return redirect(url_for("auth.login"))
    return render_template(
        "auth/password_reset.html",
        title="Request Password Reset",
        form=form,
        pwrequest=True,
    )
Exemplo n.º 8
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))

    form = ResetPasswordRequestForm()

    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email(user)
            flash(_('Check your email for instructions to reset the password'))
        else:
            flash(_('The email address hasn\'t been registered'))

        return redirect(url_for('auth.login'))

    return render_template('auth/reset_password_request.html',
                           title=_('Reset Password'),
                           form=form)
Exemplo n.º 9
0
def reset_password_request():
    """
    Responsible for sending a request for reset users password in the system

    :return: Landing page "Register" or Redirect to "login"
    """
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email(user)
        flash(
            _('Check your email for the instructions to reset your password'))
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html',
                           title=_('Reset Password'),
                           form=form)
Exemplo n.º 10
0
def reset_password_request(subdomain='www'):
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            company = Company.query.filter_by(id=user.company_id,
                                              premium=False).first()
            if company:
                send_password_reset_email(user, subdomain=subdomain)
                flash("An email with instructions was sent to your address.",
                      "success")
            else:
                flash("Your company manage your password, we can't modify it",
                      "warning")
        return redirect(url_for("auth.login", subdomain=subdomain))
    return render_template("auth/reset_password_request.html",
                           subdomain=subdomain,
                           title="Reset Password",
                           form=form)
Exemplo n.º 11
0
def reset_password_req():
    '''
    If the user requests a password reset,
    look up their account by the email they submit.
    If the account is found, send a reset email.
    '''
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email(user)
            flash('Password reset email sent.')
            return redirect(url_for('auth.login'))
        else:
            flash('No user registered with that email address.')
            return redirect(url_for('auth.reset_password_req'))
    return render_template('auth/reset_password_req.html',
                           title='Reset Password', form=form)
Exemplo n.º 12
0
def reset_password_request():
    #If they are authenticated/logged in then there is no need to reset the pass
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    #Send user a form to enter which email they want the verification to be sent to
    form = ResetPasswordRequestForm()
    #Check to see if there actually is a user with the email listed in the form
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            #send the email if everything was successful, using the
            send_password_reset_email(user)
        #Flash this msg no matter what, so users can't use this to check if someone else is using the site
        flash(
            _('Check your email for the instructions to reset your password'))
        return redirect(url_for('auth.login'))
    #The first request to this route will just load the form where user enters their email
    return render_template('auth/reset_password_request.html',
                           title='Reset Password',
                           form=form)
Exemplo n.º 13
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email(user)
            current_app.logger.info(
                'user {} with <{}> request to reset password.'.format(
                    user.username, form.email.data))
        else:
            current_app.logger.warn(
                'unregistered <{}> request to reset password.'.format(
                    form.email.data))
        flash(_('Check your email for instructions to reset your password.'))
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html',
                           title=_('Reset Password'),
                           form=form)
Exemplo n.º 14
0
def reset_password_request():
    """
    重置密码:邮件验证
    :return:
    """
    # 不是匿名用户,则跳转到首页
    if not current_user.is_anonymous:
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            token = user.generate_reset_token()
            # send_email(user.email, '重置密码', 'auth/email/reset_password', user=user, token=token,
            #            next=request.args.get('next'))
            flash('重置密码邮件已发送,请注意查收')
            redirect(url_for('auth.login'))
        else:
            flash('用户不存在')
    return render_template('auth/reset_password.html', form=form)
Exemplo n.º 15
0
def reset_password_request():
	if current_user.is_authenticated:
		return redirect(url_for('main.index'))
	form = ResetPasswordRequestForm()
	if form.validate_on_submit():
		validemail = User.validate_email(form.email.data)
		if not validemail:
			flash("%s does not appear to be a valid, deliverable email address." % form.email.data, "danger")
			return redirect(url_for('auth.reset_password_request'))
		user = User.query.filter_by(email=validemail).first()
		if user:
			send_password_reset_email(user)
		flash('Check your email for the instructions to reset your password', "info")
		return redirect(url_for('auth.login'))
	return render_template(
		'auth/password_reset.html',
		title='Request Password Reset',
		form=form,
		pwrequest=True
	)
Exemplo n.º 16
0
def reset_password_request():
    h1_txt = 'Восстановление пароля'
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter(User.email == form.email.data).first()
        if user:
            send_password_reset_email(user)
            flash(
                'Было отправлено письмо с дальнейшими инструкциями. Проверьте свой почтовый ящик.'
            )
            return redirect(url_for('auth.login'))
        else:
            flash('Пользователь с таким e-mail не зарегистрирован')
            return redirect(url_for('auth.login'))
    return render_template('add_edit_DB_item.html',
                           title='Восстановление пароля',
                           h1_txt=h1_txt,
                           form=form)
Exemplo n.º 17
0
def reset_password_request():
    """
    View function for reset password request.
    """
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.get_user(form.email.data)
        if user:
            send_password_reset_email(user)
            flash(
                'Check your email for the instructions to reset your password')
        else:
            flash('Email is not registered, please register first')
            return redirect(url_for('auth.register'))
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html',
                           title='Reset Password',
                           form=form)
Exemplo n.º 18
0
def reset_password_request():
    """
        View function for a User to ask for a password reset

        :param article_number: selected article id
        :type article_number: str

        :return: the view to be displayed
        :rtype: str
    """

    tmp_article = Article.query.filter_by(title="TMP").first()

    if tmp_article:

        db.session.delete(tmp_article)
        db.session.commit()

    if current_user.is_authenticated:

        return redirect(url_for("main.index"))

    form = ResetPasswordRequestForm()

    if form.validate_on_submit():

        user = User.query.filter_by(email=form.email.data).first()

        if user:

            send_password_reset_email(user)

        flash(
            "Un email t'a été envoyé avec les instructions afin de réinitialiser ton mot de passe"
        )

        return redirect(url_for("auth.login"))

    return render_template("auth/reset_password_request.html",
                           title="Réinitialisation du mot de passe",
                           form=form)
Exemplo n.º 19
0
def reset_password_request():
    # If the user is logged in, skip the reset password page
    if current_user.is_authenticated:
        return redirect(url_for('profile.profile'))
    form = ResetPasswordRequestForm()

    # If the form was submitted and is validated
    if form.validate_on_submit():
        u = User.query.filter(
            func.lower(User.email) == func.lower(form.email.data)).first()
        # If we find the user, send them the password reset email
        if u:
            send_password_reset_email(u)
        flash(
            'Success! Check your email for instructions on the next steps for resetting your password',
            'success')
        return redirect(url_for('auth.login'))

    return render_template('auth/reset-password-request.html',
                           title='Reset Password',
                           form=form)
Exemplo n.º 20
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))

    form = ResetPasswordRequestForm()

    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()

        if user:
            send_password_reset_email(user)

        # always make it look like a user was found to avoid this form being
        # an attack vector
        flash('Check ya email for password reset instructions and then BURN '
              'THEM with your delete key')
        return redirect(url_for('auth.login'))

    return render_template('auth/reset_password_request.html',
                           title='Reset password request',
                           form=form)
Exemplo n.º 21
0
def reset_password_request():
    # Check to make sure that the user isn't logged in and has stumbled to this page... if so redirect to home page
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))

    # Import the appropriate form object that was defined in forms.py (ResetPasswordRequestForm())
    form = ResetPasswordRequestForm()

    # Check for validation on submit and if successful (if email entered exists) than send password reset email
    # Additionally we will display a success message and redirec the user to the login page & display errors (inherent)
    # If they fail validation than simply reload the current page
    if form.validate_on_submit():
        # set the user variable to be the first returned match for the passed user argument
        user = User.query.filter_by(email=form.email.data).first()

        if user:
            send_password_reset_email(user)

        # You may notice that the flashed message below is displayed even if the email provided by the user is unknown.
        # This is so that clients cannot use this form to figure out if a given user is a member or not.
        flash('Check your email for the instructions to reset your password')
        return redirect(url_for('auth.login'))

    return render_template('auth/reset_password_request.html', title='Reset Password', form=form)
Exemplo n.º 22
0
def reset_password_request():
    form = ResetPasswordRequestForm()
    return render_template('auth/email/reset_password_request.html', form=form)