Created
January 25, 2012 22:24
-
-
Save eileencodes/1679257 to your computer and use it in GitHub Desktop.
class PasswordResetsController < ApplicationController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def edit | |
@user = User.find_by_reset_pass_token(params[:id]) | |
if @user.nil? | |
redirect_to '/login', :alert => 'Password reset does not exist.' | |
elsif @user.reset_pass_expiration < 2.hours.ago | |
redirect_to '/login ', :alert => "Password reset has expired." | |
end | |
end | |
def update | |
@user = User.find_by_reset_pass_token!(params[:id]) | |
if @user.update_attributes(params[:user]) | |
@user.reset_pass_token = nil | |
@user.save! | |
# if params are updated create session for user by matching token and pass | |
if @user.valid? | |
session[:user_id] = @user.id | |
redirect_to account_url, :notice => "Your password has been reset!" | |
else | |
render 'update' | |
end | |
else | |
flash.now[:error] = @user.errors.full_messages | |
render :action => "edit" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment