2010-02-17 06:25:20 -05:00
|
|
|
class Devise::SessionsController < ApplicationController
|
2010-03-26 07:26:51 -04:00
|
|
|
prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
|
2010-01-13 12:12:13 -05:00
|
|
|
include Devise::Controllers::InternalHelpers
|
2009-10-27 19:26:40 -04:00
|
|
|
|
2009-10-17 11:10:15 -04:00
|
|
|
# GET /resource/sign_in
|
2009-10-07 20:46:40 -04:00
|
|
|
def new
|
2011-04-18 03:56:24 -04:00
|
|
|
resource = build_resource
|
|
|
|
clean_up_passwords(resource)
|
|
|
|
respond_with_navigational(resource, stub_options(resource)){ render_with_scope :new }
|
2009-10-07 20:46:40 -04:00
|
|
|
end
|
|
|
|
|
2009-10-17 11:10:15 -04:00
|
|
|
# POST /resource/sign_in
|
2009-10-07 20:46:40 -04:00
|
|
|
def create
|
2010-09-26 15:11:28 -04:00
|
|
|
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
|
2010-12-20 05:08:48 -05:00
|
|
|
set_flash_message(:notice, :signed_in) if is_navigational_format?
|
|
|
|
sign_in(resource_name, resource)
|
|
|
|
respond_with resource, :location => redirect_location(resource_name, resource)
|
2009-10-07 20:46:40 -04:00
|
|
|
end
|
|
|
|
|
2009-10-17 11:10:15 -04:00
|
|
|
# GET /resource/sign_out
|
2009-10-07 20:46:40 -04:00
|
|
|
def destroy
|
2010-10-10 10:45:55 -04:00
|
|
|
signed_in = signed_in?(resource_name)
|
2011-01-16 08:31:37 -05:00
|
|
|
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
|
2010-10-10 10:45:55 -04:00
|
|
|
set_flash_message :notice, :signed_out if signed_in
|
2011-01-16 08:31:37 -05:00
|
|
|
|
2011-03-30 08:09:12 -04:00
|
|
|
# We actually need to hardcode this, as Rails default responder doesn't
|
2011-01-16 08:31:37 -05:00
|
|
|
# support returning empty response on GET request
|
|
|
|
respond_to do |format|
|
|
|
|
format.any(*navigational_formats) { redirect_to after_sign_out_path_for(resource_name) }
|
2011-03-30 08:09:12 -04:00
|
|
|
format.all do
|
|
|
|
method = "to_#{request_format}"
|
|
|
|
text = {}.respond_to?(method) ? {}.send(method) : ""
|
|
|
|
render :text => text, :status => :ok
|
|
|
|
end
|
2011-01-16 08:31:37 -05:00
|
|
|
end
|
2009-10-07 20:46:40 -04:00
|
|
|
end
|
2011-04-18 03:56:24 -04:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def stub_options(resource)
|
2011-04-19 02:35:03 -04:00
|
|
|
array = resource_class.authentication_keys.dup
|
|
|
|
array << :password if resource.respond_to?(:password)
|
|
|
|
{ :methods => array, :only => [:password] }
|
2011-04-18 03:56:24 -04:00
|
|
|
end
|
|
|
|
end
|