简体   繁体   English

无需密码即可设计自定义身份验证

[英]Devise custom authentication without a password

In my app I need to have a database authentication but without a password. 在我的应用程序中,我需要进行数据库身份验证,但没有密码。 Just by entering your phone number. 只需输入您的电话号码即可。 When the user sings up he enter phone number, adress and name and no password. 当用户唱歌时,他输入电话号码,地址和姓名,没有密码。

Is it real? 这是真的吗? Just can't figure out how to make it. 只是无法弄清楚如何制作它。

Thanks for help in advance! 提前感谢您的帮助!

Figured out like this: 像这样想出来:

In devise_no_pass.rb initializer add: 在devise_no_pass.rb初始化器中添加:

require 'devise/strategies/authenticatable'

module Devise
  module Strategies
    class DeviseNoPass < Authenticatable
      def authenticate!
        return super unless params[:customer_sign_in]
        customer = Customer.find_by_phone(params[:customer_sign_in]
        customer ? success!(customer) : raise
      end
    end
  end
end

Warden::Strategies.add(:devise_no_pass, Devise::Strategies::DeviseNoPass)

In devise.rb: 在devise.rb中:

    config.warden do |manager|
      manager.default_strategies(:scope => :customer).unshift :devise_no_pass
    end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM