Class: EgovUtils::PasswordsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/egov_utils/passwords_controller.rb', line 28

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



39
40
41
# File 'app/controllers/egov_utils/passwords_controller.rb', line 39

def edit
  @user = current_user
end

#newObject

New password for existing user - password reset



26
27
# File 'app/controllers/egov_utils/passwords_controller.rb', line 26

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
# 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
  end
  redirect_to egov_utils.reset_passwords_path, notice: t('notice_reset_email_sent')
end

#updateObject



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

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