Class: DeviseTokenAuth::SessionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/devise_token_auth/sessions_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#resource_data, #resource_errors

Instance Method Details

#createObject



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
40
41
42
43
# File 'app/controllers/devise_token_auth/sessions_controller.rb', line 13

def create
  if field = (resource_params.keys.map(&:to_sym) & resource_class.authentication_keys).first
    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
      return render_create_error_bad_credentials
    end

    create_and_assign_token

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

    yield @resource if block_given?

    render_create_success
  elsif @resource && !Devise.paranoid && !(!@resource.respond_to?(:active_for_authentication?) || @resource.active_for_authentication?)
    if @resource.respond_to?(:locked_at) && @resource.locked_at
      
    else
      render_create_error_not_confirmed
    end
  else
    hash_password_in_paranoid_mode
    render_create_error_bad_credentials
  end
end

#destroyObject



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

def destroy
  # remove auth instance variables so that after_action does not run
  user = remove_instance_variable(:@resource) if @resource
  client = @token.client
  @token.clear!

  if user && client && user.tokens[client]
    user.tokens.delete(client)
    user.save!

    if DeviseTokenAuth.cookie_enabled
      # If a cookie is set with a domain specified then it must be deleted with that domain specified
      # See https://api.rubyonrails.org/classes/ActionDispatch/Cookies.html
      cookies.delete(DeviseTokenAuth.cookie_name, domain: DeviseTokenAuth.cookie_attributes[:domain])
    end

    yield user if block_given?

    render_destroy_success
  else
    render_destroy_error
  end
end

#newObject



9
10
11
# File 'app/controllers/devise_token_auth/sessions_controller.rb', line 9

def new
  render_new_error
end