Module: Clearance::App::Controllers::PasswordsController::InstanceMethods

Defined in:
lib/clearance/app/controllers/passwords_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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
45
46
47
48
49
50
# File 'lib/clearance/app/controllers/passwords_controller.rb', line 19

def create
  user_as_entered = User.new params[:user]
  @user = user_as_entered
  
  failed_create('Enter an email address.') and return if user_as_entered.email.blank?
  
  found_user = User.find_by_email(user_as_entered.email)

  failed_create('Unknown email') and return if found_user.nil?
  
  if found_user.facebook_user?
    failed_create 'This is a Facebook account, please visit facebook.com to recover your password.'
    return
  end
  
  if found_user.confirmed?
    custom_validation_for_create_message = custom_validation_for_create(found_user)
    if custom_validation_for_create_message.blank?
      found_user.generate_reset_password_code
      ClearanceMailer.deliver_forgot_password found_user
      flash[:success] = "We sent you an email with instructions to reset your password."
      after_create_successful
      return
    else
      @user = user_as_entered
      failed_create(custom_validation_for_create_message)
      return
    end
  end
  
  failed_create('Sorry, this account is not active.')
end

#updateObject



52
53
54
55
56
57
58
59
60
61
# File 'lib/clearance/app/controllers/passwords_controller.rb', line 52

def update
  if @user.reset_password(params)
    session[:user_id] = @user.id
    flash[:success] = "Your password has been updated."
    redirect_to url_after_update
  else
    flash.now[:error] = 'Password not changed.'
    render :action => :edit
  end
end