Class: DeviseToken::AuthenticationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/devise_token/authentications_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#resource_data, #resource_errors

Instance Method Details

#createObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/devise_token/authentications_controller.rb', line 8

def create
  # Check
  field = (resource_params.keys.map(&:to_sym) & resource_class.authentication_keys).first

  @resource = nil
  if field
    q_value = get_case_insensitive_field_from_resource_params(field)

    @resource = find_resource(field, q_value)
  end

  if @resource && valid_params?(field, q_value) && (!@resource.respond_to?(:active_for_authentication?) || @resource.active_for_authentication?)
    valid_password = @resource.valid_password?(resource_params[:password])
    if (@resource.respond_to?(:valid_for_authentication?) && !@resource.valid_for_authentication? { valid_password }) || !valid_password
      render_create_error_bad_credentials
      return
    end

    @resource.save

    (:user, @resource, store: false, bypass: false)

    yield @resource if block_given?

    render_create_success

  elsif @resource && !(!@resource.respond_to?(:active_for_authentication?) || @resource.active_for_authentication?)
    render_create_error_not_confirmed
  else
    render_create_error_bad_credentials
  end
end

#newObject



4
5
6
# File 'app/controllers/devise_token/authentications_controller.rb', line 4

def new
  render_new_error
end