Rails 3.0 Devise reset Password by answering a question

萝らか妹 提交于 2019-12-10 20:17:49

问题


I am using devise with rails 3. In user model I have created fields for the question and answer to that question.

I want to know How I can implement forget password in following logic:

  1. On forget password page User enters the Username
  2. On Next step application should displays the question stored in db.
  3. User answers the question and app matches the answer if answer is matched with values stored in db.
  4. It redirects to edit password page where password can updated.

I tried to override password controller of devise but got stuck.

Thanks for help in advance.

Note: I am new to rails and its my first project


回答1:


I've actually not used Devise before, however assuming you have a befor_filter on your controller to route to Devise authentication, you could possibly do something like:

skip_before_filter :authenticate_with_devise if user_answered_question_correctly?



回答2:


this gem has a security_questionable feature which would do the trick, amongst other things https://github.com/phatworx/devise_security_extension




回答3:


You don't need to override Devise for this.

  1. make your own forget_password routes:

in routes.rb:

get "forgot_password" => "passwords#forgot"
get "forgot_password/verify_question" => "passwords#verify_question"
post "forgot_password/verify_answer" => "passwords#verify_answer"
post "forgot_password/reset_password" => "passwords#reset"
  1. Create app/controller/passwords_controller.rb and fill out logic you want via forms / render.
  2. Create views.
  3. Change forgot password link to your own.
  4. Profit


来源:https://stackoverflow.com/questions/4805374/rails-3-0-devise-reset-password-by-answering-a-question

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!