Class: Headstart::PasswordsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/headstart/passwords_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/headstart/passwords_controller.rb', line 13

def create
  email = params[:password][:email]
  email.downcase! if email.present?
  if user = ::User.find_by_email(email)
    user.forgot_password!
    if user.password_reset_token.present?
      if Headstart.configuration.use_delayed_job
        Delayed::Job.enqueue DeliverChangePasswordJob.new(user)
      else
        HeadstartMailer.deliver_change_password(user)
      end
      flash_notice_after_create
      redirect_to(url_after_create)
    else
      flash[:notice] = 'Your password was not able to be recovered. You may never have finished registration.'
      render :template => 'passwords/new'
    end
  else
    flash_failure_after_create
    render :template => 'passwords/new'
  end
end

#editObject



36
37
38
39
40
# File 'app/controllers/headstart/passwords_controller.rb', line 36

def edit
  @user = ::User.find_by_id_and_password_reset_token(
                 params[:user_id], params[:token])
  render :template => 'passwords/edit'
end

#newObject



9
10
11
# File 'app/controllers/headstart/passwords_controller.rb', line 9

def new
  render :template => 'passwords/new'
end

#updateObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/headstart/passwords_controller.rb', line 42

def update
  @user = ::User.find_by_id_and_password_reset_token(
                 params[:user_id], params[:token])

  if @user.update_password(params[:user][:password],
                           params[:user][:password_confirmation])
    (@user)
    flash_success_after_update
    redirect_to(url_after_update)
  else
    render :template => 'passwords/edit'
  end
end