Skip to content

Commit

Permalink
move providers to SwitchUser::Provider::ProviderName
Browse files Browse the repository at this point in the history
fixes error raise by SwitchUserController#provider_class
autoload wasn't finding the constant Provider
Provider wasn't namespaced under SwitchUser, so it was poluting the namespace
  • Loading branch information
lcowell committed Sep 27, 2012
1 parent 5901b57 commit 078a263
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 88 deletions.
2 changes: 1 addition & 1 deletion app/controllers/switch_user_controller.rb
Expand Up @@ -56,6 +56,6 @@ def provider
end

def provider_class
"Provider::#{SwitchUser.provider.to_s.classify}".constantize
"SwitchUser::Provider::#{SwitchUser.provider.to_s.classify}".constantize
end
end
6 changes: 0 additions & 6 deletions lib/provider.rb

This file was deleted.

22 changes: 0 additions & 22 deletions lib/provider/authlogic.rb

This file was deleted.

20 changes: 0 additions & 20 deletions lib/provider/devise.rb

This file was deleted.

19 changes: 0 additions & 19 deletions lib/provider/restful_authentication.rb

This file was deleted.

19 changes: 0 additions & 19 deletions lib/provider/sorcery.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/switch_user.rb
@@ -1,4 +1,4 @@
require 'provider'
require 'switch_user/provider'

module SwitchUser
if defined? Rails::Engine
Expand Down
8 changes: 8 additions & 0 deletions lib/switch_user/provider.rb
@@ -0,0 +1,8 @@
module SwitchUser
module Provider
autoload :Authlogic, "switch_user/provider/authlogic"
autoload :Devise, "switch_user/provider/devise"
autoload :RestfulAuthentication, "switch_user/provider/restful_authentication"
autoload :Sorcery, "switch_user/provider/sorcery"
end
end
24 changes: 24 additions & 0 deletions lib/switch_user/provider/authlogic.rb
@@ -0,0 +1,24 @@
module SwitchUser
module Provider
class Authlogic
def initialize(controller)
@controller = controller
end

def login(user, scope = nil)
UserSession.create(user)
end

def logout(scope = nil)
@controller.current_user_session.destroy
end

def current_user(scope = nil)
result = UserSession.find
if result
result.record
end
end
end
end
end
22 changes: 22 additions & 0 deletions lib/switch_user/provider/devise.rb
@@ -0,0 +1,22 @@
module SwitchUser
module Provider
class Devise
def initialize(controller)
@controller = controller
@warden = @controller.warden
end

def login(user, scope = nil)
@warden.set_user(user, :scope => scope)
end

def logout(scope = nil)
@warden.logout(scope)
end

def current_user(scope = nil)
@controller.current_user
end
end
end
end
21 changes: 21 additions & 0 deletions lib/switch_user/provider/restful_authentication.rb
@@ -0,0 +1,21 @@
module SwitchUser
module Provider
class RestfulAuthentication
def initialize(controller)
@controller = controller
end

def login(user, scope = nil)
@controller.current_user = user
end

def logout(scope = nil)
@controller.logout_killing_session!
end

def current_user(scope = nil)
@controller.current_user
end
end
end
end
21 changes: 21 additions & 0 deletions lib/switch_user/provider/sorcery.rb
@@ -0,0 +1,21 @@
module SwitchUser
module Provider
class Sorcery
def initialize(controller)
@controller = controller
end

def login(user, scope = nil)
@controller.auto_login(user)
end

def logout(scope = nil)
@controller.logout
end

def current_user(scope = nil)
@controller.current_user
end
end
end
end

0 comments on commit 078a263

Please sign in to comment.