【问题标题】:rails 5 authlogic cryptic user_session errorrails 5 authlogic 神秘的 user_session 错误
【发布时间】:2016-05-02 16:55:41
【问题描述】:

我正在尝试使用 Rails 5 设置 Authlogic(因此是 user_session_params.to_h),当我尝试创建新会话时,我收到以下错误消息,我不知道该怎么做。任何建议将不胜感激。

输入@user_session.errors.inspect

#<Authlogic::Session::Validation::Errors:0x0000000cb9b7a0 @base=#<UserSession: {:email=>"test@test.com", :password=>"<protected>"}>, @messages={:base=>["You did not provide any details for authentication."]}, @details={:base=>[{:error=>"You did not provide any details for authentication."}]}>

代码如下:

用户会话控制器

class UserSessionsController < ApplicationController
  def new
    @user_session = UserSession.new
  end

  def create
    @user_session = UserSession.new(user_session_params.to_h)
    puts @user_session.errors.inspect

    if @user_session.save
      flash[:notice] = "Login successful, thank you!"
      redirect_to users_path
    else
      flash[:notice] = "Something went wrong, sorry."
    end
  end

  def destroy
    current_user_session.destroy
    redirect_to new_user_sessions_path
  end

  private

  def user_session_params
    params.require(:user_session).permit(:email, :password, :remember_me)
  end
end

用户会话

class UserSession < Authlogic::Session::Base
end

查看

<%= form_for @user_session, url: user_sessions_path, method: :post, html: {class: 'form-horizontal', role: 'form'} do |f| %>
    <div class='form-group'>
      <%= f.email_field :email, class: 'form-control', placeholder: 'Login' %>
    </div>
    <div class='form-group'>
      <%= f.password_field :password, class: 'form-control', placeholder: 'Password' %>
    </div>
    <%= f.submit 'Login', class: 'btn btn-primary' %>
<% end %>

用户

class User < ApplicationRecord
    acts_as_authentic do |c|
        c.login_field = 'email'
    end
end

【问题讨论】:

  • 您需要在您的puts 之前调用@user_session.valid?,以便errors 在验证失败时实际打印一些内容。请更新问题。
  • 补充说。现在它似乎在实际使用正确的身份验证详细信息时无法识别身份验证详细信息。

标签: ruby-on-rails authlogic ruby-on-rails-5


【解决方案1】:

似乎存在 Rails 5 下的 Authlogic 问题

您可能已经从 github 问题 487 中看到 this comment,但您可能只遵循了第一步。步骤编号。 2 处理 Rails 5 下损坏的 Authlogic 回调,并且有一个指向 pull request #488 的链接,其中开发了一个修复程序。目前,您唯一的选择似乎如下:

  • 您可以尝试 this branch of Authlogic 据称已修复回调问题,如拉取请求 488 中的 commented
  • 您当然可以等到事情稳定下来,Authlogic 获得对 Rails5 的官方支持。

【讨论】:

  • 是的,我暂时决定围绕has_secure_password编写自己的简单身份验证,稍后我会更改它。
【解决方案2】:

从 Authlogic 版本 3.5.0 开始,此问题似乎已得到修复。目前 3.5.0 仍未作为稳定版本发布,但在 Gemfile 中指定 3.5 应该可以解决问题(无论如何它对我来说确实如此):

gem 'authlogic', '~&gt; 3.5'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-13
    • 2017-04-20
    • 2014-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多