使用 Authy、Twilio 和 Devise 仅向 rails 应用程序添加验证
Adding Verification only to rails app with Authy, Twillio and Devise
我正在使用 Rails 5、Ruby 2.4.0 构建一个调度应用程序,并希望将 Twillio 用于 SMS Authy(仅用于 phone 验证)和 Devise 用于用户身份验证.
我的问题是遵循 Twillio 教程 Twillio Authy verification tutroial 我是想为此工作流程创建一个自定义设备注册控制器,还是创建一个自定义用户控制器来处理这个更好?
我的应用程序现在是通过帐户创建操作中的嵌套表单创建 "owner" 一个 class 用户。我只是不确定我是否会通过我的帐户控制器在创建用户时点击用户控制器..?
这是一个垃圾问题,但我真的迷失在这里不知道如何进行。
将 SMS 验证融入标准设计流程似乎是一个绝妙的主意,而不是重复功能。幸运的是它很简单:
class TwillioRegistrationsController < Devise::RegistrationsController
def create
super do |user|
authy = Authy::API.register_user(
email: user.email,
cellphone: user.phone_number,
country_code: user.country_code
)
user.update(authy_id: authy.id)
end
end
protected
def after_sign_up_path_for(resource)
"users/verify"
end
end
Devise 让您 "tap" 通过屈服进入几乎所有控制器方法的流程。 Devise::RegistrationsController#create
在资源保存后生成资源,这是放置 twillio 逻辑的完美位置。
然后您需要 permit the additional parameters in devise and customize the form 添加其他字段。
class ApplicationController < ActionController::Base
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:phone_number, :country_code])
end
end
请注意,您仍然需要设置一个控制器来处理验证,但您可以按照教程进行操作。
我正在使用 Rails 5、Ruby 2.4.0 构建一个调度应用程序,并希望将 Twillio 用于 SMS Authy(仅用于 phone 验证)和 Devise 用于用户身份验证.
我的问题是遵循 Twillio 教程 Twillio Authy verification tutroial 我是想为此工作流程创建一个自定义设备注册控制器,还是创建一个自定义用户控制器来处理这个更好?
我的应用程序现在是通过帐户创建操作中的嵌套表单创建 "owner" 一个 class 用户。我只是不确定我是否会通过我的帐户控制器在创建用户时点击用户控制器..?
这是一个垃圾问题,但我真的迷失在这里不知道如何进行。
将 SMS 验证融入标准设计流程似乎是一个绝妙的主意,而不是重复功能。幸运的是它很简单:
class TwillioRegistrationsController < Devise::RegistrationsController
def create
super do |user|
authy = Authy::API.register_user(
email: user.email,
cellphone: user.phone_number,
country_code: user.country_code
)
user.update(authy_id: authy.id)
end
end
protected
def after_sign_up_path_for(resource)
"users/verify"
end
end
Devise 让您 "tap" 通过屈服进入几乎所有控制器方法的流程。 Devise::RegistrationsController#create
在资源保存后生成资源,这是放置 twillio 逻辑的完美位置。
然后您需要 permit the additional parameters in devise and customize the form 添加其他字段。
class ApplicationController < ActionController::Base
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:phone_number, :country_code])
end
end
请注意,您仍然需要设置一个控制器来处理验证,但您可以按照教程进行操作。