Class: Clearance::PasswordsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/clearance/passwords_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



8
9
10
11
12
13
14
# File 'app/controllers/clearance/passwords_controller.rb', line 8

def create
  if user = find_user_for_create
    user.forgot_password!
    deliver_email(user)
  end
  render template: 'passwords/create'
end

#deliver_email(user) ⇒ Object (private)



39
40
41
42
43
44
45
46
47
# File 'app/controllers/clearance/passwords_controller.rb', line 39

def deliver_email(user)
  mail = ::ClearanceMailer.change_password(user)

  if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new("4.2.0")
    mail.deliver_later
  else
    mail.deliver
  end
end

#editObject



16
17
18
19
# File 'app/controllers/clearance/passwords_controller.rb', line 16

def edit
  @user = find_user_for_edit
  render template: 'passwords/edit'
end

#ensure_existing_userObject (private)



78
79
80
81
82
83
# File 'app/controllers/clearance/passwords_controller.rb', line 78

def ensure_existing_user
  unless find_user_by_id_and_confirmation_token
    flash_failure_when_forbidden
    render template: "passwords/new"
  end
end

#find_user_by_id_and_confirmation_tokenObject (private)



58
59
60
61
62
63
# File 'app/controllers/clearance/passwords_controller.rb', line 58

def find_user_by_id_and_confirmation_token
  user_param = Clearance.configuration.user_id_parameter

  Clearance.configuration.user_model.
    find_by_id_and_confirmation_token params[user_param], params[:token].to_s
end

#find_user_for_createObject (private)



65
66
67
68
# File 'app/controllers/clearance/passwords_controller.rb', line 65

def find_user_for_create
  Clearance.configuration.user_model.
    find_by_normalized_email params[:password][:email]
end

#find_user_for_editObject (private)



70
71
72
# File 'app/controllers/clearance/passwords_controller.rb', line 70

def find_user_for_edit
  find_user_by_id_and_confirmation_token
end

#find_user_for_updateObject (private)



74
75
76
# File 'app/controllers/clearance/passwords_controller.rb', line 74

def find_user_for_update
  find_user_by_id_and_confirmation_token
end

#flash_failure_after_updateObject (private)



91
92
93
94
95
# File 'app/controllers/clearance/passwords_controller.rb', line 91

def flash_failure_after_update
  flash.now[:notice] = translate(:blank_password,
    scope: [:clearance, :controllers, :passwords],
    default: t('flashes.failure_after_update'))
end

#flash_failure_when_forbiddenObject (private)



85
86
87
88
89
# File 'app/controllers/clearance/passwords_controller.rb', line 85

def flash_failure_when_forbidden
  flash.now[:notice] = translate(:forbidden,
    scope: [:clearance, :controllers, :passwords],
    default: t('flashes.failure_when_forbidden'))
end

#newObject



21
22
23
# File 'app/controllers/clearance/passwords_controller.rb', line 21

def new
  render template: 'passwords/new'
end

#password_reset_paramsObject (private)



49
50
51
52
53
54
55
56
# File 'app/controllers/clearance/passwords_controller.rb', line 49

def password_reset_params
  if params.has_key? :user
    ActiveSupport::Deprecation.warn %{Since locales functionality was added, accessing params[:user] is no longer supported.}
    params[:user][:password]
  else
    params[:password_reset][:password]
  end
end

#updateObject



25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/clearance/passwords_controller.rb', line 25

def update
  @user = find_user_for_update

  if @user.update_password password_reset_params
     @user
    redirect_to url_after_update
  else
    flash_failure_after_update
    render template: 'passwords/edit'
  end
end

#url_after_createObject (private)



97
98
99
# File 'app/controllers/clearance/passwords_controller.rb', line 97

def url_after_create
  
end

#url_after_updateObject (private)



101
102
103
# File 'app/controllers/clearance/passwords_controller.rb', line 101

def url_after_update
  Clearance.configuration.redirect_url
end