如何覆盖设计密码控制器?
如何覆盖设计密码控制器:
https://github .com/plataformatec/devise/blob/master/app/controllers/devise/passwords_controller.rb
我想要执行以下操作:
- 将所有提交用于密码重置的电子邮件小写。数据库中的所有电子邮件均为小写。如果用户尝试重置包含任何大写字符的有效电子邮件,重置将无法找到用户。并且 devise 甚至不会给出错误消息,指出未找到用户
- 如果在 def create 中未找到用户,我想添加一个 Flash,表示未找到用户,您输入了正确的电子邮件吗?
如何才能完成以上2点呢?我相信这需要覆盖设备密码控制器。我该怎么做?或者如果您有更好、更干净的解决方案,我很想听听。
谢谢
How to override the Devise Passwords Controller:
https://github.com/plataformatec/devise/blob/master/app/controllers/devise/passwords_controller.rb
I want to do the following:
- downcase all emails submitted for password reset. All the emails in the DB as lowercase. If a user tried to reset a valid email with any characters uppercase, the reset fails to find a user. And devise doesn't even give a error message saying no user found
- If no user is found in def create, I want to add a flash that says, no user found, did you enter the right email?
How can I accomplish the 2 items above? I believe that required overriding the devise password controller. How do I do that? Or if you have a better solution that's even cleaner, I would like to hear it.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设计初始化程序有一个选项可以使任何字段不区分大小写:
config.case_insensitive_keys = [ :email ]
如果我没记错的话,它是在新版本中添加的,并且如果您在中没有看到一些相关注释如果你初始化程序,那么你应该使用
捆绑升级设备
升级你的设备gem。我使用的是1.3.3版本。如果输入无效的电子邮件,此版本还会显示错误“未找到电子邮件”。
如果您没有收到错误消息,请添加
<%= devise_error_messages! %>
到您的视图。您可以通过编辑 config/locales/devise.en.yml 来自定义错误消息the devise initializer has a option to make any field case insensitive:
config.case_insensitive_keys = [ :email ]
If I remember correctly it was added in the newer version and if you don't see some related comments in you initializer then you should upgrade your devise gem using
bundle upgrade devise
. I am using version 1.3.3.And this version also shows an error "Email not found" if an invalid email is entered.
If you not getting the error message add
<%= devise_error_messages! %>
to your view. You can customize the error messages by editingconfig/locales/devise.en.yml