改变与authlogic密码 - 确认不醒目的空白投入 [英] changing password with authlogic - validation not catching blank inputs
问题描述
我想创建一个表单,允许用户更改其密码:
I am trying to create a form to allow users to change their password:
查看:
- form_tag change_password_users_path do
= error_messages_for :user, :header_message => "Please Try Again", :message => "We had some problems updating your account"
%br
= label_tag :password, "New password:"
= password_field_tag "password"
%br
= label_tag :password_confirmation, "NConfirm new password:"
= password_field_tag "password_confirmation"
%br
= submit_tag "Update Account"
控制器:
def change_password
@user = current_user
if request.post?
@user.password = params[:password]
@user.password_confirmation = params[:password_confirmation]
if @user.save
redirect_to user_path(current_user)
else
render :action => "change_password"
end
end
end
Authlogic正在迎头赶上验证错误时,密码是太短或密码不匹配的确认,不过当表单与这两个领域的空白提交没有做任何事情。
@ user.save必须返回true,因为我重定向到user_path(CURRENT_USER)。
Authlogic is catching validation errors when the password is 'too short' or the password doesn't match the confirmation, but doesn't do anything when the form is submitted with both fields blank. @user.save must be returning true, because I am redirected to 'user_path(current_user)'.
密码实际上不是在数据库中更改。
The password is not actually changed in the database.
感谢您的帮助。
推荐答案
我建议你打电话的 @ user.changed 像下面的例子来检查空密码:
I suggest you call @user.changed? like the following example to check for blank passwords:
def change_password
@user = current_user
if request.post?
@user.password = params[:user][:password]
@user.password_confirmation = params[:user][:password_confirmation]
if @user.changed? && @user.save
redirect_to user_path(current_user)
else
render :action => "change_password"
end
end
end
这篇关于改变与authlogic密码 - 确认不醒目的空白投入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!