Class: Storefront::Users::PasswordsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/workarea/storefront/users/passwords_controller.rb

Instance Method Summary collapse

Instance Method Details

#changeObject



46
47
# File 'app/controllers/workarea/storefront/users/passwords_controller.rb', line 46

def change
end

#createObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/workarea/storefront/users/passwords_controller.rb', line 18

def create
  password_reset = User::PasswordReset.setup!(params[:email])
  if password_reset.present?
    Storefront::AccountMailer.password_reset(password_reset.id.to_s).deliver_later
  end

  flash[:success] = t(
    'workarea.storefront.flash_messages.password_reset_email_sent',
    email: params[:email]
  )
  redirect_to forgot_password_path
end

#editObject



9
10
11
12
13
14
15
16
# File 'app/controllers/workarea/storefront/users/passwords_controller.rb', line 9

def edit
  reset = User::PasswordReset.find_by(token: params[:token]) rescue nil

  unless reset
    flash[:error] = t('workarea.storefront.flash_messages.password_reset_expired')
    redirect_to forgot_password_path
  end
end

#make_changeObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/workarea/storefront/users/passwords_controller.rb', line 49

def make_change
  unless current_user.authenticate(params[:old_password])
    flash[:error] = t('workarea.storefront.flash_messages.old_password_invalid')
    render :change and return
  end

  if params[:password].blank?
    flash[:error] = t('workarea.storefront.flash_messages.password_required')
    render :change and return
  end

  if current_user.update_attributes(password: params[:password])
    flash[:success] = t('workarea.storefront.flash_messages.password_reset')
    redirect_back_or 
  else
    flash[:error] = current_user.errors.full_messages
    render :change and return
  end
end

#newObject



6
7
# File 'app/controllers/workarea/storefront/users/passwords_controller.rb', line 6

def new
end

#updateObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/workarea/storefront/users/passwords_controller.rb', line 31

def update
  reset = User::PasswordReset.find_by(token: params[:token]) rescue nil

  if reset.blank?
    flash[:error] = t('workarea.storefront.flash_messages.password_reset_expired')
    render :edit
  elsif reset.complete(params[:password])
    flash[:success] = t('workarea.storefront.flash_messages.password_reset')
    redirect_to 
  else
    flash[:error] = reset.errors.full_messages.to_sentence
    redirect_to reset_password_path(token: reset.token)
  end
end