- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我已经使用 Devise gem 向小型用户类添加了一些参数,但在使用 current_password 时遇到了一些问题。在我的帐户更新表单中,当我更新帐户并输入当前密码时收到错误消息“不能为空”。该帐户随后不会更新。我怀疑它正在某个地方被清理,删除了输入,然后被读取为空白。但是我不确定。我在下面列出了我认为相关的所有内容。
用户模型:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :username, :email, :password, :password_confirmation, :remember_me, :about_me
has_many :microposts
end
应用 Controller :
class ApplicationController < ActionController::Base
protect_from_forgery
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username, :email)}
devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:username, :email)}
devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:username, :about_me, :email, :password, :password_confirmation, :current_password)}
end
end
密码 Controller :
class Users::PasswordsController < Devise::PasswordsController
def resource_params
params.require(:user).permit(:email, :password, :password_confirmation, :current_password)
end
private :resource_params
end
注册 Controller
class Users::RegistrationsController < Devise::RegistrationsController
before_filter :configure_permitted_parameters
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) do |u|
u.permit(:username, :about_me, :email, :password, :password_confirmation)
end
devise_parameter_sanitizer.for(:account_update) do |u|
u.permit(:username, :about_me, :email, :password, :password_confirmation, :current_password)
end
end
end
设计路线:
devise_for :users, :controllers => {:registrations => "users/registrations", :passwords => "users/passwords" }
有问题的 View (标准设计/注册/编辑表单):
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :email, required: true, autofocus: true %>
<%= f.input :username, required: false, autofocus: true %>
<%= f.input :about_me, required: false, autofocus: true %>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<p>Currently waiting confirmation for: <%= resource.unconfirmed_email %></p>
<% end %>
<%= f.input :password, autocomplete: "off", hint: "leave it blank if you don't want to change it", required: false %>
<%= f.input :password_confirmation, required: false %>
<%= f.input :current_password, hint: "we need your current password to confirm your changes", required: true %>
</div>
<div class="form-actions">
<%= f.button :submit, "Update" %>
</div>
<% end %>
<h3>Cancel my account</h3>
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p>
同样,问题是当输入用于确认更改的密码时,该字段旁边会出现错误消息“不能为空”。有任何想法吗?谢谢
最佳答案
这是我过去遇到过的一个问题,需要一些变通办法。默认情况下,Devise 的 :registerable
模块允许用户更改他们的信息,并且需要输入 :password
和 :password_confirmation
参数。据我了解,您试图要求用户输入并确认他们的 :current_password
。
为了实现您正在寻找的行为,您必须覆盖 Devise 的 RegistrationsController
。我也不认为您需要 PasswordsController
,因为 Devise 的 RegistrationsController
会为您处理。您需要编写并实现一个方法来检查用户的 :current_password
的有效性,然后通过 update
操作将它们重定向到正确的位置。您可以在 Users::RegistrationController
类中编写以下私有(private)方法:
def needs_password?(user, params)
user.email != params[:user][:email] ||
params[:user][:password].present? ||
params[:user][:password_confirmation].present?
end
然后修改 User::RegistrationsController
中的 update
方法如下:
class Users::RegistrationsController < Devise::RegistrationsController
def update
@user = User.find(current_user.id)
successfully_updated = if needs_password?(@user, params)
@user.update_with_password(devise_parameter_sanitizer.sanitize(:account_update))
else
# remove the virtual current_password attribute
# update_without_password doesn't know how to ignore it
params[:user].delete(:current_password)
@user.update_without_password(devise_parameter_sanitizer.sanitize(:account_update))
end
if successfully_updated
set_flash_message :notice, :updated
# Sign in the user bypassing validation in case their password changed
sign_in @user, :bypass => true
redirect_to after_update_path_for(@user)
else
render "edit"
end
end
希望这会有所帮助。您还可以引用 Devise 的文档了解如何执行此操作:https://github.com/plataformatec/devise/wiki/How-To%3a-Allow-users-to-edit-their-account-without-providing-a-password .
关于ruby - 使用带有 rails : current_password being sanitized? 的设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23348229/
我目前使用以下代码在存储字符串之前对其进行清理: ERB::Util::h(string) 当字符串已经像这样清理后,我的问题就出现了: string = "Watching baseball `&a
我有几个版本的项目结帐和编译。如果我发现错误,我会比较版本以缩小问题范围。有时我会启用像 AddressSanitizer 这样的 sanitizer 。如果我重新使用一个可执行文件,我不记得它是否是
过去有人担心在某些环境中的生产中使用 ASAN:https://seclists.org/oss-sec/2016/q1/363 .评论来自 2016 年 - 今天的情况如何? 是否推荐使用 sani
过去有人担心在某些环境中的生产中使用 ASAN:https://seclists.org/oss-sec/2016/q1/363 .评论来自 2016 年 - 今天的情况如何? 是否推荐使用 sani
我正在使用 Google Caja HTML Sanitizer ( https://code.google.com/p/google-caja/wiki/JsHtmlSanitizer ),但它正在
我正在使用 goog.dom.safeHtmlToNode 动态更新包含内容的选项卡 由于较新版本的 google 闭包库删除了 dom 片段方法:goog.dom.htmlToDocumentFra
我正在使用 DOMPurify.sanitize()里面 dangerouslySetInnerHTML={{}}显示 innerHtml从数据库返回。对于最初的目的,我使用 getServersid
我不知道我需要做什么才能使这些选项不再被禁用。任何帮助,将不胜感激: 最佳答案 Thread Sanitizer 可用于以下准备条件: 关闭其他选项,例如 'Malloc stack' 需要64位模拟
我想知道是否有人使用过这个类并发现它可靠? http://www.phpclasses.org/package/3746-PHP-Remove-unsafe-tags-and-attributes-f
假设我复制了一些“恶意”输入,例如带有事件处理程序或其他 javascript 的 DOM 节点 如果我将其复制到我的剪贴板并将其粘贴到 contenteditable div 中,事件处理程序将被
这是我的一个表单(PHP+MySQL,textarea被TinyMCE取代)。它记录了带有段落、项目符号、标题和文本对齐方式(右对齐、左对齐、居中对齐和对齐)的描述。 提交后,记录显示为 Introd
我有以下代码片段,我在其中检查 soap 结果并将数据插入我的数据库。 Connection dbconn = null; Statement stmt1 = null; Statem
在以下示例中,我如何删除所有保留 html 内容的未知现有自定义标签: my header my Title my SubTitle 我想回去
我正在 Ubuntu 14.04 上使用带有 Clang 3.7.0 的 Memory Sanitizer。以下代码可以完美运行: #include int main() { double an
有哪些好的 PHP html(输入) sanitizer ? 最好是,如果内置了某些东西 - 我希望我们能做到这一点。 更新: 根据请求,通过评论,输入应该不允许 HTML(并且显然防止 XSS 和
我有以下数组,想知道验证和清理该数组以确保只允许整数的最佳方法是什么? if(is_array($_POST['taxonomy'])) { $term_ids = array_map('es
$sanitize 服务 tells me that All safe tokens (from a whitelist) are then serialized back to properly e
很抱歉,如果这是一个 super 简单的概念,但我发现很难获得正确的心态才能正确使用 clang 提供的 sanitizer 。 float foo(float f) { return (f / 0)
Clang有各种 sanitizer ,可以打开以在运行时发现问题。 但是,有些 sanitizer 我不能一起使用。这是为什么? clang++-3.9 -std=c++1z -g -fsaniti
一直在用fsanitize=address在编译 C 程序时,为了跟踪段错误大约一年了。我时不时地遇到一个奇怪的行为,如果编译没有我的程序会出现段错误 fsanitize=address但是当我用 f
我是一名优秀的程序员,十分优秀!