Sha256: 0b9e71acb4a2088d29410b3361c33d0902c2878c75bd7a7bac0cc00f5376c7d9

Contents?: true

Size: 1.78 KB

Versions: 2

Compression:

Stored size: 1.78 KB

Contents

class Devise::Instant2faController < DeviseController
  if self.respond_to?(:prepend_before_action)
    prepend_before_action :find_resource_and_require_password_checked, :only => [
      :show, :update
    ]
  else
    prepend_before_filter :find_resource_and_require_password_checked, :only => [
      :show, :update
    ]
  end

  def show
    @hosted_page_url = session["#{resource_name}_hosted_page_url"]
  end

  def update
    render :show and return if params[:instant2faToken].nil?

    begin
      Instant2fa.confirm_verification(@resource.id.to_s, params[:instant2faToken])
      after_two_factor_success_for(@resource)
    rescue Instant2fa::Errors::VerificationMismatch
      after_two_factor_fail_for(@resource)
    rescue Instant2fa::Errors::VerificationFailed
      after_two_factor_fail_for(@resource)
    end
  end

  private

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

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

  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

  def after_two_factor_success_for(resource)
    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
    sign_in(resource_name, resource)

    set_flash_message(:notice, :signed_in) if is_navigational_format?
    respond_with resource, :location => after_sign_in_path_for(resource)
  end

  def after_two_factor_fail_for(resource)
    set_flash_message :alert, :attempt_failed, now: true
    sign_out(resource)
    redirect_to :root
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
devise_instant2fa-1.0.2 app/controllers/devise/instant2fa_controller.rb
devise_instant2fa-1.0.1 app/controllers/devise/instant2fa_controller.rb