Created
September 30, 2010 14:27
-
-
Save RSpace/604661 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomFailure < Devise::FailureApp | |
# Never do http authentication through Devise | |
def http_auth? | |
false | |
end | |
def redirect_url | |
send(:"new_#{scope}_session_path", :format => (request.xhr? ? 'js' : nil )) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Devise.setup do |config| | |
... | |
# ==> Warden configuration | |
# If you want to use other strategies, that are not (yet) supported by Devise, | |
# you can configure them inside the config.warden block. | |
config.warden do |manager| | |
manager.failure_app = CustomFailure | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MyApp::Application.routes.draw do | |
# Devise authentication | |
devise_for :users, | |
:controllers => { :sessions => '/sessions', :registrations => '/registrations' } | |
end | |
... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SessionsController < Devise::SessionsController | |
def sign_in_and_redirect(resource_or_scope, resource=nil) | |
scope = Devise::Mapping.find_scope!(resource_or_scope) | |
resource ||= resource_or_scope | |
redirect_url = stored_location_for(scope) | |
respond_to do |format| | |
format.js do | |
sign_in(scope, resource) unless warden.user(scope) == resource | |
if redirect_url.present? | |
redirect_url = "#{redirect_url}.js" unless redirect_url[-3..-1] == '.js' | |
redirect_url += redirect_url.match(/\?/) ? '&' : '?' | |
redirect_url += "after_authentication=true" | |
redirect_to redirect_url | |
else | |
render(:update) do |page| | |
page << render('/shared/after_authentication') | |
end | |
end | |
end | |
format.html { super } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment