Похоже, вы просто хотите истечь пароль один раз.Если вы хотите делать это через регулярные промежутки времени (например, каждые пару месяцев) или хотите запретить пользователям повторно использовать пароли, это усложняется.
Взято из приложения, в котором я работаюon:
app / models / user.rb (при условии, что вы так называете свою модель):
def password_should_expire?
# your logic goes here, remember it should return false after the password has been reset
end
app / controllers / 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