【发布时间】:2012-01-26 17:06:38
【问题描述】:
我正在使用 Omniauth 来允许用户通过 Facebook、Twitter 和 Google 登录(并创建一个帐户)。
但是,如果用户决定不再使用这些服务,而是继续使用他们的帐户,他们将需要添加密码。
如何让用户在不输入current password 的情况下为其帐户添加密码?*
当我让用户转到edit_user_registration_path(@user) 时,他们会看到下面的表格:
= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put, name: 'validation'}) do |f|
= devise_error_messages!
= f.label :email, class: 'block'
= f.email_field :email, class: 'large'
%span.infobar Keep this here unless you'd like to change your email
= f.label :password, class: 'block'
= f.password_field :password, class: 'large'
%span.infobar Leave blank if you don't want to change it
= f.label :password_confirmation, class: 'block'
= f.password_field :password_confirmation, class: 'large'
- if @user.password_required?
= f.label :current_password, class: 'block'
= f.password_field :current_password, class: 'large'
%span.infobar We need your current password to confirm changes
= f.submit "Update"
user.rb
def password_required?
(authentications.empty? || !password.blank?) && super
end
如您所见,我有它,如果@user.password_required?,则显示当前密码字段。即使在尝试为帐户创建新密码时未显示此字段,表单也不会正确验证,因为需要当前密码。
【问题讨论】:
标签: ruby-on-rails authentication devise omniauth