ruby-on-rails – Rails会在24小时内过期密码
发布时间:2020-12-17 03:53:10 所属栏目:百科 来源:网络整理
导读:在我的rails 3.1应用程序中,我想为用户创建并过期随机密码.我正在使用devise gem.Any插件可用于使密码到期并持续一段时间? ??或者请给我一些合理的建议来实现这个功能. 请认为我是新手. 解决方法 听起来你只想让密码失效一次.如果您希望定期(例如每隔几个月
在我的rails 3.1应用程序中,我想为用户创建并过期随机密码.我正在使用devise gem.Any插件可用于使密码到期并持续一段时间?
??或者请给我一些合理的建议来实现这个功能. 请认为我是新手. 解决方法
听起来你只想让密码失效一次.如果您希望定期(例如每隔几个月)执行此操作,或者如果您想阻止用户重新使用密码,则会变得更加复杂.
取自我正在开发的应用程序: app / models / user.rb(假设你的名字是你的名字): def password_should_expire? # your logic goes here,remember it should return false after the password has been reset end 应用程序/控制器/ application_controller.rb before_filter :check_password_expiry def check_password_expiry return if !current_user || ["sessions","passwords"].include?(controller_name) # do nothing if not logged in,or viewing an account-related page # otherwise you might lock them out completely without being able to change their password if current_user.password_should_expire? @expiring_user = current_user # save him for later @expiring_user.generate_reset_password_token! # this is a devise method sign_out(current_user) # log them out and force them to use the reset token to create a new password redirect_to edit_password_url(@expiring_user,:reset_password_token => @expiring_user.reset_password_token,:forced_reset => true) end end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |