Class: Devise::DeviseSafeguardController

Inherits:
DeviseController
  • Object
show all
Includes:
Controllers::Helpers
Defined in:
app/controllers/devise/devise_safeguard_controller.rb

Instance Method Summary collapse

Instance Method Details

#find_resourceObject



38
39
40
41
42
43
44
# File 'app/controllers/devise/devise_safeguard_controller.rb', line 38

def find_resource
  @resource = send("current_#{resource_name}")

  if @resource.nil?
    @resource = resource_class.find_by_id(session["#{resource_name}_id"])
  end
end

#find_resource_and_require_password_checkedObject



46
47
48
49
50
51
52
# File 'app/controllers/devise/devise_safeguard_controller.rb', line 46

def find_resource_and_require_password_checked
  find_resource

  if @resource.nil? || session[:"#{resource_name}_password_checked"].to_s != "true"
    redirect_to invalid_resource_path
  end
end

#GET_verify_safeguardObject



6
7
8
# File 'app/controllers/devise/devise_safeguard_controller.rb', line 6

def GET_verify_safeguard
  render 'verify_safeguard'
end

#invalid_resource_pathObject



54
55
56
# File 'app/controllers/devise/devise_safeguard_controller.rb', line 54

def invalid_resource_path
  root_path
end

#POST_verify_safeguardObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/devise/devise_safeguard_controller.rb', line 10

def POST_verify_safeguard
  if token_ok?
    @resource.update_attribute(:last_sign_in_with_safeguard, DateTime.now)

    #remember_device if params[:remember_device].to_i == 1
    if session.delete("#{resource_name}_remember_me") == true && @resource.respond_to?(:remember_me=)
      @resource.remember_me = true
    end
    (resource_name, @resource)

    set_flash_message(:notice, :signed_in) if is_navigational_format?
    respond_with resource, :location => (@resource)
  else
    set_flash_message(:error, :invalid_token)
    render :verify_safeguard
  end
end

#token_ok?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
# File 'app/controllers/devise/devise_safeguard_controller.rb', line 28

def token_ok?
  resp = Safeguard::API.is_valid?({
    :email => @resource.email,
    :token => params[:safeguard_token],
    :token_type => params[:token][:type]
  })
  resp
end