Sha256: ba4e9d2146e275d727dd12649c99c22a8c44f6105f5b27f353fe2935b4a1c2dc

Contents?: true

Size: 1.32 KB

Versions: 10

Compression:

Stored size: 1.32 KB

Contents

class PasswordResetsController < ApplicationController

  before_filter :load_user_using_perishable_token, :only => [:show, :update]
  skip_before_filter :require_user
  respond_to :html

  def index

  end

  def create
    @user = SpudUser.find_by_email(params[:email])
    if @user
      @user.reset_perishable_token!
      CoreMailer.forgot_password_notification(@user, password_reset_url(@user.perishable_token)).deliver
      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()
        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

10 entries across 10 versions & 1 rubygems

Version Path
tb_core-1.2.1 app/controllers/password_resets_controller.rb
tb_core-1.2.0 app/controllers/password_resets_controller.rb
tb_core-1.1.10 app/controllers/password_resets_controller.rb
tb_core-1.1.9 app/controllers/password_resets_controller.rb
tb_core-1.1.8 app/controllers/password_resets_controller.rb
tb_core-1.1.7 app/controllers/password_resets_controller.rb
tb_core-1.1.6 app/controllers/password_resets_controller.rb
tb_core-1.1.5 app/controllers/password_resets_controller.rb
tb_core-1.1.4 app/controllers/password_resets_controller.rb
tb_core-1.1.2 app/controllers/password_resets_controller.rb