2024-09-13 16:52:42 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-09-13 16:47:31 +02:00
|
|
|
require "administrate/field/base"
|
|
|
|
|
|
|
|
class JwtField < Administrate::Field::Base
|
|
|
|
def to_s
|
|
|
|
if data.present?
|
|
|
|
begin
|
|
|
|
decoded_token = JWT.decode(data, nil, false)
|
|
|
|
expiration = Time.zone.at(decoded_token[0]['exp'])
|
|
|
|
|
|
|
|
if expiration < Time.zone.now
|
|
|
|
"Token présent, expiré le #{expiration.strftime('%d/%m/%Y à %H:%M')}"
|
|
|
|
else
|
|
|
|
"Token présent, expirera le #{expiration.strftime('%d/%m/%Y à %H:%M')}"
|
|
|
|
end
|
|
|
|
rescue JWT::DecodeError => e
|
|
|
|
"Token invalide : #{e.message}"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
"Pas de token"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|