Method: Devise::Controllers::Helpers#sign_in

Defined in:
lib/devise/controllers/helpers.rb

#sign_in(resource_or_scope, *args) ⇒ Object

Sign in a user that already was authenticated. This helper is useful for logging users in after sign up.

All options given to sign_in is passed forward to the set_user method in warden. The only exception is the :bypass option, which bypass warden callbacks and stores the user straight in session. This option is useful in cases the user is already signed in, but we want to refresh the credentials in session.

Examples:

 :user, @user                      # sign_in(scope, resource)
 @user                             # sign_in(resource)
 @user, :event => :authentication  # sign_in(resource, options)
 @user, :bypass => true            # sign_in(resource, options)


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/devise/controllers/helpers.rb', line 109

def (resource_or_scope, *args)
  options  = args.extract_options!
  scope    = Devise::Mapping.find_scope!(resource_or_scope)
  resource = args.last || resource_or_scope

  expire_session_data_after_sign_in!

  if options[:bypass]
    warden.session_serializer.store(resource, scope)
  elsif warden.user(scope) == resource && !options.delete(:force)
    # Do nothing. User already signed in and we are not forcing it.
    true
  else
    warden.set_user(resource, options.merge!(:scope => scope))
  end
end