Omniauth를 사용하여 사용자가 Facebook, Twitter 및 Google을 통해 로그인하고 계정을 만들 수 있습니다.Rails 3.2 Omniauth Devise - 비밀번호 추가 - 현재 비밀번호 건너 뛰기
그러나 사용자가 더 이상 해당 서비스를 사용하지 않기로 결정했지만 계정을 계속 사용하려면 비밀번호를 추가해야합니다.
어떻게 사용자가 입력하지 않고 자신의 계정에 암호를 추가 할 수있는 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?
인 경우 현재 암호 필드를 보여줍니다. 계정의 새 암호를 만들 때이 필드가 표시되지 않더라도 현재 암호가 필요하므로 양식의 유효성이 올바르게 검사되지 않습니다.
이 나를 위해 작동하지 않았 때문에 : 비밀번호 : 제출 된 경우 password_confirmation 속성. 암호의 길이가 1보다 작 으면 매개 변수에서 미리 삭제해야합니다. – wintersolutions