cafmal 0.22.0 → 0.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cafmal/auth.rb +40 -19
- data/lib/cafmal/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d6712ce334fc95292bc85613b620f54a5ae86a2
|
4
|
+
data.tar.gz: 696029cbc24ad382f20074fb4ff8b68a70c7f5d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bcbe576328a29f763cd5adaf681e9145e7161848566d83ee577a09203f9d58b924d8d5f81e48ca27f2bf4a4abaeda4f4a954ece956c9d410a18ada34180b96e
|
7
|
+
data.tar.gz: 02e7fcad6e7c1e140716e0d383cc48106f51a9225a0b62fd10ef245a11d39b95e15a3db9d2684ec05fb7a4e5a2eea5d2e5325040d171e00c74307d1f646a252d
|
data/lib/cafmal/auth.rb
CHANGED
@@ -38,7 +38,7 @@ module Cafmal
|
|
38
38
|
@decoded_token['header'] = JSON.parse(Base64.decode64(@token.split('.')[0]))
|
39
39
|
@decoded_token['payload'] = JSON.parse(Base64.decode64(@token.split('.')[1]))
|
40
40
|
|
41
|
-
if (@decoded_token['payload']['role']
|
41
|
+
if (@decoded_token['payload']['role'] != 'worker' && @decoded_token['payload']['role'] != 'alerter')
|
42
42
|
team_id = JSON.parse(Cafmal::User.new(@cafmal_api_url, @token).show(@decoded_token['payload']['sub']))["team_id"]
|
43
43
|
event = Cafmal::Event.new(@cafmal_api_url, @token)
|
44
44
|
event.create({name: 'user.login', message: "#{email} has logged in.", kind: 'login', severity: 'info', team_id: team_id})
|
@@ -52,31 +52,52 @@ module Cafmal
|
|
52
52
|
|
53
53
|
# we supply the token here, so web does not have to cache the auth obj
|
54
54
|
def logout(token)
|
55
|
-
|
56
|
-
headers = {"Content-Type" => "application/json", "Authorization" => "Bearer #{token}"}
|
55
|
+
headers = {"Content-Type" => "application/json", "Authorization" => "Bearer #{token}"}
|
57
56
|
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
decoded_token = {}
|
58
|
+
decoded_token['header'] = JSON.parse(Base64.decode64(token.split('.')[0]))
|
59
|
+
decoded_token['payload'] = JSON.parse(Base64.decode64(token.split('.')[1]))
|
61
60
|
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
user = JSON.parse(Cafmal::User.new(@cafmal_api_url, token).show(decoded_token['payload']['sub']))
|
62
|
+
team_id = user["team_id"]
|
63
|
+
email = user["email"]
|
65
64
|
|
66
|
-
|
65
|
+
#@TODO if you are the last logged in user, unsilence your team alerts
|
67
66
|
|
68
|
-
|
69
|
-
|
67
|
+
# kind has to be login, as it's a label of events
|
68
|
+
event_id = JSON.parse(Cafmal::Event.new(@cafmal_api_url, token).create({name: 'user.logout', message: "#{email} has logged out.", kind: 'login', severity: 'info', team_id: team_id}))
|
70
69
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
70
|
+
if event_id.nil?
|
71
|
+
false
|
72
|
+
else
|
73
|
+
@token = nil
|
74
|
+
@decoded_token = nil
|
75
|
+
true
|
78
76
|
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# refresh token
|
80
|
+
def refresh
|
81
|
+
headers = {"Content-Type" => "application/json", "Authorization" => "Bearer #{@token}"}
|
82
|
+
credentials = {token: @token}.to_json
|
83
|
+
refresh_request = Cafmal::Request::Post.new(@cafmal_api_url + '/user_token_refresh', credentials, headers)
|
84
|
+
if refresh_request.code < 300
|
85
|
+
@token = JSON.parse(refresh_request.response.body)['jwt']
|
86
|
+
@decoded_token = {}
|
87
|
+
@decoded_token['header'] = JSON.parse(Base64.decode64(@token.split('.')[0]))
|
88
|
+
@decoded_token['payload'] = JSON.parse(Base64.decode64(@token.split('.')[1]))
|
79
89
|
|
90
|
+
if (@decoded_token['payload']['role'] != 'worker' && @decoded_token['payload']['role'] != 'alerter')
|
91
|
+
team_id = JSON.parse(Cafmal::User.new(@cafmal_api_url, @token).show(@decoded_token['payload']['sub']))["team_id"]
|
92
|
+
event = Cafmal::Event.new(@cafmal_api_url, @token)
|
93
|
+
event.create({name: 'user.refresh_login', message: "#{@decoded_token['payload']['email']} has refreshed his login.", kind: 'login', severity: 'info', team_id: team_id})
|
94
|
+
|
95
|
+
#@TODO silence all alerts for your team_id, set silenced_at now + 1h
|
96
|
+
end
|
97
|
+
return true
|
98
|
+
else
|
99
|
+
return false
|
100
|
+
end
|
80
101
|
end
|
81
102
|
end
|
82
103
|
end
|
data/lib/cafmal/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cafmal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.23.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nils Bartels
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|