Class: Devise::RegistrationsController

Inherits:
DeviseController show all
Defined in:
app/controllers/devise/registrations_controller.rb

Instance Method Summary collapse

Instance Method Details

#account_update_paramsObject (protected)



123
124
125
# File 'app/controllers/devise/registrations_controller.rb', line 123

def 
  devise_parameter_sanitizer.for(: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.



103
104
105
# File 'app/controllers/devise/registrations_controller.rb', line 103

def (resource)
  respond_to?(:root_path) ? 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.



97
98
99
# File 'app/controllers/devise/registrations_controller.rb', line 97

def (resource)
  (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.



109
110
111
# File 'app/controllers/devise/registrations_controller.rb', line 109

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.



114
115
116
117
# File 'app/controllers/devise/registrations_controller.rb', line 114

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.



85
86
87
# File 'app/controllers/devise/registrations_controller.rb', line 85

def build_resource(hash=nil)
  self.resource = resource_class.new_with_session(hash || {}, session)
end

#cancelObject

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.



70
71
72
73
# File 'app/controllers/devise/registrations_controller.rb', line 70

def cancel
  expire_session_data_after_sign_in!
  redirect_to new_registration_path(resource_name)
end

#createObject

POST /resource



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/devise/registrations_controller.rb', line 12

def create
  build_resource()

  if resource.save
    if resource.active_for_authentication?
      set_flash_message :notice, :signed_up if is_navigational_format?
      (resource_name, resource)
      respond_with resource, :location => (resource)
    else
      set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
      expire_session_data_after_sign_in!
      respond_with resource, :location => (resource)
    end
  else
    clean_up_passwords resource
    respond_with resource
  end
end

#destroyObject

DELETE /resource



58
59
60
61
62
63
# File 'app/controllers/devise/registrations_controller.rb', line 58

def destroy
  resource.destroy
  Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
  set_flash_message :notice, :destroyed if is_navigational_format?
  respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
end

#editObject

GET /resource/edit



32
33
34
# File 'app/controllers/devise/registrations_controller.rb', line 32

def edit
  render :edit
end

#newObject

GET /resource/sign_up



6
7
8
9
# File 'app/controllers/devise/registrations_controller.rb', line 6

def new
  build_resource({})
  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.



91
92
93
# File 'app/controllers/devise/registrations_controller.rb', line 91

def (resource_name, resource)
  (resource_name, resource)
end

#sign_up_paramsObject (protected)



119
120
121
# File 'app/controllers/devise/registrations_controller.rb', line 119

def 
  devise_parameter_sanitizer.for(:sign_up)
end

#updateObject

PUT /resource We need to use a copy of the resource because we don’t want to change the current user in place.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/devise/registrations_controller.rb', line 39

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)

  if resource.update_with_password()
    if is_navigational_format?
      flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
        :update_needs_confirmation : :updated
      set_flash_message :notice, flash_key
    end
     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)

Returns:

  • (Boolean)


77
78
79
80
81
# File 'app/controllers/devise/registrations_controller.rb', line 77

def update_needs_confirmation?(resource, previous)
  resource.respond_to?(:pending_reconfirmation?) &&
    resource.pending_reconfirmation? &&
    previous != resource.unconfirmed_email
end