From 4a1faf270ae328a1a28d9f8f54d9a96ed41a1542 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Sun, 26 Feb 2023 20:20:02 -0600 Subject: Añade métodos de controladores faltantes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/refresh_tokens_controller.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 app/controllers/api/refresh_tokens_controller.rb (limited to 'app/controllers/api/refresh_tokens_controller.rb') diff --git a/app/controllers/api/refresh_tokens_controller.rb b/app/controllers/api/refresh_tokens_controller.rb new file mode 100644 index 0000000..3b0843e --- /dev/null +++ b/app/controllers/api/refresh_tokens_controller.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module Api + # The controller to generate new tokens. + class RefreshTokensController < AuthenticatedController + def create + @current_user_account.update_attribute(:session_key, SecureRandom.hex(16)) + @token = { token: service.call(DateTime.current + 30), refresh: service.call(authentication_token[0]['exp']) } + + render json: @token, status: :ok + end + + def service_params + { email: @current_user_account.email, role: @current_user_account.role, + session_key: @current_user_account.session_key } + end + + def service + @service ||= Services::TokenGenerationService.new(service_params) + end + end +end -- cgit v1.2.3