Class: Profiles::PasswordsController

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

Instance Method Summary collapse

Instance Method Details

#createObject


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

def create
  unless @user.password_automatically_set || @user.valid_password?(user_params[:current_password])
    redirect_to new_profile_password_path, alert: 'You must provide a valid current password'
    return
  end

  new_password = user_params[:password]
  new_password_confirmation = user_params[:password_confirmation]

  result = @user.update_attributes(
    password: new_password,
    password_confirmation: new_password_confirmation,
    password_automatically_set: false
  )

  if result
    @user.update_attributes(password_expires_at: nil)
    redirect_to root_path, notice: 'Password successfully changed'
  else
    render :new
  end
end

#editObject


35
36
# File 'app/controllers/profiles/passwords_controller.rb', line 35

def edit
end

#newObject


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

def new
end

#resetObject


57
58
59
60
# File 'app/controllers/profiles/passwords_controller.rb', line 57

def reset
  current_user.send_reset_password_instructions
  redirect_to edit_profile_password_path, notice: 'We sent you an email with reset password instructions'
end

#updateObject


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/profiles/passwords_controller.rb', line 38

def update
  password_attributes = user_params.select do |key, value|
    %w(password password_confirmation).include?(key.to_s)
  end
  password_attributes[:password_automatically_set] = false

  unless @user.password_automatically_set || @user.valid_password?(user_params[:current_password])
    redirect_to edit_profile_password_path, alert: 'You must provide a valid current password'
    return
  end

  if @user.update_attributes(password_attributes)
    flash[:notice] = "Password was successfully updated. Please login with it"
    redirect_to new_user_session_path
  else
    render 'edit'
  end
end