class DeviseController

All Devise controllers are inherited from here.

Protected Instance Methods

clean_up_passwords(object) click to toggle source
# File app/controllers/devise_controller.rb, line 184
def clean_up_passwords(object)
  object.clean_up_passwords if object.respond_to?(:clean_up_passwords)
end
devise_i18n_options(options) click to toggle source
# File app/controllers/devise_controller.rb, line 164
def devise_i18n_options(options)
  options
end
devise_mapping() click to toggle source

Attempt to find the mapped route for devise based on request path

# File app/controllers/devise_controller.rb, line 53
def devise_mapping
  @devise_mapping ||= request.env["devise.mapping"]
end
find_message(kind, options = {}) click to toggle source

Get message for given

# File app/controllers/devise_controller.rb, line 169
def find_message(kind, options = {})
  options[:scope] ||= translation_scope
  options[:default] = Array(options[:default]).unshift(kind.to_sym)
  options[:resource_name] = resource_name
  options = devise_i18n_options(options)
  I18n.t("#{options[:resource_name]}.#{kind}", options)
end
navigational_formats() click to toggle source

Returns real navigational formats which are supported by Rails

require_no_authentication() click to toggle source

Helper for use in before_filters where no authentication is required.

Example:

before_filter :require_no_authentication, only: :new
# File app/controllers/devise_controller.rb, line 96
def require_no_authentication
  assert_is_devise_resource!
  return unless is_navigational_format?
  no_input = devise_mapping.no_input_strategies

  authenticated = if no_input.present?
    args = no_input.dup.push scope: resource_name
    warden.authenticate?(*args)
  else
    warden.authenticated?(resource_name)
  end

  if authenticated && resource = warden.user(resource_name)
    flash[:alert] = I18n.t("devise.failure.already_authenticated")
    redirect_to after_sign_in_path_for(resource)
  end
end
resource() click to toggle source

Gets the actual resource stored in the instance variable

# File app/controllers/devise_controller.rb, line 32
def resource
  instance_variable_get(:"@#{resource_name}")
end
resource=(new_resource) click to toggle source

Sets the resource creating an instance variable

# File app/controllers/devise_controller.rb, line 88
def resource=(new_resource)
  instance_variable_set(:"@#{resource_name}", new_resource)
end
resource_class() click to toggle source

Proxy to devise map class

# File app/controllers/devise_controller.rb, line 43
def resource_class
  devise_mapping.to
end
resource_name() click to toggle source

Proxy to devise map name

# File app/controllers/devise_controller.rb, line 37
def resource_name
  devise_mapping.name
end
Also aliased as: scope_name
resource_params() click to toggle source
# File app/controllers/devise_controller.rb, line 194
def resource_params
  params.fetch(resource_name, {})
end
respond_with_navigational(*args, &block) click to toggle source
# File app/controllers/devise_controller.rb, line 188
def respond_with_navigational(*args, &block)
  respond_with(*args) do |format|
    format.any(*navigational_formats, &block)
  end
end
scope_name() click to toggle source
Alias for: resource_name
set_flash_message(key, kind, options = {}) click to toggle source

Sets the flash message with :key, using I18n. By default you are able to setup your messages using specific resource scope, and if no message is found we look to the default scope. Set the “now” options key to a true value to populate the flash.now hash in lieu of the default flash hash (so the flash message will be available to the current action instead of the next action). Example (i18n locale file):

en:
  devise:
    passwords:
      #default_scope_messages - only if resource_scope is not found
      user:
        #resource_scope_messages

Please refer to README or en.yml locale file to check what messages are available.

# File app/controllers/devise_controller.rb, line 148
def set_flash_message(key, kind, options = {})
  message = find_message(kind, options)
  if options[:now]
    flash.now[key] = message if message.present?
  else
    flash[key] = message if message.present?
  end
end
set_minimum_password_length() click to toggle source

Sets minimum password length to show to user

# File app/controllers/devise_controller.rb, line 158
def set_minimum_password_length
  if devise_mapping.validatable?
    @minimum_password_length = resource_class.password_length.min
  end
end
signed_in_resource() click to toggle source

Returns a signed in resource from session (if one exists)

# File app/controllers/devise_controller.rb, line 48
def signed_in_resource
  warden.authenticate(scope: resource_name)
end
successfully_sent?(resource) click to toggle source

Helper for use after calling send_*_instructions methods on a resource. If we are in paranoid mode, we always act as if the resource was valid and instructions were sent.

# File app/controllers/devise_controller.rb, line 117
def successfully_sent?(resource)
  notice = if Devise.paranoid
    resource.errors.clear
    :send_paranoid_instructions
  elsif resource.errors.empty?
    :send_instructions
  end

  if notice
    set_flash_message :notice, notice if is_flashing_format?
    true
  end
end
translation_scope() click to toggle source

Controllers inheriting DeviseController are advised to override this method so that other controllers inheriting from them would use existing translations.

# File app/controllers/devise_controller.rb, line 180
def translation_scope
  "devise.#{controller_name}"
end
unknown_action!(msg) click to toggle source
# File app/controllers/devise_controller.rb, line 82
def unknown_action!(msg)
  logger.debug "[Devise] #{msg}" if logger
  raise AbstractController::ActionNotFound, msg
end