Class: Admin::TokensController

Inherits:
ApplicationController show all
Includes:
Koi::Controller::RecordsAuthentication
Defined in:
app/controllers/admin/tokens_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Koi::Controller::RecordsAuthentication

#record_sign_in!, #record_sign_out!, #update_last_sign_in

Instance Attribute Details

#admin_userObject (readonly)

Returns the value of attribute admin_user.



9
10
11
# File 'app/controllers/admin/tokens_controller.rb', line 9

def admin_user
  @admin_user
end

Instance Method Details

#createObject



19
20
21
# File 'app/controllers/admin/tokens_controller.rb', line 19

def create
  render locals: { token: admin_user.generate_token_for(:password_reset) }
end

#showObject



11
12
13
14
15
16
17
# File 'app/controllers/admin/tokens_controller.rb', line 11

def show
  if (@admin_user = Admin::User.find_by_token_for(:password_reset, params[:token]))
    render locals: { admin_user:, token: params[:token] }, layout: "koi/login"
  else
    redirect_to(new_admin_session_path, status: :see_other, notice: I18n.t("koi.auth.token_invalid"))
  end
end

#updateObject



23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/admin/tokens_controller.rb', line 23

def update
  if (@admin_user = Admin::User.find_by_token_for(:password_reset, params[:token]))
    record_sign_in!(admin_user)

    session[:admin_user_id] = admin_user.id

    redirect_to admin_admin_user_path(admin_user), status: :see_other, notice: t("koi.auth.token_consumed")
  else
    redirect_to(new_admin_session_path, status: :see_other, notice: I18n.t("koi.auth.token_invalid"))
  end
end