Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.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 Desive不允许用户更新其信息_Ruby On Rails_Ruby_Devise_Ruby On Rails 5 - Fatal编程技术网

Ruby on rails Desive不允许用户更新其信息

Ruby on rails Desive不允许用户更新其信息,ruby-on-rails,ruby,devise,ruby-on-rails-5,Ruby On Rails,Ruby,Devise,Ruby On Rails 5,在写这篇文章之前,我已经检查了这些问题和类似的问题,但不知何故,我不断地遇到问题,这些问题没有帮助 问题是,我需要用户能够更改他们的密码。为此,我使用Desive及其观点。我可以在所有其他领域完美地使用Desive,但当我尝试此操作时,即使使用刚刚创建的帐户,也会出现两个错误:当前密码无效,密码确认无效 我试过两种消毒液: users/registration\u controller.rb # frozen_string_literal: true class Users::Registra

在写这篇文章之前,我已经检查了这些问题和类似的问题,但不知何故,我不断地遇到问题,这些问题没有帮助

问题是,我需要用户能够更改他们的密码。为此,我使用Desive及其观点。我可以在所有其他领域完美地使用Desive,但当我尝试此操作时,即使使用刚刚创建的帐户,也会出现两个错误:当前密码无效,密码确认无效

我试过两种消毒液:

users/registration\u controller.rb

# frozen_string_literal: true

class Users::RegistrationsController < Devise::RegistrationsController
  # before_action :configure_sign_up_params, only: [:create]
  skip_before_action :require_no_authentication
  before_action :authenticate_user!
  before_action :authorize_admin!, only: :create
  # before_action :configure_account_update_params, only: [:update]

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

  # POST /resource
  def create
     build_resource(sign_up_params)

     resource.save
     yield resource if block_given?
     if resource.persisted?
       if resource.active_for_authentication?
         set_flash_message! :notice, :signed_up
         respond_with resource, location: after_sign_up_path_for(resource)
       else
         set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
         expire_data_after_sign_in!
         respond_with resource, location: after_inactive_sign_up_path_for(resource)
       end
     else
       clean_up_passwords resource
       set_minimum_password_length
       respond_with resource
     end
  end

  # GET /resource/edit
  # def edit
  #   super
  # end

  # PUT /resource
  # def update
  #   super
  # end

  # DELETE /resource
  # def destroy
  #   super
  # end

  # GET /resource/cancel
  # Forces the session data which is usually expired after sign
  # in to be expired now. This is useful if the user wants to
  # cancel oauth signing in/up in the middle of the process,
  # removing all OAuth session data.
  # def cancel
  #   super
  # end

  protected

  # If you have extra params to permit, append them to the sanitizer.
  def configure_sign_up_params
    devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name, :email, :password, :password_confirmation, :creditos, :role, :birthday, :dni, :address, :phone, :gender])
  end

  # If you have extra params to permit, append them to the sanitizer.
  def configure_account_update_params
    devise_parameter_sanitizer.permit(:account_update, keys: [:first_name, :last_name, :email, :password, :password_confirmation, :current_password, :creditos, :role, :birthday, :dni, :address, :phone, :gender])
  end

  # The path used after sign up.
  def after_sign_up_path_for(resource) #Resource is the user just created

    empresa = Empresa.create(user_id: resource.id)
    resource.empresa_id = empresa.id
    if resource.save(validate: false)
      edit_empresa_path(resource.empresa)
    else
      flash[:alert] = "Ha habido un problema"
      redirect_to (root_path)
    end
  end

  # The path used after sign up for inactive accounts.
  # def after_inactive_sign_up_path_for(resource)
  #   super(resource)
  # end

  private

  def authorize_admin!
    unless user_signed_in? && current_user.admin?
      redirect_to root_path, alert: "Tú no eres administrador."
    end
  end

end
class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception
  before_action :configure_permitted_parameters, if: :devise_controller?

  private
  def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up) do |user|
      user.permit(:email, :password, :password_confirmation, :role, :creditos )
    end
    devise_parameter_sanitizer.permit(:account_update) do |user|
      user.permit(:email, :password, :password_confirmation, :current_password, :role, :creditos )
    end
  end
end
#冻结的字符串文字:true
类用户::注册控制器<设计::注册控制器
#在\u操作之前:配置\u注册\u参数,仅:[:创建]
在\u操作之前跳过\u:要求\u无\u身份验证
在\u操作之前:验证\u用户!
行动前:授权管理员!,仅限::创建
#在\u操作之前:配置\u帐户\u更新\u参数,仅:[:更新]
#获取/资源/注册
#def新
#超级
#结束
#员额/资源
def创建
构建资源(注册参数)
资源节约
如果给定块,是否产生资源?
如果资源持久化?
如果resource.active\u用于\u身份验证?
设置闪光信息!:通知:已注册
使用资源响应,位置:为(资源)注册路径后
其他的
设置闪光信息!:注意::“已注册但{resource.inactive_message}”
登录后数据过期!
使用资源响应,位置:在不活动之后注册路径(资源)
结束
其他的
清除密码资源
设置\u最小\u密码\u长度
用资源回应你
结束
结束
#获取/资源/编辑
#定义编辑
#超级
#结束
#投入/资源
#def更新
#超级
#结束
#删除/删除资源
#def销毁
#超级
#结束
#获取/资源/取消
#强制执行通常在签名后过期的会话数据
#现在就要到期了。如果用户愿意,这是有用的
在进程中间取消OAuthIn签入/注册,
#删除所有OAuth会话数据。
#def取消
#超级
#结束
受保护的
#如果要允许使用额外的参数,请将它们附加到消毒液中。
def配置\注册\参数
设计参数消毒器。许可证(:注册,密钥:[:名字,姓氏,电子邮件,密码,密码确认,信用卡,角色,生日,dni,地址,电话,性别])
结束
#如果要允许使用额外的参数,请将它们附加到消毒液中。
def配置\帐户\更新\参数
设计参数消毒器。允许(:帐户更新,密钥:[:名字、姓氏、电子邮件、密码、密码确认、当前密码、信用卡、角色、生日、dni、地址、电话、性别])
结束
#注册后使用的路径。
def after_sign_up_path_for(resource)#resource是刚刚创建的用户
empresa=empresa.create(用户id:resource.id)
resource.empresa_id=empresa.id
if resource.save(验证:false)
编辑\u empresa\u路径(resource.empresa)
其他的
flash[:alert]=“Ha habido un problema”
重定向到(根路径)
结束
结束
#注册非活动帐户后使用的路径。
#非活动后的def注册路径(资源)
#超级(资源)
#结束
私有的
def授权管理!
除非用户登录&当前_user.admin?
重定向到根路径,警告:“Túno eres administrador。”
结束
结束
结束
应用程序\u控制器.rb

# frozen_string_literal: true

class Users::RegistrationsController < Devise::RegistrationsController
  # before_action :configure_sign_up_params, only: [:create]
  skip_before_action :require_no_authentication
  before_action :authenticate_user!
  before_action :authorize_admin!, only: :create
  # before_action :configure_account_update_params, only: [:update]

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

  # POST /resource
  def create
     build_resource(sign_up_params)

     resource.save
     yield resource if block_given?
     if resource.persisted?
       if resource.active_for_authentication?
         set_flash_message! :notice, :signed_up
         respond_with resource, location: after_sign_up_path_for(resource)
       else
         set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
         expire_data_after_sign_in!
         respond_with resource, location: after_inactive_sign_up_path_for(resource)
       end
     else
       clean_up_passwords resource
       set_minimum_password_length
       respond_with resource
     end
  end

  # GET /resource/edit
  # def edit
  #   super
  # end

  # PUT /resource
  # def update
  #   super
  # end

  # DELETE /resource
  # def destroy
  #   super
  # end

  # GET /resource/cancel
  # Forces the session data which is usually expired after sign
  # in to be expired now. This is useful if the user wants to
  # cancel oauth signing in/up in the middle of the process,
  # removing all OAuth session data.
  # def cancel
  #   super
  # end

  protected

  # If you have extra params to permit, append them to the sanitizer.
  def configure_sign_up_params
    devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name, :email, :password, :password_confirmation, :creditos, :role, :birthday, :dni, :address, :phone, :gender])
  end

  # If you have extra params to permit, append them to the sanitizer.
  def configure_account_update_params
    devise_parameter_sanitizer.permit(:account_update, keys: [:first_name, :last_name, :email, :password, :password_confirmation, :current_password, :creditos, :role, :birthday, :dni, :address, :phone, :gender])
  end

  # The path used after sign up.
  def after_sign_up_path_for(resource) #Resource is the user just created

    empresa = Empresa.create(user_id: resource.id)
    resource.empresa_id = empresa.id
    if resource.save(validate: false)
      edit_empresa_path(resource.empresa)
    else
      flash[:alert] = "Ha habido un problema"
      redirect_to (root_path)
    end
  end

  # The path used after sign up for inactive accounts.
  # def after_inactive_sign_up_path_for(resource)
  #   super(resource)
  # end

  private

  def authorize_admin!
    unless user_signed_in? && current_user.admin?
      redirect_to root_path, alert: "Tú no eres administrador."
    end
  end

end
class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception
  before_action :configure_permitted_parameters, if: :devise_controller?

  private
  def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up) do |user|
      user.permit(:email, :password, :password_confirmation, :role, :creditos )
    end
    devise_parameter_sanitizer.permit(:account_update) do |user|
      user.permit(:email, :password, :password_confirmation, :current_password, :role, :creditos )
    end
  end
end
class ApplicationController
注意:我已经多次使用不同的帐户验证当前密码是否正确。上述方法一次使用一种。不是同时


你为什么需要在那里发送电子邮件?如果用户可以更改密码,则他已登录。如我所见,您有自定义注册控制器。如果你能展示它的完整代码,那会很有帮助的。然而,这个控制器也是由Desive生成的,仅对我的应用程序进行了一些调整。