Sha256: 4d6885c7f29068a473b040d93b20a1556f54157da4ee4761122273427f987729

Contents?: true

Size: 866 Bytes

Versions: 2

Compression:

Stored size: 866 Bytes

Contents

require_dependency "current_user/application_controller"

module CurrentUser
  class SessionsController < ApplicationController
    before_filter :check_key, :except => :destroy

    def new
      sign_out
      @users = users
    end

    def create
      user = ::User.find params[:user_id]
      sign_in user
      redirect_to main_app.root_url
    end

    def destroy
      new
      render :new
    end

    private

    def check_key
      key = ::CurrentUser.authentication_key

      if key.blank? || key != params[:key]
        render_unauthorized
      end
    end

    # TODO: move it from the controller
    def users
      identifier = ::CurrentUser.identifier

      if identifier.respond_to? :call
        ::User.all.sort { |x,y| identifier.call(x) <=> identifier.call(y) }
      else
        ::User.order identifier.to_s
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
current_user-0.1.0 app/controllers/current_user/sessions_controller.rb
current_user-0.0.1 app/controllers/current_user/sessions_controller.rb