나는 내가 사용 지어진 사용자 모델이 레일의합니다 (Rails tutorial Book 기준) has_secure_password
:다음 암호 변경보기에 current_password 필드를 추가 하시겠습니까?
schema.rb :
create_table "users", :force => true do |t|
t.string "password_digest"
end
user.rb :
class User < ActiveRecord::Base
attr_accessible :name, :email, :avatar, :password, :password_confirmation, :provider, :uid
has_secure_password
validates :password, presence: true, length: { minimum: 6 }
validates :password_confirmation, presence: true
그리고이 같은 견해를 가지고 있습니다. uses/password_edit.html.erb
:
<%= f.label :password %>
<%= f.password_field :password, "New Password" %>
<%= f.label :password_confirmation, "Retype Password" %>
<%= f.password_field :password_confirmation %>
이제 상단에 :current_password
필드를 추가하고 싶습니다. 문제는 데이터베이스에 password_digest
열만있는 것입니다.
그래서 저는 여기에서 약간 잃어 버렸습니다. current_password
이 올바르지 않은 경우에도 양식에서 오류를 발생시키는 방법을 모르겠습니다.
제안 사항?
편집 :
users_controller.html.erb :이
데프 업데이트 OLD_PASSWORD =의 PARAMS [: current_password]
if authenticated = User.authenticate(old_password)
if params[:user][:password].blank? && params[:user][:password_confirmation].blank?
# Use old password if none indicated
params[:user][:password] = old_password
params[:user][:password_confirmation] = old_password
end
end
@user = User.find(params[:id])
@user.errors.add(:base, "Invalid password") unless authenticated
@user.updating_password = true if params[:form_name] == "edit_password"
if authenticated && @user.update_attributes(params[:user])
flash[:success] = "Profile updated"
sign_in @user
redirect_to @user
else
if params[:form_name] == "edit_password"
render 'edit_password'
else
render 'edit'
end
end
@user.updating_password = nil
끝
이제보기가 어떻게 보이는지 추가하고 컨트롤러 편집에서 서식을 수정할 수 있습니까? – Geoff