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)



143
144
145
# File 'app/controllers/devise/registrations_controller.rb', line 143

def 
  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.



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

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



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

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.



129
130
131
# File 'app/controllers/devise/registrations_controller.rb', line 129

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.



134
135
136
137
# File 'app/controllers/devise/registrations_controller.rb', line 134

def authenticate_scope!
  send(:authenticate_#{resource_name}!", force: true)
  self.resource = send(:current_#{resource_name}")
end

#build_resource(hash = {}) ⇒ Object (protected)

Build a devise resource passing in the session. Useful to move temporary session data to the newly created user.



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

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



81
82
83
84
# File 'app/controllers/devise/registrations_controller.rb', line 81

def cancel
  expire_data_after_sign_in!
  redirect_to new_registration_path(resource_name)
end

#create {|resource| ... } ⇒ Object

POST /resource

Yields:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/devise/registrations_controller.rb', line 16

def create
  build_resource()

  resource.save
  yield resource if block_given?
  if resource.persisted?
    if resource.active_for_authentication?
      set_flash_message! :notice, :signed_up
      (resource_name, resource)
      respond_with resource, location: (resource)
    else
      set_flash_message! :notice, :signed_up_but_#{resource.inactive_message}"
      expire_data_after_sign_in!
      respond_with resource, location: (resource)
    end
  else
    clean_up_passwords resource
    set_minimum_password_length
    respond_with resource
  end
end

#destroy {|resource| ... } ⇒ Object

DELETE /resource

Yields:



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

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

#editObject

GET /resource/edit



39
40
41
# File 'app/controllers/devise/registrations_controller.rb', line 39

def edit
  render :edit
end

#new {|resource| ... } ⇒ Object

GET /resource/sign_up

Yields:



9
10
11
12
13
# File 'app/controllers/devise/registrations_controller.rb', line 9

def new
  build_resource
  yield resource if block_given?
  respond_with 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.



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

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

#sign_up_paramsObject (protected)



139
140
141
# File 'app/controllers/devise/registrations_controller.rb', line 139

def 
  devise_parameter_sanitizer.sanitize(:sign_up)
end

#translation_scopeObject (protected)



147
148
149
# File 'app/controllers/devise/registrations_controller.rb', line 147

def translation_scope
  'devise.registrations'
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.

Yields:



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/devise/registrations_controller.rb', line 46

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, )
  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
      set_flash_message :notice, flash_key
    end
     resource, scope: resource_name
    respond_with resource, location: after_update_path_for(resource)
  else
    clean_up_passwords resource
    set_minimum_password_length
    respond_with resource
  end
end

#update_needs_confirmation?(resource, previous) ⇒ Boolean (protected)

Returns:

  • (Boolean)


88
89
90
91
92
# File 'app/controllers/devise/registrations_controller.rb', line 88

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.



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

def update_resource(resource, params)
  resource.update_with_password(params)
end