diff --git a/app/controllers/switch_user_controller.rb b/app/controllers/switch_user_controller.rb index 3ddc451..9e232d2 100644 --- a/app/controllers/switch_user_controller.rb +++ b/app/controllers/switch_user_controller.rb @@ -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 diff --git a/lib/provider.rb b/lib/provider.rb deleted file mode 100644 index e8ea02a..0000000 --- a/lib/provider.rb +++ /dev/null @@ -1,6 +0,0 @@ -module SwitchUser - 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 diff --git a/lib/provider/authlogic.rb b/lib/provider/authlogic.rb deleted file mode 100644 index 0be4851..0000000 --- a/lib/provider/authlogic.rb +++ /dev/null @@ -1,22 +0,0 @@ -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 diff --git a/lib/provider/devise.rb b/lib/provider/devise.rb deleted file mode 100644 index f7801d1..0000000 --- a/lib/provider/devise.rb +++ /dev/null @@ -1,20 +0,0 @@ -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 diff --git a/lib/provider/restful_authentication.rb b/lib/provider/restful_authentication.rb deleted file mode 100644 index 6005283..0000000 --- a/lib/provider/restful_authentication.rb +++ /dev/null @@ -1,19 +0,0 @@ -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 diff --git a/lib/provider/sorcery.rb b/lib/provider/sorcery.rb deleted file mode 100644 index 550556f..0000000 --- a/lib/provider/sorcery.rb +++ /dev/null @@ -1,19 +0,0 @@ -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 diff --git a/lib/switch_user.rb b/lib/switch_user.rb index a765bcb..41178f4 100644 --- a/lib/switch_user.rb +++ b/lib/switch_user.rb @@ -1,4 +1,4 @@ -require 'provider' +require 'switch_user/provider' module SwitchUser if defined? Rails::Engine diff --git a/lib/switch_user/provider.rb b/lib/switch_user/provider.rb new file mode 100644 index 0000000..59da256 --- /dev/null +++ b/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 diff --git a/lib/switch_user/provider/authlogic.rb b/lib/switch_user/provider/authlogic.rb new file mode 100644 index 0000000..3e8884c --- /dev/null +++ b/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 diff --git a/lib/switch_user/provider/devise.rb b/lib/switch_user/provider/devise.rb new file mode 100644 index 0000000..244573d --- /dev/null +++ b/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 diff --git a/lib/switch_user/provider/restful_authentication.rb b/lib/switch_user/provider/restful_authentication.rb new file mode 100644 index 0000000..25243dd --- /dev/null +++ b/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 diff --git a/lib/switch_user/provider/sorcery.rb b/lib/switch_user/provider/sorcery.rb new file mode 100644 index 0000000..7d768e4 --- /dev/null +++ b/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