It looks like you just want the password to expire once. If you want to do this at regular intervals (for example, every couple of months) or if you want to prevent users from reusing passwords, this becomes more difficult.
In the application I'm working on:
app / models / user.rb (assuming you name your model):
def password_should_expire?
application / 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
source share