私のアプリでdevise gemを使用しています。サインイン中にユーザーモデルからメソッドを渡すために使用するコールバックは何ですか?ブール値をtrueまたはfalseに変更するためのログイン処理中のコールバック
Warden::Manager.after_set_user ? before_validation? before_save? before_create?
方法の詳細:ユーザーテーブルのis_active: 私はブール値の列を持っています。 ユーザーがサインインしようとするたびに、braintreeコードは、ユーザーがbraintree APIを介してアクティブな購読をしているかどうかを確認します。また、ユーザーがアクティブであるかどうかに関わらず、is_active列をtrueまたはfalseに更新しようとしています。
私は現在、これを使用していますが、それは働いていない:
Warden::Manager.after_set_user :scope => :user do |user, auth, opts|
customer = Braintree::Customer.find('customer_id')
customer_card = customer.payment_methods[0].token
payment_method = Braintree::PaymentMethod.find(customer_card)
sub = payment_method.subscriptions[0]
sub.status
if Braintree::Subscription::Status::Active
obj = User.find_by_id(params[:id])
obj.is_active = true
obj.save!
else
obj = User.find_by_id(params[:id])
obj.is_active = false
obj.save!
end
end
def active_for_authentication?
super && is_active?
end
def inactive_message
"User not active, please subscribe!"
end
返信いただきありがとうございます@coreyward!私が持っているもう一つの質問は 'Warden :: Manager.after_set_user'以外のコールバックを使うべきでしょうか? – Theopap