GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: A Ruby on Rails-based OpenID server for all ya identity providers out there. It is pretty close to the current OpenID specifications and supports SReg, AX (only fetch requests, yet) and PAPE
Homepage: http://dennisbloete.de/projects/masquerade/
Clone URL: git://github.com/dbloete/masquerade.git
Click here to lend your support to: masquerade and make a donation at www.pledgie.com !
masquerade / app / controllers / passwords_controller.rb
100644 44 lines (38 sloc) 1.351 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class PasswordsController < ApplicationController
 
  before_filter :find_account_by_reset_code, :only => [:edit, :update]
 
  # Forgot password
  def create
    if @account = Account.find_by_email(params[:email], :conditions => 'activation_code IS NULL')
      @account.forgot_password!
      flash[:notice] = 'A password reset link has been sent to your email address.'
      redirect_to login_path
    else
      flash[:error] = 'Could not find a user with that email address.'
      render :action => 'new'
    end
  end
  
  # Reset password
  def update
    unless params[:password].blank?
      if @account.update_attributes(:password => params[:password], :password_confirmation => params[:password_confirmation])
        flash[:notice] = 'Password reset.'
        redirect_to login_path
      else
        flash[:error] = 'Password mismatch.'
        render :action => 'edit'
      end
    else
      flash[:error] = 'Password cannot be blank.'
      render :action => 'edit'
    end
  end
  
  private
  
  def find_account_by_reset_code
    @reset_code = params[:id]
    @account = Account.find_by_password_reset_code(@reset_code) unless @reset_code.blank?
    unless @account
      flash[:error] = 'Sorry, your password reset code is invalid. Please check the code and try again.'
      redirect_to new_password_path
    end
  end
  
end