Настройка видов в authy-devise
Я пытаюсь реализовать двухфакторную аутентификацию через authy 2FA
изtwilio
с помощью devise-authy
драгоценный камень.
Я хочу настроить представления с тремя страницами для 2FA.
первая страница - моя страница входа, где пользователь входит
username
а такжеpassword
,on submit
он будет перенаправлен на страницуВторая страница - на этой странице он может выбрать метод 2FA для получения кода по телефону или смс, после чего он перенаправляется
Третья страница - вот он наконец вводит код.
Я могу настроить первые две страницы.
Моя проблема в том, что на третьей странице, где я настраиваю authy form
для проверки кода я получаю ошибку undefined method id for nil class
<%= verify_authy_form do %>
<legend><%= I18n.t('submit_token_title', {:scope => 'devise'}) %></legend>
<%= label_tag :token %>
<%= text_field_tag :token, "", :autocomplete => :off, :id => 'authy-token' %>
<label>
<%= check_box_tag :remember_device %>
<span><%= I18n.t('remember_device', {:scope => 'devise'}) %></span>
</label>
<!-- Help tooltip -->
<!-- You need to configure a help message. -->
<!-- See documentation: https://github.com/authy/authy-form-helpers#help-tooltip -->
<!-- <%= link_to '?', '#', :id => 'authy-help' %> -->
<%= authy_request_sms_link %>
<%= authy_request_phone_call_link %>
<%= submit_tag I18n.t('submit_token', {:scope => 'devise'}), :class => 'btn' %>
<% end %>
Я получаю сообщение об ошибке в этой строке verify_authy_form При проверке кода gem я обнаружил, что мне нужно @authy_id
так что я попробовал <%@authy_id=User.find(session[:user_id]).authy_id%>
ввиду не все равно никакого успеха.
Это мое Users::AuthyCustomController
где я переопределил некоторые методы, как указано в гем
class Users::AuthyCustomController < Devise::DeviseAuthyController
protected
def after_authy_enabled_path_for(resource)
my_own_path
end
def after_authy_verified_path_for(resource)
my_own_path
end
def after_authy_disabled_path_for(resource)
my_own_path
end
def invalid_resource_path
my_own_path
end
def authentication_sms
end
def authentication_phone
@authy_id=User.find(session[:user_id]).authy_id
# redirect_to user_verify_authy_path
# redirect_to user_verify_authy_path and return
end
end
Я погуглил, но не смог найти решение
1 ответ
Я получаю ошибку
undefined method id for nil class
This is the form helper
def verify_authy_form(opts = {}, &block)
opts = default_opts.merge(:id => 'devise_authy').merge(opts)
form_tag([resource_name, :verify_authy], opts) do
buffer = hidden_field_tag(:"#{resource_name}_id", @resource.id)
buffer << capture(&block)
end
end
Я верю что @resource
является nil
so when it does @resource.id
triggers the error
I believe this form is managed from this controller action
# verify 2fa
def POST_verify_authy
token = Authy::API.verify({
:id => @resource.authy_id,
:token => params[:token],
:force => true
})
if token.ok?
@resource.update_attribute(:last_sign_in_with_authy, DateTime.now)
session["#{resource_name}_authy_token_checked"] = true
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)
else
handle_invalid_token :verify_authy, :invalid_token
end
end
and you can prove that by checking and including the relevant output from rake routes
, So maybe you should debug that two pieces of code, the controller action is responsible to feeding @resource
к form