/ / कस्टम सत्र नियंत्रक के साथ मुझे दो कारक प्रमाणीकरण को कैसे एकीकृत करना चाहिए? - रूबी-ऑन-रेल, रूबी, रूबी-ऑन-रेल -4, तैयार करें

कस्टम सत्र नियंत्रक के साथ मुझे दो कारक प्रमाणीकरण को कैसे एकीकृत करना चाहिए? - रूबी-ऑन-रेल, रूबी, रूबी-ऑन-रेल -4, तैयार करें

मैंने हुडिनी को मौजूदा रेल अनुप्रयोगों के साथ दो कारक प्रमाणीकरण एकीकृत किया।
सबसे पहले मेरे पास कोई कस्टम session_controller नहीं है दो तरीकों से प्रमाणीकरण ठीक काम कर रहा है
लेकिन जब मैंने कस्टम कंट्रोलर में कस्टम बिल्ड एक्शन लिखा था तो यह प्रमाणित नहीं है दो तरीकों से प्रमाणीकरण.

सत्र नियंत्रक की कार्रवाई बनाने के लिए कस्टम कोड यहां दिया गया है।

  if status_response.nil?
render :file => "public/api_not_found.html", :status => :not_found, :layout => false
else
if status_response["code"].to_i == 1
signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
flash[:alert] = "Invalid Email ID or password."
yield if block_given?
respond_to_on_destroy
else
self.resource = warden.authenticate!(auth_options)
set_flash_message(:notice, :signed_in) if is_flashing_format?
sign_in(resource_name, resource)
yield resource if block_given?
respond_with resource, location: after_sign_in_path_for(resource)
end
end

User.rb का मॉडल कोड:

  devise :two_factor_authenticatable, :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:confirmable, password_length: 8..30
has_one_time_password


def send_two_factor_authentication_code
puts ">>>>>>>>>>>>>>> otp_secret_key: #{otp_secret_key}, otp_code: #{otp_code}"
end

मुझे पता है कि क्या हम सत्र नियंत्रक की निर्माण कार्य को अनुकूलित कर रहे हैं तो हमें कॉल करना चाहिए दो तरीकों से प्रमाणीकरण। मैंने इसे नियंत्रक में आमंत्रित करने की कोशिश की लेकिन यह एक त्रुटि फेंकता है।

तो मेरा सवाल है कि मैं कैसे एकीकृत करना चाहिए दो तरीकों से प्रमाणीकरण सत्र नियंत्रक की कस्टम निर्माण कार्रवाई के साथ?

उत्तर:

जवाब के लिए 0 № 1

ऐसा लगता है कि मैं बस सुपर का उपयोग करना चाहता था।

    if status_response.nil?
render :file => "public/api_not_found.html", :status => :not_found, :layout => false
else
if status_response["code"].to_i == 1
#If this is true then I didn"t got auth_tok from API therefore i forcefully signed out the user.
else
super
end
end

तो यहां मैं उपयोगकर्ता की प्रतिक्रिया की जांच कर रहा हूं और इसके आधार पर मैं उपयोगकर्ता को साइन इन करने की अनुमति देना चाहता हूं।
और दूसरी बात यह है कि डेटाबेस में otp_code शून्य नहीं होना चाहिए। यदि यह शून्य है तो 2 एफए काम नहीं करेगा। यह otp_code पूछे बिना बस रूट पर रीडायरेक्ट करता है।