Devise::PasswordsController 中实际更新的用户密码在哪里?
Where is the users password actually updated in Devise::PasswordsController?
我对 rails 设备 gem 很陌生。并试图了解它是如何工作的。
在我的项目中,有Devise::PasswordsController。
def update
self.resource = resource_class.reset_password_by_token(resource_params)
yield resource if block_given?
if resource.errors.empty?
resource.unlock_access! if unlockable?(resource)
if Devise.sign_in_after_reset_password
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
set_flash_message!(:notice, flash_message)
resource.after_database_authentication
sign_in(resource_name, resource)
else
set_flash_message!(:notice, :updated_not_active)
end
respond_with resource, location: after_resetting_password_path_for(resource)
else
set_minimum_password_length
respond_with resource
end
end
这会将新密码更新到数据库。
在我的服务器日志中。我可以看到执行了 UPDATE
SQL 查询。
UPDATE `users` SET `reset_password_sent_at` = NULL, `encrypted_password` = 'somevalue......', `reset_password_token` = NULL, `updated_at` = '2020-xx-xx xx:xx:xx' WHERE `users`.`id` = xxx
但是,
为什么我找不到任何与此等效的 ruby 代码? 与 resource.update
中的一样像那样。
抱歉,如果我的问题没有意义。如果是这样,请纠正我的误解。
在哪里可以找到执行SQL的函数?
实际更新发生在 Devise::Models::Recoverable#reset_password which is called by #reset_password_by_token。
# Update password saving the record and clearing token. Returns true if
# the passwords are valid and the record was saved, false otherwise.
def reset_password(new_password, new_password_confirmation)
if new_password.present?
self.password = new_password
self.password_confirmation = new_password_confirmation
save
else
errors.add(:password, :blank)
false
end
end
我对 rails 设备 gem 很陌生。并试图了解它是如何工作的。
在我的项目中,有Devise::PasswordsController。
def update
self.resource = resource_class.reset_password_by_token(resource_params)
yield resource if block_given?
if resource.errors.empty?
resource.unlock_access! if unlockable?(resource)
if Devise.sign_in_after_reset_password
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
set_flash_message!(:notice, flash_message)
resource.after_database_authentication
sign_in(resource_name, resource)
else
set_flash_message!(:notice, :updated_not_active)
end
respond_with resource, location: after_resetting_password_path_for(resource)
else
set_minimum_password_length
respond_with resource
end
end
这会将新密码更新到数据库。
在我的服务器日志中。我可以看到执行了 UPDATE
SQL 查询。
UPDATE `users` SET `reset_password_sent_at` = NULL, `encrypted_password` = 'somevalue......', `reset_password_token` = NULL, `updated_at` = '2020-xx-xx xx:xx:xx' WHERE `users`.`id` = xxx
但是,
为什么我找不到任何与此等效的 ruby 代码? 与 resource.update
中的一样像那样。
抱歉,如果我的问题没有意义。如果是这样,请纠正我的误解。
在哪里可以找到执行SQL的函数?
实际更新发生在 Devise::Models::Recoverable#reset_password which is called by #reset_password_by_token。
# Update password saving the record and clearing token. Returns true if
# the passwords are valid and the record was saved, false otherwise.
def reset_password(new_password, new_password_confirmation)
if new_password.present?
self.password = new_password
self.password_confirmation = new_password_confirmation
save
else
errors.add(:password, :blank)
false
end
end