Class: Devise::RegistrationsController
- Inherits:
-
DeviseController
- Object
- DeviseController
- Devise::RegistrationsController
- Defined in:
- app/controllers/devise/registrations_controller.rb
Instance Method Summary collapse
- #account_update_params ⇒ Object protected
-
#after_inactive_sign_up_path_for(resource) ⇒ Object
protected
The path used after sign up for inactive accounts.
-
#after_sign_up_path_for(resource) ⇒ Object
protected
The path used after sign up.
-
#after_update_path_for(resource) ⇒ Object
protected
The default url to be used after updating a resource.
-
#authenticate_scope! ⇒ Object
protected
Authenticates the current scope and gets the current resource from the session.
-
#build_resource(hash = nil) ⇒ Object
protected
Build a devise resource passing in the session.
-
#cancel ⇒ Object
GET /resource/cancel Forces the session data which is usually expired after sign in to be expired now.
-
#create {|resource| ... } ⇒ Object
POST /resource.
-
#destroy {|resource| ... } ⇒ Object
DELETE /resource.
-
#edit ⇒ Object
GET /resource/edit.
-
#new ⇒ Object
GET /resource/sign_up.
-
#sign_up(resource_name, resource) ⇒ Object
protected
Signs in a user on sign up.
- #sign_up_params ⇒ Object protected
-
#update {|resource| ... } ⇒ Object
PUT /resource We need to use a copy of the resource because we don’t want to change the current user in place.
- #update_needs_confirmation?(resource, previous) ⇒ Boolean protected
-
#update_resource(resource, params) ⇒ Object
protected
By default we want to require a password checks on update.
Instance Method Details
#account_update_params ⇒ Object (protected)
145 146 147 |
# File 'app/controllers/devise/registrations_controller.rb', line 145 def account_update_params devise_parameter_sanitizer.sanitize(:account_update) end |
#after_inactive_sign_up_path_for(resource) ⇒ Object (protected)
The path used after sign up for inactive accounts. You need to overwrite this method in your own RegistrationsController.
122 123 124 125 126 127 |
# File 'app/controllers/devise/registrations_controller.rb', line 122 def after_inactive_sign_up_path_for(resource) scope = Devise::Mapping.find_scope!(resource) router_name = Devise.mappings[scope].router_name context = router_name ? send(router_name) : self context.respond_to?(:root_path) ? context.root_path : "/" end |
#after_sign_up_path_for(resource) ⇒ Object (protected)
The path used after sign up. You need to overwrite this method in your own RegistrationsController.
116 117 118 |
# File 'app/controllers/devise/registrations_controller.rb', line 116 def after_sign_up_path_for(resource) after_sign_in_path_for(resource) end |
#after_update_path_for(resource) ⇒ Object (protected)
The default url to be used after updating a resource. You need to overwrite this method in your own RegistrationsController.
131 132 133 |
# File 'app/controllers/devise/registrations_controller.rb', line 131 def after_update_path_for(resource) signed_in_root_path(resource) end |
#authenticate_scope! ⇒ Object (protected)
Authenticates the current scope and gets the current resource from the session.
136 137 138 139 |
# File 'app/controllers/devise/registrations_controller.rb', line 136 def authenticate_scope! send(:"authenticate_#{resource_name}!", force: true) self.resource = send(:"current_#{resource_name}") end |
#build_resource(hash = nil) ⇒ Object (protected)
Build a devise resource passing in the session. Useful to move temporary session data to the newly created user.
104 105 106 |
# File 'app/controllers/devise/registrations_controller.rb', line 104 def build_resource(hash=nil) self.resource = resource_class.new_with_session(hash || {}, session) end |
#cancel ⇒ Object
GET /resource/cancel Forces the session data which is usually expired after sign in to be expired now. This is useful if the user wants to cancel oauth signing in/up in the middle of the process, removing all OAuth session data.
83 84 85 86 |
# File 'app/controllers/devise/registrations_controller.rb', line 83 def cancel expire_data_after_sign_in! redirect_to new_registration_path(resource_name) end |
#create {|resource| ... } ⇒ Object
POST /resource
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/devise/registrations_controller.rb', line 16 def create build_resource(sign_up_params) resource_saved = resource.save yield resource if block_given? if resource_saved if resource.active_for_authentication? :notice, :signed_up if is_flashing_format? sign_up(resource_name, resource) respond_with resource, location: after_sign_up_path_for(resource) else :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format? expire_data_after_sign_in! respond_with resource, location: after_inactive_sign_up_path_for(resource) end else clean_up_passwords resource @validatable = devise_mapping.validatable? if @validatable @minimum_password_length = resource_class.password_length.min end respond_with resource end end |
#destroy {|resource| ... } ⇒ Object
DELETE /resource
70 71 72 73 74 75 76 |
# File 'app/controllers/devise/registrations_controller.rb', line 70 def destroy resource.destroy Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name) :notice, :destroyed if is_flashing_format? yield resource if block_given? (resource){ redirect_to after_sign_out_path_for(resource_name) } end |
#edit ⇒ Object
GET /resource/edit
42 43 44 |
# File 'app/controllers/devise/registrations_controller.rb', line 42 def edit render :edit end |
#new ⇒ Object
GET /resource/sign_up
6 7 8 9 10 11 12 13 |
# File 'app/controllers/devise/registrations_controller.rb', line 6 def new build_resource({}) @validatable = devise_mapping.validatable? if @validatable @minimum_password_length = resource_class.password_length.min end respond_with self.resource end |
#sign_up(resource_name, resource) ⇒ Object (protected)
Signs in a user on sign up. You can overwrite this method in your own RegistrationsController.
110 111 112 |
# File 'app/controllers/devise/registrations_controller.rb', line 110 def sign_up(resource_name, resource) sign_in(resource_name, resource) end |
#sign_up_params ⇒ Object (protected)
141 142 143 |
# File 'app/controllers/devise/registrations_controller.rb', line 141 def sign_up_params devise_parameter_sanitizer.sanitize(:sign_up) end |
#update {|resource| ... } ⇒ Object
PUT /resource We need to use a copy of the resource because we don’t want to change the current user in place.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/controllers/devise/registrations_controller.rb', line 49 def update self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key) prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email) resource_updated = update_resource(resource, account_update_params) yield resource if block_given? if resource_updated if is_flashing_format? flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ? :update_needs_confirmation : :updated :notice, flash_key end sign_in resource_name, resource, bypass: true respond_with resource, location: after_update_path_for(resource) else clean_up_passwords resource respond_with resource end end |
#update_needs_confirmation?(resource, previous) ⇒ Boolean (protected)
90 91 92 93 94 |
# File 'app/controllers/devise/registrations_controller.rb', line 90 def update_needs_confirmation?(resource, previous) resource.respond_to?(:pending_reconfirmation?) && resource.pending_reconfirmation? && previous != resource.unconfirmed_email end |
#update_resource(resource, params) ⇒ Object (protected)
By default we want to require a password checks on update. You can overwrite this method in your own RegistrationsController.
98 99 100 |
# File 'app/controllers/devise/registrations_controller.rb', line 98 def update_resource(resource, params) resource.update_with_password(params) end |