[英]How to register devise login event?
I am using Devise and Omniauth to offer login via native(devise), facebook and google+ 我正在使用Devise和Omniauth通过native(devise),facebook和google +提供登录
Users can theoretically login with any method in succession and I would like to register the last method of authentication. 从理论上讲,用户可以使用任何方法连续登录,我想注册最后一种身份验证方法。 For Facebook and G+ I am able to record it in the find_* method on my user table but Devise 'native' auth is a closed book.
对于Facebook和G +,我可以将其记录在用户表的find_ *方法中,但是Devise'native'auth已关闭。
The best approach i can think of is to update a session variable in a controller just prior to login and then use a warden authentication callback or subclass the sessions controller 我能想到的最佳方法是在登录之前更新控制器中的会话变量,然后使用监护人身份验证回调或将会话控制器子类化
as here: Ruby on Rails Devise code after login 如下所示: 登录后的Ruby on Rails Devise代码
to update the user with the auth type straight after but it seems a little messy. 之后立即使用auth类型更新用户,但似乎有些混乱。
Devise has a method that you can call, which will run after database auth in your user model, you could then update the attribute here. Devise有一个可以调用的方法,该方法将在用户模型中的数据库身份验证后运行,然后可以在此处更新属性。
class User < ActiveRecord::Base
...
devise :database_authenticatable, :omniauthable ....
...
def after_database_authentication
update_attribute(:auth_type, 'database')
end
...
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.