Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 111 lines (96 sloc) 3.588 kb
02e8c04 @josevalim Update views generator and now have scoped views.
josevalim authored
1 class Devise::RegistrationsController < ApplicationController
ac8221a @josevalim Add cancel to registrations controller as a way to delete information fr...
josevalim authored
2 prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ]
a5ba2ac @carlosantoniodasilva Use prepend_before_filter in require_no_authentication.
carlosantoniodasilva authored
3 prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
6b837cb @carlosantoniodasilva Introducing Registerable module, allowing users to sign up.
carlosantoniodasilva authored
4 include Devise::Controllers::InternalHelpers
5
c914c14 @zmack Fix typo in route description
zmack authored
6 # GET /resource/sign_up
8a15ac6 @josevalim Stub out other views for Registerable.
josevalim authored
7 def new
16666b7 @josevalim Get rid of flash hook and clean up passwords after registration.
josevalim authored
8 build_resource({})
8a15ac6 @josevalim Stub out other views for Registerable.
josevalim authored
9 render_with_scope :new
10 end
11
3f08665 @carlosantoniodasilva Fix RegistrationsController routes comments
carlosantoniodasilva authored
12 # POST /resource
6b837cb @carlosantoniodasilva Introducing Registerable module, allowing users to sign up.
carlosantoniodasilva authored
13 def create
8a15ac6 @josevalim Stub out other views for Registerable.
josevalim authored
14 build_resource
6b837cb @carlosantoniodasilva Introducing Registerable module, allowing users to sign up.
carlosantoniodasilva authored
15
16 if resource.save
02ae0c2 @josevalim Update CHANGELOG.
josevalim authored
17 if resource.active_for_authentication?
db1ce8e @josevalim Sign up now check if the user is active or not and redirect him accordin...
josevalim authored
18 set_flash_message :notice, :signed_up
19 sign_in_and_redirect(resource_name, resource)
20 else
21 set_flash_message :notice, :inactive_signed_up, :reason => resource.inactive_message.to_s
611261c @josevalim More tests for Omniauth.
josevalim authored
22 expire_session_data_after_sign_in!
db1ce8e @josevalim Sign up now check if the user is active or not and redirect him accordin...
josevalim authored
23 redirect_to after_inactive_sign_up_path_for(resource)
24 end
6b837cb @carlosantoniodasilva Introducing Registerable module, allowing users to sign up.
carlosantoniodasilva authored
25 else
16666b7 @josevalim Get rid of flash hook and clean up passwords after registration.
josevalim authored
26 clean_up_passwords(resource)
6b837cb @carlosantoniodasilva Introducing Registerable module, allowing users to sign up.
carlosantoniodasilva authored
27 render_with_scope :new
28 end
29 end
8a15ac6 @josevalim Stub out other views for Registerable.
josevalim authored
30
31 # GET /resource/edit
32 def edit
33 render_with_scope :edit
34 end
35
36 # PUT /resource
37 def update
901c6ae @josevalim Always get a new object on edit, update and delete.
josevalim authored
38 if resource.update_with_password(params[resource_name])
8a15ac6 @josevalim Stub out other views for Registerable.
josevalim authored
39 set_flash_message :notice, :updated
617e142 @josevalim Store the salt in session and expire the session if the user changes his...
josevalim authored
40 sign_in resource_name, resource, :bypass => true
d98882d @josevalim Tidy up previous commit.
josevalim authored
41 redirect_to after_update_path_for(resource)
8a15ac6 @josevalim Stub out other views for Registerable.
josevalim authored
42 else
16666b7 @josevalim Get rid of flash hook and clean up passwords after registration.
josevalim authored
43 clean_up_passwords(resource)
8a15ac6 @josevalim Stub out other views for Registerable.
josevalim authored
44 render_with_scope :edit
45 end
46 end
47
48 # DELETE /resource
49 def destroy
901c6ae @josevalim Always get a new object on edit, update and delete.
josevalim authored
50 resource.destroy
8a15ac6 @josevalim Stub out other views for Registerable.
josevalim authored
51 sign_out_and_redirect(self.resource)
e4c5158 @josevalim Sign out by default will destroy the existing session.
josevalim authored
52 set_flash_message :notice, :destroyed
8a15ac6 @josevalim Stub out other views for Registerable.
josevalim authored
53 end
54
ac8221a @josevalim Add cancel to registrations controller as a way to delete information fr...
josevalim authored
55 # GET /resource/cancel
56 # Forces the session data which is usually expired after sign
08da923 @josevalim Add more docs to the cancel action.
josevalim authored
57 # in to be expired now. This is useful if the user wants to
58 # cancel oauth signing in/up in the middle of the process,
59 # removing all OAuth session data.
ac8221a @josevalim Add cancel to registrations controller as a way to delete information fr...
josevalim authored
60 def cancel
61 expire_session_data_after_sign_in!
62 redirect_to new_registration_path(resource_name)
63 end
64
8a15ac6 @josevalim Stub out other views for Registerable.
josevalim authored
65 protected
66
ef841ca @josevalim Start to add helpers for OAuth tests.
josevalim authored
67 # Build a devise resource passing in the session. Useful to move
68 # temporary session data to the newly created user.
69 def build_resource(hash=nil)
70 hash ||= params[resource_name] || {}
71 self.resource = resource_class.new_with_session(hash, session)
72 end
73
ec5f8ae @josevalim Update RDoc.
josevalim authored
74 # The path used after sign up. You need to overwrite this method
75 # in your own RegistrationsController.
db1ce8e @josevalim Sign up now check if the user is active or not and redirect him accordin...
josevalim authored
76 def after_sign_up_path_for(resource)
77 after_sign_in_path_for(resource)
78 end
79
80 # Overwrite redirect_for_sign_in so it takes uses after_sign_up_path_for.
aac9c40 @josevalim Ensure after hooks are called on registrations controller, closes #852
josevalim authored
81 def redirect_location(scope, resource) #:nodoc:
82 stored_location_for(scope) || after_sign_up_path_for(resource)
db1ce8e @josevalim Sign up now check if the user is active or not and redirect him accordin...
josevalim authored
83 end
84
85 # The path used after sign up for inactive accounts. You need to overwrite
86 # this method in your own RegistrationsController.
87 def after_inactive_sign_up_path_for(resource)
88 root_path
89 end
90
91 # The default url to be used after updating a resource. You need to overwrite
92 # this method in your own RegistrationsController.
93 def after_update_path_for(resource)
94 if defined?(super)
95 ActiveSupport::Deprecation.warn "Defining after_update_path_for in ApplicationController " <<
96 "is deprecated. Please add a RegistrationsController to your application and define it there."
97 super
98 else
99 after_sign_in_path_for(resource)
100 end
101 end
102
901c6ae @josevalim Always get a new object on edit, update and delete.
josevalim authored
103 # Authenticates the current scope and gets a copy of the current resource.
104 # We need to use a copy because we don't want actions like update changing
105 # the current user in place.
8a15ac6 @josevalim Stub out other views for Registerable.
josevalim authored
106 def authenticate_scope!
0615c0a @josevalim Fix infinite redirect issues. Closes #787 and closes #795.
josevalim authored
107 send(:"authenticate_#{resource_name}!", true)
8a8ba6c @josevalim Depend on ORM Adapter.
josevalim authored
108 self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
8a15ac6 @josevalim Stub out other views for Registerable.
josevalim authored
109 end
c914c14 @zmack Fix typo in route description
zmack authored
110 end
Something went wrong with that request. Please try again.