如何使用warden.authenticate进行身份验证!

时间:2010-12-30 01:55:09

标签: ruby-on-rails devise warden

我想在论坛上发表评论时,即时进行“登录或注册”。我正在使用Devise / Warden。

我想做这样的事情:

user = warden.authenticate!(params[:email], params[:password])
sign_in(:user, user)

有人可以给我一些如何做到的提示吗?

谢谢!

3 个答案:

答案 0 :(得分:1)

开启:可注册但不可:在您的模型中确认。

答案 1 :(得分:1)

Warden有set_user辅助方法。所以你应该能够做到:

warden.set_user(@user, scope: :user)

你可以定义一个控制器助手方法,登录用户并将它们重定向到你想要的路径

有关详细信息,请访问:https://github.com/hassox/warden/wiki/Authenticated-session-data

答案 2 :(得分:0)

我知道这是一个古老的话题,但我已经使用了

# Inside SessionController < Devise::SessionsController
def create
    self.resource = warden.authenticate!(auth_options)
    sign_in(resource_name, resource)  # this will set cookie
end

它是特定的设计,但是当在设计控制器中检查auth_options方法时,我发现了这段代码here

# File 'app/controllers/devise/sessions_controller.rb', line 45

def auth_options
    { scope: resource_name, recall: "#{controller_path}#new" }
end

希望有所帮助。

相关问题