Sha256: a49183222d9dce32b7bac93dcdae7e18470568168847c780f93c3195dcef545d

Contents?: true

Size: 1.4 KB

Versions: 14

Compression:

Stored size: 1.4 KB

Contents

class PasswordResetsController < ApplicationController

  before_action :load_user_using_perishable_token, only: [:show, :update]
  skip_before_action :require_user, raise: false
  respond_to :html
  layout 'user_sessions'

  def index

  end

  def create
    @user = SpudUser.find_by(email: params[:email])
    if @user
      @user.reset_perishable_token!
      TbCoreMailer.forgot_password_notification(@user, password_reset_url(@user.perishable_token)).deliver_later
      flash[:notice] = 'Password reset instructions have been sent to your email'
      redirect_to login_path
    else
      flash.now[:error] = 'No user was found with that email address'
      render 'index'
    end
  end

  def show

  end

  def update
    if params[:spud_user][:password].blank?
      @user.errors.add(:password, 'must not be blank')
    else
      @user.password = params[:spud_user][:password]
      @user.password_confirmation = params[:spud_user][:password_confirmation]
      if @user.save()
        SpudUserSession.create(@user)
        flash[:notice] = 'Password successfully updated'
        redirect_back_or_default(root_path)
        return
      end
    end
    render 'show'
  end

private

  def load_user_using_perishable_token
    @user = SpudUser.find_using_perishable_token(params[:id])
    unless @user
      flash[:error] = 'Password reset token was invalid or expired'
      redirect_to login_path
    end
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
tb_core-1.5.4 app/controllers/password_resets_controller.rb
tb_core-1.5.3 app/controllers/password_resets_controller.rb
tb_core-1.5.2 app/controllers/password_resets_controller.rb
tb_core-1.5.1 app/controllers/password_resets_controller.rb
tb_core-1.4.3.1 app/controllers/password_resets_controller.rb
tb_core-1.5.0 app/controllers/password_resets_controller.rb
tb_core-1.4.8 app/controllers/password_resets_controller.rb
tb_core-1.4.7 app/controllers/password_resets_controller.rb
tb_core-1.4.6 app/controllers/password_resets_controller.rb
tb_core-1.4.5 app/controllers/password_resets_controller.rb
tb_core-1.4.4 app/controllers/password_resets_controller.rb
tb_core-1.4.3 app/controllers/password_resets_controller.rb
tb_core-1.4.2 app/controllers/password_resets_controller.rb
tb_core-1.4.1 app/controllers/password_resets_controller.rb