简体   繁体   English

如何注册设备登录事件?

[英]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.

相关问题 设计注册和登录栏 - Devise register and login rails 设计:允许用户注册为“UsErNaMe”,但使用“用户名”登录 - Devise: Allow users to register as “UsErNaMe” but login with “username” 使用Rails remote设计ajax登录/注册:true - Devise ajax login/register with Rails remote: true 如何使用 Rails 和 devise 检测登录事件,以便将登录事件推送到数据层? - How to detect a login event with Rails and devise in order to push login event into datalayer? 即使没有通过电子邮件链接确认电子邮件,如何配置设备使用户登录? - How to config devise to make user login after register even without confirm email via email link? 用户登录或注册时,如何覆盖devise以重定向到除根以外的其他URL? - How to override devise to redirect to a different URL other than the root when user login or register? Rails 5:禁用对Devise注册和登录表单页面的访问 - Rails 5: disable access to Devise register and login form pages 如何使用活动记录关联在设计中注册用户? - How to register user in devise with active record association? 如何使用rspec登录devise - how to login in with devise using rspec 如何使用devise实现永久登录 - How to implement permanent login with devise
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM