summaryrefslogtreecommitdiff
path: root/app/controllers/api/authentications_controller/create_logic.rb
blob: 782c76006d946205cb406194de9beb57d9bb1346 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen_string_literal: true

module Api
  class AuthenticationsController
    # The logic for the create method of AuthenticationsController.
    class CreateLogic
      include TokenGenerationConcern

      def initialize(params)
        @email = params[:email]
        @password = params[:password]
        @user_account = UserAccount.find_by(email: @email)
      end

      def call
        return unless @user_account&.authenticate(@password)

        generate_user_session_key(@user_account)
        generate_token
      end
    end
  end
end