我继承了一个应用程序更新用户的配置文件的以下行为:如何在使用Authlogic时编写和测试密码更改?
class UsersController < ApplicationController
# ...
def update
@user = current_user
if @user.update_attributes(params[:user])
flash[:notice] = "Successfully updated profile."
redirect_to root_url
else
flash[:error] = "Hrm, something went wrong."
render :action => 'edit'
end
end
end
的形式PUT
S(真POST
s的一个_method=PUT
)到行动有password
和password_confirmation
场,但没有old_password
场。我已经通过测试发现,我甚至不需要填写password_confirmation
字段。
第一个问题:在使用Authlogic时,是否有一种更为确定的密码更改方式?
第二个问题:有没有关于密码更改的最佳实践(特别是从可用性的角度来看)的文献?它应该是一个单独的形式,不与其他用户字段混合?
第三个问题:大多数网站都有old_password
字段,但Authlogic似乎并不支持本地。 Authlogic-ey确认用户自己改变密码的方式是什么,而不是那些黑客攻击会话的人?
我得到密码更新的麻烦的原因是我在做{@user = Factory(:user),UserSession.create(@user )}在一个整体设置块中,然后在内部设置块中再次执行{@user = Factory(:user)}'并检查该用户的密码更改,但实际上在外部更改该密码。 D'哦! – 2010-02-10 17:17:14