![](/img/trans.png)
[英]Customising the Devise :authenticate_user filter to also check for auth tokens
[英]Rails devise check for authenticate user without filter
在controller
不使用before filter
,我想检查user
是否已通过身份验证,因为这会强制user
进行身份验证。 我正在寻找一种方法,该方法如何在控制器中询问user
是否已通过身份验证,并据此确定从controller
发回的内容。
当前代码:
class Api::TestsController < Api::ApiController
before_filter :authenticate_user!
// the filter is force me to be an authenticated user to get access to this controller
end
我想要的是:
class Api::TestsController < Api::ApiController
def index
if current_user
// do something if the user is authenticated
else
// do something if the user not authenticated
end
end
end
我该如何实施? 我想要的是:
class Api::TestsController < Api::ApiController
def index
if current_user then
// do something if the user is authenticated
else
// do something if the user not authenticated
end
end
end
我该如何实施?
好吧,使用方法user_signed_in?
然后。 假设您的设计模型是User
。
class Api::TestsController < Api::ApiController
def index
if user_signed_in?
# do something if the user is authenticated
else
# do something if the user not authenticated
end
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.