summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/api/authentications_controller.rb8
-rw-r--r--app/controllers/services/token_generation_service.rb4
2 files changed, 8 insertions, 4 deletions
diff --git a/app/controllers/api/authentications_controller.rb b/app/controllers/api/authentications_controller.rb
index f2fb993..85ef3d4 100644
--- a/app/controllers/api/authentications_controller.rb
+++ b/app/controllers/api/authentications_controller.rb
@@ -6,12 +6,12 @@ module Api
AUTHENTICATION_ERROR = 'Credenciales incorrectas'
def create
- @logic = logic
+ @logic = logic.new(permitted_params)
@token = @logic.call
- render json: @token && return if @token
+ render json: @token, status: :ok and return if @token
- render json: { message: AUTHENTICATION_ERROR}, status: :unauthorized
+ render json: { message: AUTHENTICATION_ERROR }, status: :unauthorized
end
def destroy; end
@@ -21,7 +21,7 @@ module Api
private
def permitted_params
- params.require(:user_account).permit(:email, :password)
+ params.require(:credentials).permit(:email, :password)
end
def service
diff --git a/app/controllers/services/token_generation_service.rb b/app/controllers/services/token_generation_service.rb
index 2df2ea6..b1bc10a 100644
--- a/app/controllers/services/token_generation_service.rb
+++ b/app/controllers/services/token_generation_service.rb
@@ -8,6 +8,10 @@ module Services
@role = params[:role]
end
+ def call(expiration)
+ JWT.encode(payload.merge({ exp: expiration.to_i }), ENV['HMAC_SECRET_KEY'], 'HS512')
+ end
+
private
def payload