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