[英]devise first login with rails
How can I determine on my custom session controller that the user is the first time login, I want to be able to create a session and to redirect to welcome#index
if its the first time else it would be redirected to root_url
. 我如何在我的自定义会话控制器上确定该用户是第一次登录,我希望能够创建一个会话并重定向到
welcome#index
如果是第一次登录),否则它将被重定向到root_url
。
The code that I have is has follow 我拥有的代码如下
class MysessionsController < Devise::SessionsController
def create
self.resource = warden.authenticate!(auth_options)
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => after_sign_in_path_for(resource)
end
protected
def after_sign_up_path_for(resource)
"http://google.com"
end
end
I know I need to custom after_sign_up_path_for(resource)
to what I want but I cant find how to determine if the user has sign in before or not with devise 我知道我需要自定义
after_sign_up_path_for(resource)
到我想要的内容,但是我无法找到如何确定用户是否已经通过after_sign_up_path_for(resource)
登录了
you should be able to do this with :sign_in_count
column. 您应该可以使用
:sign_in_count
列来执行此:sign_in_count
。 if this is 0 it means user has not sign in before 如果为0,则表示用户之前未登录
So as an example 举个例子
redirect_to ((current_user.sign_in_count == 0) ? path1 : path2 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.