2
A
回答
4
您需要重写Devise的passwords_controller
,您可以看到here的默认方法。首先,创建自己的控制器,它会从设计控制器继承:
class User::PasswordsController < Devise::PasswordsController
一旦你有你的控制器准备好,加入所有的,你不希望覆盖等方法,而只是内部调用super其中。这将是new
,edit
和create
方法。另外不要忘记添加受保护的after_sending_reset_password_instructions_path_for(resource_name)
方法。
您关心覆盖的方法是update
操作。
def update
self.resource = resource_class.reset_password_by_token(resource_params)
if resource.errors.empty?
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
set_flash_message(:notice, "Your flash message here")
redirect_to new_user_session_path
else
respond_with resource
end
end
所有我们在这里改变的是删除与重定向到登录页面,用户签署线,然后将我们自定义的提示信息。
最后,你必须告诉设计使用新的控制器,所以在routes.rb
变化devise_for :users
到:
devise_for :users, :controllers => { :passwords => 'users/passwords' }
而且应该这样做。
0
上述答案是正确的,但事情是根据设计版本而有所不同。我遵循上面说的,我无法得到它的工作,一段时间后,我发现我使用的设计版本不支持resource_params方法,然后我尝试了不同的版本,并得到它的工作。
2
下面是根据色器件3.1.1更新
class Users::PasswordsController < Devise::PasswordsController
def new
super
end
def edit
super
end
def create
super
end
#override this so user isn't signed in after resetting password
def update
self.resource = resource_class.reset_password_by_token(resource_params)
if resource.errors.empty?
resource.unlock_access! if unlockable?(resource)
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
set_flash_message(:notice, flash_message) if is_navigational_format?
respond_with resource, :location => after_resetting_password_path_for(resource)
else
respond_with resource
end
end
protected
def after_resetting_password_path_for(resource)
new_session_path(resource)
end
末
相关问题
- 1. 日志SQL Server密码更改
- 2. 密码验证中断设计确认
- 3. jquery验证:密码更改和确认
- 4. 在设计用户上更改密码
- 5. 在设计中更改用户密码
- 6. 设计验证 - 密码恢复后无需确认
- 7. 设计不验证密码/密码确认
- 8. 设计在密码更改后注销用户
- 9. 设计密码确认
- 10. 需要旧密码更改新密码authlogic认证
- 11. 用设计发送密码更改确认
- 12. 设计更改密码格式
- 13. Rails 3设计手动更改密码
- 14. 设计自定义密码更改
- 15. 设计,允许用户更改密码
- 16. 用户在drupal中更改密码时记录在日志中
- 17. 更改密码时验证旧密码
- 18. 设计..第一次登录后应该要求更改密码
- 19. 更改设计初始值设定项,现在认证中断
- 20. 更新密码设计
- 21. 设计更新密码
- 22. 设计密码更新
- 23. 双密码认证
- 24. 在asp.net身份更改密码验证
- 25. 在更改为新密码之前确认旧密码codeigniter
- 26. Laravel 5.2 - 验证用户更改密码 - 更新后密码匹配问题
- 27. MVC验证更改密码。当前密码与新密码
- 28. 使用材料设计lite错误确认密码验证
- 29. 如何设计宁静登记,认证,重置密码
- 30. 删除密码确认;设计