Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 401尝试确认设计用户时_Ruby On Rails_Ruby On Rails 4_Devise_Http Status Code 401_Devise Confirmable - Fatal编程技术网

Ruby on rails 401尝试确认设计用户时

Ruby on rails 401尝试确认设计用户时,ruby-on-rails,ruby-on-rails-4,devise,http-status-code-401,devise-confirmable,Ruby On Rails,Ruby On Rails 4,Devise,Http Status Code 401,Devise Confirmable,我正在尝试配置一个designe:confirformable帐户,在该帐户中,用户在确认帐户后选择其密码(这是一个官方记录的修改,可以找到详细信息) 问题:没有修改(我第一次创建帐户时设置了密码),确认工作正常。然而,在修改下,我得到了一个401错误(未经授权)。其日志如下: Started POST "/users/sign_in" for 192.168.1.8 at 2016-01-31 01:53:54 -0700 Processing by Users::SessionsContro

我正在尝试配置一个designe
:confirformable
帐户,在该帐户中,用户在确认帐户后选择其密码(这是一个官方记录的修改,可以找到详细信息)

问题:没有修改(我第一次创建帐户时设置了密码),确认工作正常。然而,在修改下,我得到了一个401错误(未经授权)。其日志如下:

Started POST "/users/sign_in" for 192.168.1.8 at 2016-01-31 01:53:54 -0700
Processing by Users::SessionsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"O7mUtX/5i3Cw2sgAtn8+i4VAuytkHpcxZ0ZnKL6rmfmQsRj0MblP4OGY4K3dxqXQ7qjVMsqpYEIs7Oqkm9G3JA==", "user"=>{"email"=>"neanderslob@neanderslob.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "button"=>""}
  ^[[1m^[[36mUser Load (0.8ms)^[[0m  ^[[1mSELECT  "users".* FROM "users" WHERE "users"."email" = $1  ORDER BY "users"."id" ASC LIMIT 1^[[0m  [["email", "neanderslob@neanderslob.com"]]
  ^[[1m^[[35m (0.2ms)^[[0m  BEGIN
  ^[[1m^[[36m (0.1ms)^[[0m  ^[[1mCOMMIT^[[0m
Completed 401 Unauthorized in 70ms (ActiveRecord: 1.1ms)
当然没有输入密码,因为这是不必要的

附件是我的自定义确认控制器

class Users::ConfirmationsController < Devise::ConfirmationsController
  # Remove the first skip_before_filter (:require_no_authentication) if you
  # don't want to enable logged users to access the confirmation page.
   skip_before_filter :require_no_authentication
   skip_before_filter :authenticate_user!

  # GET /resource/confirmation/new
  def new
    super
  end

  # POST /resource/confirmation
  def create
    super
  end

  # GET /resource/confirmation?confirmation_token=abcdef
  def show
    with_unconfirmed_confirmable do
      if @confirmable.has_no_password?
        do_show
      else
        do_confirm
      end
    end
    unless @confirmable.errors.empty?
      self.resource = @confirmable
      render 'devise/confirmations/new' #Change this if you don't have the views on default path
    end
  end

  # PUT /resource/confirmation
  def update
    with_unconfirmed_confirmable do
      if @confirmable.has_no_password?
        @confirmable.attempt_set_password(params[:user])
        if @confirmable.valid? and @confirmable.password_match?
          do_confirm
        else
          do_show
          @confirmable.errors.clear #so that we wont render :new
        end
      else
        @confirmable.errors.add(:email, :password_already_set)
      end
    end

    if !@confirmable.errors.empty?
      self.resource = @confirmable
      render 'devise/confirmations/new' #Change this if you don't have the views on default path
    end
  end


  protected

  # The path used after resending confirmation instructions.
  def after_resending_confirmation_instructions_path_for(resource_name)
    super(resource_name)
  end

  # The path used after confirmation.
  def after_confirmation_path_for(resource_name, resource)
    super(resource_name, resource)
  end


  def with_unconfirmed_confirmable
    @confirmable = User.find_or_initialize_with_error_by(:confirmation_token, params[:confirmation_token])
    if !@confirmable.new_record?
      @confirmable.only_if_unconfirmed {yield}
    end
  end

  def do_show
    @confirmation_token = params[:confirmation_token]
    @requires_password = true
    self.resource = @confirmable
    render 'devise/confirmations/show' #Change this if you don't have the views on default path
  end

  def do_confirm
    @confirmable.confirm!
    set_flash_message :notice, :confirmed
    sign_in_and_redirect(resource_name, @confirmable)
  end
end

日志与您发布的控制器无关。这是关于你的会话控制器的。你真的需要它有什么特别的原因吗?问题是用户在进行确认时无法正常验证用户。我会重新考虑。@sevensacat这是一个有用的观察结果(可能是他们为什么把它放在那里):-P事实证明我的
create
方法出于某种原因被注释掉了。不知道为什么到目前为止,这还没有影响到任何其他与会话相关的活动。无论如何,我将把会话控制器放在我的问题中;请随意指出答案中显而易见的地方,我很乐意给您评分。@max感谢您的回答;这种用户管理方法是必要的,因为我需要用户创建完全掌握在一组选定的管理员手中,然后提醒用户已经为他们创建了一个帐户。我不完全理解你的担心;如果您有时间,请您重申您评论中的第二句话好吗?基本上,Desive confirmations的工作方式是,用户正常创建,但未标记为已确认-然后用户执行确认步骤,在该步骤中,他/她可以像其他任何用户一样通过电子邮件/pw进行身份验证。但是,如果用户没有PW,则不能使用正常的管理员策略。您的用例与Desive Confirmatible的目的是如此不同,因此您最好从头开始写一些东西,而不是到处戳洞。
class Users::SessionsController < Devise::SessionsController

  # GET /resource/sign_in
  def new
    super
  end

  # POST /resource/sign_in
  # def create
  #   super
  # end

  # DELETE /resource/sign_out
  def destroy
    super
  end
end