Class: EgovUtils::PasswordsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/egov_utils/passwords_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/egov_utils/passwords_controller.rb', line 31

def create
  if change_password!(@user)
    EgovUtils::UserMailer.with(host: mailer_host).password_change_info(@user).deliver_later
    flash[:notice] = t(:notice_password_changed)
    redirect_to main_app.root_path
  else
    flash[:warning] = t(:warning_password_not_changed)
    redirect_to reset_passwords
  end
end

#editObject



42
43
44
# File 'app/controllers/egov_utils/passwords_controller.rb', line 42

def edit
  @user = current_user
end

#newObject

New password for existing user - password reset



29
30
# File 'app/controllers/egov_utils/passwords_controller.rb', line 29

def new
end

#resetObject



11
12
13
# File 'app/controllers/egov_utils/passwords_controller.rb', line 11

def reset
  return render_404 unless EgovUtils::Settings.allow_password_reset?
end

#send_reset_tokenObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/egov_utils/passwords_controller.rb', line 15

def send_reset_token
  return render_404 unless EgovUtils::Settings.allow_password_reset?
  @user = EgovUtils::User.find_by(mail: params[:reset_password][:mail])
  if @user && @user.password_change_possible?
    @token = @user.generate_reset_password_token
    EgovUtils::UserMailer.with(host: mailer_host).password_reset(@user, @token).deliver_later if @user.save
    flash[:notice] = t('notice_reset_email_sent')
  elsif @user && !@user.password_change_possible?
    flash[:error] = t('notice_pw_reset_not_possible')
  end
  redirect_to egov_utils.reset_passwords_path
end

#updateObject



46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/egov_utils/passwords_controller.rb', line 46

def update
  @user = current_user
  if @user.password_check?(params[:password_change][:current_password]) && change_password!(@user)
    EgovUtils::UserMailer.password_change_info(@user).deliver_later
    flash[:notice] = t(:notice_password_changed)
    redirect_to main_app.root_path
  else
    flash[:warning] = t(:warning_password_not_changed)
    redirect_to edit_password_path(@user)
  end
end