summaryrefslogtreecommitdiff
path: root/app/controllers/concerns/token_generation_concern.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/concerns/token_generation_concern.rb')
-rw-r--r--app/controllers/concerns/token_generation_concern.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/app/controllers/concerns/token_generation_concern.rb b/app/controllers/concerns/token_generation_concern.rb
new file mode 100644
index 0000000..7f43e4c
--- /dev/null
+++ b/app/controllers/concerns/token_generation_concern.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+# Common logic for all the logics that require the token generation
+# service.
+module TokenGenerationConcern
+ extend ActiveSupport::Concern
+
+ def service
+ @service ||= Services::TokenGenerationService.new(service_params)
+ end
+
+ def generate_user_session_key
+ @user_account.session_key = SecureRandom.hex(16)
+ @user_account.save
+ end
+
+ def generate_token
+ { token: service.call(DateTime.current + 30.minutes), refresh: service.call(DateTime.current + 3.days) }
+ end
+end