Sha256: 26b55cccee422cf3d370b2b14d3a28dbe991e8253b49b20531fa293a0da8adf3

Contents?: true

Size: 1.86 KB

Versions: 5

Compression:

Stored size: 1.86 KB

Contents

module Clearance
  module App
    module Controllers
      module PasswordsController

        def self.included(base)
          base.class_eval do
            before_filter :existing_user?, :only => [:edit, :update]
            filter_parameter_logging :password, :password_confirmation
            
            include InstanceMethods
            
          private
            include PrivateInstanceMethods
          end
        end

        module InstanceMethods
          def new
          end

          def create
            user = User.find_by_email params[:password][:email]
            if user.nil?
              flash.now[:warning] = 'Unknown email'
              render :action => :new
            else
              ClearanceMailer.deliver_change_password user
              redirect_to url_after_create
            end
          end

          def edit
            @user = User.find_by_email_and_crypted_password(params[:email],
                                                            params[:password])
          end

          def update
            @user = User.find_by_email_and_crypted_password(params[:email],
                                                            params[:password])
            if @user.update_attributes params[:user]
              session[:user_id] = @user.id
              redirect_to @user
            else
              render :action => :edit
            end
          end
        end

        module PrivateInstanceMethods
          def existing_user?
            user = User.find_by_email_and_crypted_password(params[:email],
                                                           params[:password])
            if user.nil?
              render :nothing => true, :status => :not_found
            end
          end
          
          def url_after_create
            new_session_url
          end
        end

      end
    end
  end
end

Version data entries

5 entries across 5 versions & 4 rubygems

Version Path
gravis-clearance-0.3.7 lib/clearance/app/controllers/passwords_controller.rb
mischa-clearance-0.3.3 lib/clearance/app/controllers/passwords_controller.rb
mischa-mischa-clearance-0.3.3 lib/clearance/app/controllers/passwords_controller.rb
thoughtbot-clearance-0.3.4 lib/clearance/app/controllers/passwords_controller.rb
thoughtbot-clearance-0.3.7 lib/clearance/app/controllers/passwords_controller.rb