module Devise::Controllers::InternalHelpers
def build_resource(hash=nil)
def build_resource(hash=nil) hash ||= params[resource_name] || {} self.resource = resource_class.new(hash) end
def clean_up_passwords(object) #:nodoc:
def clean_up_passwords(object) #:nodoc: object.clean_up_passwords if object.respond_to?(:clean_up_passwords) end
def devise_controller?
def devise_controller? true end
def devise_mapping
def devise_mapping @devise_mapping ||= request.env["devise.mapping"] end
def is_devise_resource? #:nodoc:
Checks whether it's a devise mapped resource or not.
def is_devise_resource? #:nodoc: unknown_action! <<-MESSAGE unless devise_mapping not find devise mapping for path #{request.fullpath.inspect}. you forgot to wrap your route inside the scope block? For example: vise_scope :user do match "/some/route" => "some_devise_controller" d E end
def navigational_formats
def navigational_formats @navigational_formats ||= Devise.navigational_formats.select{ |format| Mime::EXTENSION_LOOKUP[format.to_s] } end
def require_no_authentication
Example:
Helper for use in before_filters where no authentication is required.
def require_no_authentication return unless is_navigational_format? no_input = devise_mapping.no_input_strategies args = no_input.dup.push :scope => resource_name if no_input.present? && warden.authenticate?(*args) resource = warden.user(resource_name) flash[:alert] = I18n.t("devise.failure.already_authenticated") redirect_to after_sign_in_path_for(resource) end end
def resource
def resource instance_variable_get(:"@#{resource_name}") end
def resource=(new_resource)
def resource=(new_resource) instance_variable_set(:"@#{resource_name}", new_resource) end
def resource_class
def resource_class devise_mapping.to end
def resource_name
def resource_name devise_mapping.name end
def respond_with_navigational(*args, &block)
def respond_with_navigational(*args, &block) respond_with(*args) do |format| format.any(*navigational_formats, &block) end end
def set_flash_message(key, kind, options={}) #:nodoc:
available.
Please refer to README or en.yml locale file to check what messages are
#resource_scope_messages
user:
#default_scope_messages - only if resource_scope is not found
passwords:
devise:
en:
Example (i18n locale file):
found we look to default scope.
to setup your messages using specific resource scope, and if no one is
Sets the flash message with :key, using I18n. By default you are able
def set_flash_message(key, kind, options={}) #:nodoc: options[:scope] = "devise.#{controller_name}" options[:default] = Array(options[:default]).unshift(kind.to_sym) options[:resource_name] = resource_name message = I18n.t("#{resource_name}.#{kind}", options) flash[key] = message if message.present? end
def signed_in_resource
def signed_in_resource warden.authenticate(:scope => resource_name) end
def successfully_sent?(resource)
If we are in paranoid mode, we always act as if the resource was valid
Helper for use after calling send_*_instructions methods on a resource.
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_navigational_format? true end end
def unknown_action!(msg)
def unknown_action!(msg) logger.debug "[Devise] #{msg}" if logger raise ActionController::UnknownAction, msg end