Sha256: 2ddf607d7a17849a4ed6aa0f4cd77a420dbb3ae6b600075e500082efdf6d789a

Contents?: true

Size: 1.9 KB

Versions: 9

Compression:

Stored size: 1.9 KB

Contents

module Casein
  class PasswordResetsController < Casein::CaseinController
  
    skip_before_filter :authorise
    before_filter :load_user_using_perishable_token, :only => [:edit, :update]

    layout 'casein_auth'
    
    def create
      users = Casein::AdminUser.where(:email => params[:recover_email]).all

      if users.length > 0
        users.each do |user|
          user.send_password_reset_instructions
        end

        if users.length > 1
          flash[:notice] = "Multiple accounts were found. Emails have been sent to " + params[:recover_email] + " with instructions on how to reset your passwords"
        else
          flash[:notice] = "An email has been sent to " + params[:recover_email] + " with instructions on how to reset your password"
        end
      else
        flash[:warning] = "There is no user with that email"
      end

      redirect_to new_casein_admin_user_session_url
    end

    def edit
      render
    end

    def update
      
      if params[:casein_admin_user][:password].empty? || params[:casein_admin_user][:password_confirmation].empty?
        flash.now[:warning] = "A field has been left empty"
      else
      
        @reset_user.password = params[:casein_admin_user][:password]
        @reset_user.password_confirmation = params[:casein_admin_user][:password_confirmation]
      
        if @reset_user.save
          flash[:notice] = "Password successfully updated"
          redirect_to new_casein_admin_user_session_url
          return
        end
      end
      
      render :action => :edit
    end

  private
    
    def load_user_using_perishable_token
      
      @reset_user = Casein::AdminUser.find_using_perishable_token params[:token]
      
      unless @reset_user
        flash[:warning] = "Your account could not be located. Try to copy and paste the URL directly from the email."
        redirect_to new_casein_admin_user_session_url
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
casein-5.1.1.5 app/controllers/casein/password_resets_controller.rb
casein-5.1.1.4 app/controllers/casein/password_resets_controller.rb
casein-5.1.1.3 app/controllers/casein/password_resets_controller.rb
casein-5.1.1.2 app/controllers/casein/password_resets_controller.rb
casein-5.1.1.1 app/controllers/casein/password_resets_controller.rb
casein-5.1.1.0 app/controllers/casein/password_resets_controller.rb
casein-5.1.0.0 app/controllers/casein/password_resets_controller.rb
casein-5.0.1.0 app/controllers/casein/password_resets_controller.rb
casein-5.0.0.0 app/controllers/casein/password_resets_controller.rb