在我的论坛上发表评论时,我想即时进行“登录或注册”。我正在使用设计/监狱长。
我想做这样的事情:
user = warden.authenticate!(params[:email], params[:password])
sign_in(:user, user)
谁能给我一些关于如何做到这一点的提示?
谢谢!
在我的论坛上发表评论时,我想即时进行“登录或注册”。我正在使用设计/监狱长。
我想做这样的事情:
user = warden.authenticate!(params[:email], params[:password])
sign_in(:user, user)
谁能给我一些关于如何做到这一点的提示?
谢谢!
Warden 有一个set_user
辅助方法。所以你应该能够做到:
warden.set_user(@user, scope: :user)
您可能可以定义一个控制器辅助方法,以登录用户并将他们重定向到您想要的路径
更多信息请访问:https ://github.com/hassox/warden/wiki/Authenticated-session-data
在您的模型中打开 :registerable 但不是 :confirmable 。
我知道这是一个古老的话题,但我已经使用过
# Inside SessionController < Devise::SessionsController
def create
self.resource = warden.authenticate!(auth_options)
sign_in(resource_name, resource) # this will set cookie
end
它是特定于设计的,但是在设计控制器中检查 auth_options 方法时,我在这里找到了这段代码:
# File 'app/controllers/devise/sessions_controller.rb', line 45
def auth_options
{ scope: resource_name, recall: "#{controller_path}#new" }
end
希望有帮助。