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 +4 -4
- data/app/controllers/cats/core/access_controller.rb +37 -0
- data/config/routes.rb +1 -0
- data/lib/cats/core/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90bb7ac6c5367ab8fd22ede292563557c104607222408c8ed5ed94a32b8a82e2
|
4
|
+
data.tar.gz: b4fb9a29a7a65ce4036b361102bde71f756247b0ff37762543fe94e8fc94a06c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/lib/cats/core/version.rb
CHANGED
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.
|
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
|