cats_core 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45dbf26292f9ebc98fb50e4195e44773184d3f460c0d5aadb3c45afcffffa752
4
- data.tar.gz: 7cab2b31272ec765c42d8cd8724f1d8f3daff1481fd82057edf08ed40ce389b3
3
+ metadata.gz: 90bb7ac6c5367ab8fd22ede292563557c104607222408c8ed5ed94a32b8a82e2
4
+ data.tar.gz: b4fb9a29a7a65ce4036b361102bde71f756247b0ff37762543fe94e8fc94a06c
5
5
  SHA512:
6
- metadata.gz: 6017835a41ce450bb778aea397234083ac257ec74b1f995a5087811dfae0db693172468ceed14c11ef8433dd26eca298436256ff8fc876a7482e8ce2610d46bb
7
- data.tar.gz: 87ff5af9c3533a23b57ede84a3547818b7f54e51cfb629dbd8f3c26c6de73900f974c2ecb0bc38c999b01bdd29a0b7260daf4ec03510407fae8511d85ae372d3
6
+ metadata.gz: c8c6c949827ee51f1465507caa6301a49af21d47ed2acbf478cb20902733079d1fb630438a9dad3b04df4a1002d1bb9b1e07c5af6c299d250e7d4b11775e045e
7
+ data.tar.gz: abdb8edd5e5bc49d7b954bd37ad23c22081b8d68d4d71fb9def9af20e45bff3ee094e355bc95a17f6ce91676c6fa0832f3d2a9a8767d17e1fdd04f5e5c942a34
@@ -0,0 +1,37 @@
1
+ module Cats
2
+ module Core
3
+ class AccessController < ApplicationController
4
+ skip_before_action :authenticate, only: [:login]
5
+
6
+ def login
7
+ user = Cats::Core::User.find_by(email: auth_params[:email])
8
+ if user
9
+ if user.authenticate(auth_params[:password])
10
+ roles = user.roles.map(&:name)
11
+
12
+ unless roles.count.positive?
13
+ render json: { error: 'User has no roles.' }, status: :unprocessable_entity
14
+ return
15
+ end
16
+
17
+ payload = {
18
+ id: user.id, email: user.email, first_name: user.first_name, last_name: user.last_name, roles: roles
19
+ }
20
+ jwt = Cats::Core::TokenAuthService.issue(payload)
21
+ render json: { token: jwt, user: payload }
22
+ else
23
+ rener json: { error: 'Invalid username or password.' }, status: 400
24
+ end
25
+ else
26
+ render json: { error: 'User does not exist.' }, status: 400
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def auth_params
33
+ params.require(:auth).permit(:email, :password)
34
+ end
35
+ end
36
+ end
37
+ end
data/config/routes.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  Cats::Core::Engine.routes.draw do
2
+ post '/login', controller: :access, action: :login
2
3
  get '/notifications/unread', controller: :notifications, action: :unread
3
4
  get '/notifications/read', controller: :notifications, action: :read
4
5
 
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.0.8'.freeze
3
+ VERSION = '1.0.9'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cats_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
@@ -216,6 +216,7 @@ files:
216
216
  - MIT-LICENSE
217
217
  - README.md
218
218
  - Rakefile
219
+ - app/controllers/cats/core/access_controller.rb
219
220
  - app/controllers/cats/core/application_controller.rb
220
221
  - app/controllers/cats/core/notifications_controller.rb
221
222
  - app/controllers/cats/core/roles_controller.rb