Exemplo n.º 1
0
def reset_password(token):
    """Allow a user to reset their password.
    
    Args:
        token (str): A reset token generated by send_password_reset_email
    
    Returns:
        reset_password.html: Redirect to reset password page when navigating to
            this route for the first time.
            Redirect to home page if user is already logged in.
            Redirect to home page if reset token is not authenticated.
            Redirect to login page if reset token is authenticated.
    """
    if current_user.is_authenticated:
        return redirect(url_for('coding.index'))
    user = User.verify_reset_password_token(token)
    if not user:
        return redirect(url_for('coding.index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash('Your password has been reset.')
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password.html', form=form)
Exemplo n.º 2
0
def passwordreset():
    """
    Handle requests to the /passwordreset route
    Update users password
    """

    # Redirect users who are not logged in.
    if not current_user or current_user.is_anonymous:
        return redirect(url_for('auth.signin'))

    form = ResetPasswordForm()

    if form.validate_on_submit():

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

        user.password = form.password.data

        # add user to the database
        db.session.add(user)
        db.session.commit()

        logout_user()

        flash('You have successfully reset your password. Please signin.')

        # redirect to the login page
        return redirect(url_for('auth.signin'))

    return render_template('auth/reset.html', form=form)
Exemplo n.º 3
0
def reset_password(subdomain='www'):
    token = request.args.get("token")
    if token:
        user = User.verify_reset_password_token(token)
        if not user:
            flash(
                "Your token is not valid or expired, request a new one from the login page",
                "danger")
            return redirect(url_for("main.index", subdomain=subdomain))
    if current_user.is_authenticated:
        user = current_user
    form = ResetPasswordForm()
    if form.validate_on_submit() and user:
        company = Company.query.filter_by(id=user.company_id,
                                          premium=False).first()
        if company:
            user.set_password(form.password.data)
            db.session.commit()
            flash("Your password has been reset.", "success")
        else:
            flash("Your company manage your password, we can't modify it",
                  "danger")
        return redirect(url_for("auth.login", subdomain=subdomain))

    return render_template("auth/reset_password.html",
                           subdomain=subdomain,
                           title="Reset password",
                           form=form)
Exemplo n.º 4
0
def reset_password(token):
    # 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'))

    # determine who the user is by invoking the token verification method in the User class. This method returns the
    # user if the token is valid, or None if not. If the token is invalid I redirect to the home page.
    user = User.verify_reset_password_token(token)

    # If the token above is invalid than redirect the user to the homepage
    if not user:
        return redirect(url_for('main.index'))

    # If the token checked above is valid, present the user with a second form, in which the new password is requested
    # Import the appropriate form object that was defined in forms.py (ResetPasswordForm())
    form = ResetPasswordForm()

    # This form is processed in a way similar to previous forms, and as a result of a valid form submission,
    # I invoke the set_password() method of User to change the password, and then redirect to the login page,
    # where the user can now login. I also display a success message to communicate with the user a successful change
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash('Your password has been reset.')
        return redirect(url_for('auth.login'))

    # If form fails to validate than refresh the page
    return render_template('auth/reset_password.html', form=form)
Exemplo n.º 5
0
def reset_password(token):
    """
    View function of actual form to reset the password by setting it on the page.
    :param token:
    :return:
    """
    # Reject when already authenticated.
    if current_user.is_authenticated:
        return redirect(url_for("main.index"))

    # verify the token to get the username.
    user = User.verify_reset_password_token(token)

    # if None (i.e. bad token) do not proceed.
    if not user:
        return redirect(url_for("main.index"))

    # Instantiate resetpassword form.
    form = ResetPasswordForm()

    # if the form is valid,
    if form.validate_on_submit():

        # set the password for this user.
        user.set_password(form.password.data)

        # push to data base.
        db.session.commit()

        flash("Your password has been reset.")

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

    return render_template("auth/reset_password.html", form=form)
Exemplo n.º 6
0
def reset_password(token):
	'''
	
		View function checks if the user is not logged in, and then determines 
	who the user is by invoking the token verification method in the User class. 
		This method returns the user if the token is valid, or None if not. If the token is invalid user is redirected to the home page.

	'''
	if current_user.is_authenticated:
		return redirect(url_for('main.index'))
	
	user = User.verify_reset_password_token(token)
	
	if not user:
		return redirect(url_for('main.index'))
	
	form = ResetPasswordForm()
	
	if form.validate_on_submit():
		user.set_password(form.password.data)
		db.session.commit()
		flash('Your password has been reset.')
		return redirect(url_for('auth.login'))
	
	return render_template('auth/reset_password.html', form=form)
Exemplo n.º 7
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for("main.index"))
    username, value = User.verify_reset_password_token(token)
    user = User.query.filter_by(username=username).first()
    if not user:
        return redirect(url_for("main.index"))
    reset_password = ResetPassword.query.filter_by(user_id=user.did).first()
    if reset_password:
        user.delete_expired_tokens(reset_password)
    form = ResetPasswordForm()
    if form.validate_on_submit():
        password = form.password.data
        if value == reset_password.first_value:
            reset_password.first_value = None
            reset_password.first_date = None
            user.set_password(password)
        elif value == reset_password.second_value:
            reset_password.second_value = None
            reset_password.second_date = None
            user.set_password(password)
        else:
            flash(_("Invalid or expired token"))
            return redirect(url_for("auth.reset_password_request"))
        db.session.add(reset_password)
        db.session.add(user)
        db.session.commit()
        flash(_("Your password has been reset."))
        return redirect(url_for("auth.login"))
    return render_template("auth/reset_password.html", form=form)
Exemplo n.º 8
0
def do_password_reset():
    token = session['reset_token']
    if not token:
        flash("Token not found!", "danger")
        return redirect(url_for('auth.login'))

    user = User.verify_reset_password_token(token)
    if not user:
        flash("Password reset token is invalid or has expired.", "danger")
        session.pop('reset_token',
                    None)  # remove the invalid token from the session
        return redirect(url_for('auth.login'))

    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        EmailToken.expire_token(tokenstr=token)
        session.pop('reset_token',
                    None)  # remove the reset token from the session
        # No need to db.session.commit() because expire_token commits the session for us

        flash('Your password has been reset.', "success")
        return redirect(url_for('auth.login'))
    return render_template('auth/password_reset.html',
                           title="Reset Password",
                           form=form)
Exemplo n.º 9
0
def reset_password():
    form = ResetPasswordForm()
    if form.validate_on_submit():
        email = form.email.data

        #reset password
        try:
            User.reset(email)

            # Reset successful
            flash(
                'Password reset sent for {}. Check your inbox.'.format(email),
                'teal')
            return redirect(url_for('auth.sign_in'))

        except Exception as e:
            # Reset unsuccessful
            error_json = e.args[1]
            error = json.loads(error_json)['error']['message']
            flash("Error: {}".format(error), 'red')

            return render_template('auth/reset_password.html',
                                   title='Reset Password',
                                   form=form)

    return render_template('auth/reset_password.html',
                           title='Reset Password',
                           form=form)
Exemplo n.º 10
0
def reset_password():
    form = ResetPasswordForm()
    if form.validate_on_submit():
        current_user.set_password(form.password.data)
        db.session.commit()
        logout_user()
        flash('Your password has been reset.')
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password.html', form=form)
Exemplo n.º 11
0
def reset_password():
    form = ResetPasswordForm()
    if form.validate_on_submit():
        current_user.set_password(form.password.data)
        db.session.commit()
        flash('新密码设置完成')
        return redirect(url_for(current_user.get_index()))
    return render_template('auth/reset_password.html',
                           title='Reset Password',
                           form=form)
Exemplo n.º 12
0
def reset_password(token):
  user = User.verify_reset_password_token(token)
  if not user:
      return redirect(url_for('main.index'))
  form = ResetPasswordForm()
  if form.validate_on_submit():
      user.set_password(form.password.data)
      db.session.commit()
      flash('Your password has been reset.')
      return redirect(url_for('auth.login'))
  return render_template('auth/reset_password.html', form=form)
Exemplo n.º 13
0
def reset_password():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    token = request.args.get('x_token') or request.args.get('token')
    email = request.args.get('x_email') or request.args.get('email')
    form = ResetPasswordForm()
    if form.validate_on_submit():
        User.set_password_token(email, token, form.password.data)
        flash(_('Your password has been reset.'))
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password.html', form=form)
Exemplo n.º 14
0
def reset_password_request() -> str:
    if current_user.is_authenticated:
        return redirect(url_for("main.index"))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            email.send_password_reset_confirmation(user)
        flash("Check your email to reset your password.")
        return redirect(url_for("auth.login"))
    return render_template("auth/form.html", title="Reset Password", form=form)
Exemplo n.º 15
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordForm(request.form)
    if form.validate_on_submit():
        user = User.verify_reset_password_token(token)
        user.password = bcrypt.generate_password_hash(form.password.data)
        db.session.commit()
        flash('Your password has been reset.')
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password.html', form=form)
Exemplo n.º 16
0
def reset_password():
    if not current_user.is_authenticated:
        return redirect(url_for('auth.login'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user = current_user
        if handle_reset_password(user, form):
            return redirect(url_for('main.index'))
    return render_template('auth/reset_password.html',
                           title='Reset Password',
                           form=form)
Exemplo n.º 17
0
def reset(token):
    if not current_user.is_anonymous:
        return redirect(url_for("main.index"))
    form = ResetPasswordForm()
    if not form.validate_on_submit():
        return render_template("auth/reset.html.j2", form=form)
    if User.reset_password(token, form.new_password.data):
        flash("Your password has been updated")
    else:
        flash("Password reset failed. Please try again")
    return redirect(url_for("auth.login"))
Exemplo n.º 18
0
def reset_password_request():
	if current_user.is_authenticated:
		return redirect(url_for('main.index'))
	form = ResetPasswordForm()
	if form.validate_on_submit():
		user = User.query.filter_by(email = form.email.data).first()
		if user is not None:
			send_password_reset_email(user)
		flash('Check your email for password reset link')
		return redirect(url_for('auth.login'))
	return render_template('reset_password_request.html',form=form)
Exemplo n.º 19
0
def reset_password():
    form = ResetPasswordForm()

    if form.validate_on_submit():
        user = User.query.filter_by(user_email=session['user_email']).first()
        user.user_password = generate_password_hash(
            form.password.data).decode('utf-8')
        db.session.add(user)
        db.session.commit()
        login_user(user)
        return redirect(url_for('bins.success'))
    return render_template('auth/reset_password.html', form=form)
Exemplo n.º 20
0
def reset_password(token):
    if not current_user.is_anonymous:
        return redirect(url_for('main.index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        if User.reset_password(token, form.password.data):
            db.session.commit()
            flash('您的密码已修改')
            return redirect(url_for('auth.login'))
        else:
            return redirect(url_for('main.index'))
    return render_template('auth/reset_password.html', form=form)
Exemplo n.º 21
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    user_ = User.verify_reset_password_token(token)
    if not user_:
        return redirect(url_for('main.index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user_.set_password(form.password.data)
        flash(_('Your Password has been reset'))
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password.html', form=form)
Exemplo n.º 22
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    user = User.verify_reset_password_token(token)
    if not user:
        return redirect(url_for('main.index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash(_('Your password has been reset.'))
        return redirect(url_for('auth.login'))
Exemplo n.º 23
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('feed.feed'))
    user = UsersController.verify_token_reset_password(token)
    if not user:
        return redirect(url_for('auth.login'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        controller = UsersController()
        controller.update_password(user=user, new_password=form.password.data)
        return redirect(url_for('auth.login'))
    return render_template("auth/reset_password.html", form=form, token=token)
Exemplo n.º 24
0
def reset_password(token):
    form = ResetPasswordForm()
    if form.validate_on_submit():
        dest_url = 'http://' + Config.MAIL_SENDING_SERVICE_URL + '/api/reset-password/token-receiving/' +\
                   str(token)
        new_password = str(form.re_new_password.data)
        result = requests.get(dest_url)
        account_to_reset = get_api_info(result)[0]
        account_to_reset['password'] = new_password
        update_account_url = 'http://' + Config.ACCOUNT_SERVICE_URL + '/api/account/account-updating'
        requests.put(update_account_url, data=account_to_reset)
        return render_template('auth/email/inform_reset_success.html', form=form, account_email=account_to_reset['account_email'])
Exemplo n.º 25
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for("main.index"))
    user = verify_reset_password_token(token)
    if not user:
        return redirect(url_for("main.index"))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        change_password(user, form.password.data)
        flash(_("Your password has been reset"))
        return redirect(url_for("auth.login"))
    return render_template("auth/reset_password.html", form=form)
Exemplo n.º 26
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        if User.reset_password(token, form.password.data):
            db.session.commit()
            flash('Ваш пароль был сброшен')
            return redirect(url_for('auth.login'))
        else:
            return redirect(url_for('main.index'))
    return render_template('auth/reset_password.html', form=form)
Exemplo n.º 27
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    client = Client.verify_reset_password_token(token)
    if not client:
        return redirect(url_for('main.index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        client.set_password(form.password.data)
        db.session.commit()
        flash(_('Your password has been reset.'))
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password.html', form=form)
Exemplo n.º 28
0
def reset_password(token):
	if current_user.is_authenticated:
		return redirect(url_for('main.index'))
	user=User.verify_reset_password_token(token)
	if not user:
		return redirect(url_for('main.index'))
	form=ResetPasswordForm()
	if form.validate_on_submit():
		user.set_password(form.password.data)
		db.session.commit()
		flash('密码已重置.')
		return redirect(url_for('auth.login'))
	return render_template('auth/reset_password.html',title='密码重置',form=form)
Exemplo n.º 29
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for("main.index"))
    user = User.verify_reset_password_token(token)
    if not user:
        return redirect(url_for("main.index"))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash("Your password has been reseted")
        return redirect(url_for("auth.login"))
    return render_template("reset_password.html", form=form)
Exemplo n.º 30
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    _user = User.verify_reset_password_token(token)  # this is weird naming?
    if not _user:
        return redirect(url_for('main.index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        _user.set_password(form.password.data)
        db.session.commit()
        flash('your password has been reset')
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_pw.html', form=form)
Exemplo n.º 31
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    user = User.verify_token(token, Operations.RESET_PASSWORD)
    if not user:
        return redirect(url_for('main.index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash(_('Your password has been reset.'))
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password.html', form=form)
Exemplo n.º 32
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    user = User.verify_reset_password_token(token)
    if not user:
        return redirect(url_for('main.index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash(_('Your password has been reset.'))
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password.html', form=form)
Exemplo n.º 33
0
def reset_password(token):
    if not current_user.is_anonymous:
        return redirect(url_for('main.index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is None:
            return redirect(url_for('main.index'))
        if user.reset_password(token, form.password.data):
            flash('Your password has been updated.')
            return redirect(url_for('auth.login'))
        else:
            return redirect(url_for('main.index'))

    return render_template('auth/reset_password.html', form=form)