From 42671b4b5f38064faba02c6e220c425f39afd87c Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Thu, 23 Feb 2023 17:30:00 -0600 Subject: AƱade login MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/authentications_controller/create_logic.rb | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 app/controllers/api/authentications_controller/create_logic.rb (limited to 'app/controllers/api/authentications_controller/create_logic.rb') diff --git a/app/controllers/api/authentications_controller/create_logic.rb b/app/controllers/api/authentications_controller/create_logic.rb new file mode 100644 index 0000000..173db58 --- /dev/null +++ b/app/controllers/api/authentications_controller/create_logic.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +module Services + class AuthenticationsController + # The logic for the create method of AuthenticationsController. + class CreateLogic + def initialize(params) + @email = params[:email] + @password = params[:password] + @user_account = UserAccount.find_by(email: @email) + end + + def call + return false if @user_account.nil? && wrong_user_password? + + { token: service.call(DateTime.now + 30.minutes), refresh: service.call(DateTime.now + 3.days) } + end + + private + + def wrong_user_password? + @user_account.password != @password + end + + def service + @service ||= Services::TokenGenerationService.new(service_params) + end + + def service_params + { email: @email, role: @user_account.role} + end + end + end +end -- cgit v1.2.3