Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 53 lines (44 sloc) 1.696 kb
2b64c6d @sj26 Make all controllers inherit from a single DeviseController
sj26 authored
1 class Devise::SessionsController < DeviseController
a5ba2ac @carlosantoniodasilva Use prepend_before_filter in require_no_authentication.
carlosantoniodasilva authored
2 prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
ab9d856 @josevalim Add a deprecation warning for previous controller authorization style.
josevalim authored
3 prepend_before_filter :allow_params_authentication!, :only => :create
dede8af @josevalim Do not include Devise internal helpers in application controller.
josevalim authored
4
b21b629 @carlosantoniodasilva Better documentation.
carlosantoniodasilva authored
5 # GET /resource/sign_in
7ce49cb @carlosantoniodasilva Configuring session and password controllers as engine, and getting inte...
carlosantoniodasilva authored
6 def new
4a4dcb3 @josevalim sessions/new also responds to xml and json now
josevalim authored
7 resource = build_resource
8 clean_up_passwords(resource)
83c4755 @josevalim Extract auth_options into its own method.
josevalim authored
9 respond_with(resource, serialize_options(resource))
7ce49cb @carlosantoniodasilva Configuring session and password controllers as engine, and getting inte...
carlosantoniodasilva authored
10 end
11
b21b629 @carlosantoniodasilva Better documentation.
carlosantoniodasilva authored
12 # POST /resource/sign_in
7ce49cb @carlosantoniodasilva Configuring session and password controllers as engine, and getting inte...
carlosantoniodasilva authored
13 def create
83c4755 @josevalim Extract auth_options into its own method.
josevalim authored
14 resource = warden.authenticate!(auth_options)
e8e3df3 @sikachu Add support for non-navigational format response to SessionsController
sikachu authored
15 set_flash_message(:notice, :signed_in) if is_navigational_format?
16 sign_in(resource_name, resource)
bba6562 @josevalim after_sign_in_path_for now redirects to session[scope_return_to] if any ...
josevalim authored
17 respond_with resource, :location => after_sign_in_path_for(resource)
7ce49cb @carlosantoniodasilva Configuring session and password controllers as engine, and getting inte...
carlosantoniodasilva authored
18 end
19
15b76e9 @josevalim The default here is now DELETE.
josevalim authored
20 # DELETE /resource/sign_out
7ce49cb @carlosantoniodasilva Configuring session and password controllers as engine, and getting inte...
carlosantoniodasilva authored
21 def destroy
e4c5158 @josevalim Sign out by default will destroy the existing session.
josevalim authored
22 signed_in = signed_in?(resource_name)
9ea7249 @hinrik Allow specifying a resource_return_to for sign out
hinrik authored
23 redirect_path = after_sign_out_path_for(resource_name)
0487e9e @sikachu Add support for `destory_user_session_path` in another non-navigational ...
sikachu authored
24 Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
e4c5158 @josevalim Sign out by default will destroy the existing session.
josevalim authored
25 set_flash_message :notice, :signed_out if signed_in
0487e9e @sikachu Add support for `destory_user_session_path` in another non-navigational ...
sikachu authored
26
1e37e42 @josevalim Do not use stored location for sign out.
josevalim authored
27 # We actually need to hardcode this as Rails default responder doesn't
0487e9e @sikachu Add support for `destory_user_session_path` in another non-navigational ...
sikachu authored
28 # support returning empty response on GET request
29 respond_to do |format|
9ea7249 @hinrik Allow specifying a resource_return_to for sign out
hinrik authored
30 format.any(*navigational_formats) { redirect_to redirect_path }
5b94d9b @josevalim Refactor a bit navigational format responses, to not call to_sym and reu...
josevalim authored
31 format.all do
32 method = "to_#{request_format}"
33 text = {}.respond_to?(method) ? {}.send(method) : ""
34 render :text => text, :status => :ok
35 end
0487e9e @sikachu Add support for `destory_user_session_path` in another non-navigational ...
sikachu authored
36 end
7ce49cb @carlosantoniodasilva Configuring session and password controllers as engine, and getting inte...
carlosantoniodasilva authored
37 end
4a4dcb3 @josevalim sessions/new also responds to xml and json now
josevalim authored
38
39 protected
40
83c4755 @josevalim Extract auth_options into its own method.
josevalim authored
41 def serialize_options(resource)
3cedba1 @ches Fix optional enforcement of particular authentication keys
ches authored
42 methods = resource_class.authentication_keys.dup
43 methods = methods.keys if methods.is_a?(Hash)
44 methods << :password if resource.respond_to?(:password)
45 { :methods => methods, :only => [:password] }
4a4dcb3 @josevalim sessions/new also responds to xml and json now
josevalim authored
46 end
83c4755 @josevalim Extract auth_options into its own method.
josevalim authored
47
48 def auth_options
49 { :scope => resource_name, :recall => "#{controller_path}#new" }
50 end
3cedba1 @ches Fix optional enforcement of particular authentication keys
ches authored
51 end
52
Something went wrong with that request. Please try again.