Class: Admin::TokensController
Constant Summary
Koi::Controller::JsonWebToken::SECRET_KEY
Instance Method Summary
collapse
#decode_token, #encode_token
Instance Method Details
#create ⇒ Object
10
11
12
13
14
15
|
# File 'app/controllers/admin/tokens_controller.rb', line 10
def create
admin = Admin::User.find(params[:id])
token = encode_token(admin_id: admin.id, exp: 5.minutes.from_now.to_i, iat: Time.current.to_i)
render locals: { token: }
end
|
#show ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
|
# File 'app/controllers/admin/tokens_controller.rb', line 28
def show
return redirect_to new_admin_session_path, notice: "Token invalid or consumed already" if @token.blank?
admin = Admin::User.find(@token[:admin_id])
if token_utilised?(admin, @token)
return redirect_to new_admin_session_path, notice: "Token invalid or consumed already"
end
render locals: { admin:, token: params[:token] }, layout: "koi/login"
end
|
#update ⇒ Object
17
18
19
20
21
22
23
24
25
26
|
# File 'app/controllers/admin/tokens_controller.rb', line 17
def update
return redirect_to admin_dashboard_path, status: :see_other if admin_signed_in?
return redirect_to new_admin_session_path, status: :see_other, notice: "invalid token" if @token.blank?
admin = Admin::User.find(@token[:admin_id])
sign_in_admin(admin)
redirect_to admin_admin_user_path(admin)
end
|