From 41a17f47ae275f8e84de03115e142cc23526bacc Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Fri, 3 Mar 2023 20:34:06 -0600 Subject: AƱade refactorizaciones MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/authentications_controller.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'app/controllers/api/authentications_controller.rb') diff --git a/app/controllers/api/authentications_controller.rb b/app/controllers/api/authentications_controller.rb index 3eb52c7..b9a6f08 100644 --- a/app/controllers/api/authentications_controller.rb +++ b/app/controllers/api/authentications_controller.rb @@ -4,20 +4,29 @@ module Api # The controller that handles authentications. class AuthenticationsController < ApplicationController def create - @token = logic(permitted_params).call + @current_user_account = UserAccount.find_by(email: permitted_params[:email]) - render json: @token, status: :ok and return if @token + unless @current_user_account&.authenticate(permitted_params[:password]) + render json: { error_message: 'Credenciales incorrectas' }, status: :unauthorized and return + end - render json: { error_message: 'Credenciales incorrectas' }, status: :unauthorized + render json: generate_token, status: :ok end def destroy current_user_account.session_key = nil current_user_account.save + + render status: :no_content end private + def service_params + { email: @current_user_account.email, + role: @current_user_account.role } + end + def permitted_params params.require(:credentials).permit(:email, :password) end -- cgit v1.2.3