koinz 0.0.7 → 0.0.8
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.
- data/lib/koinz/controllers/internal_helpers.rb +34 -5
- data/lib/koinz/version.rb +1 -1
- metadata +4 -4
@@ -6,8 +6,15 @@ module Koinz
|
|
6
6
|
# handles auth_token and two-legged token too
|
7
7
|
def login_required
|
8
8
|
if !current_user
|
9
|
-
|
10
|
-
|
9
|
+
respond_to do |format|
|
10
|
+
format.html {
|
11
|
+
session[:user_id] = nil
|
12
|
+
redirect_to login_required_path
|
13
|
+
}
|
14
|
+
format.json {
|
15
|
+
render :json => { 'error' => 'Access Denied' }.to_json
|
16
|
+
}
|
17
|
+
end
|
11
18
|
end
|
12
19
|
end
|
13
20
|
|
@@ -54,16 +61,38 @@ module Koinz
|
|
54
61
|
|
55
62
|
def authenticate_token
|
56
63
|
if params[:access_token]
|
57
|
-
result = Koinz::OAuth2Client::UserManager.call(params[:access_token], '/
|
64
|
+
result = Koinz::OAuth2Client::UserManager.call(params[:access_token], '/isalive.json')
|
58
65
|
return if result.is_a?(Hash) and result[:error]
|
59
|
-
|
66
|
+
|
67
|
+
# All is well
|
68
|
+
session[:last_access] = Time.now.utc
|
60
69
|
end
|
61
70
|
end
|
62
71
|
|
72
|
+
def timedout?
|
73
|
+
return true if not session[:last_access]
|
74
|
+
(session[:last_access] - DEVISE_TIMEOUT.ago) < 1.minute #grace period
|
75
|
+
end
|
76
|
+
|
63
77
|
def current_user
|
64
|
-
authenticate_token
|
78
|
+
authenticate_token if !@current_user or timedout?
|
79
|
+
|
65
80
|
# if not session, bail out
|
66
81
|
return nil unless session[:user_id]
|
82
|
+
|
83
|
+
if timedout?
|
84
|
+
# get/set session from User Manager
|
85
|
+
result = Koinz::OAuth2Client::UserManager.call(get_session_access_token, '/isalive.json')
|
86
|
+
# session has indeed timed out even from user manager - cleanup!
|
87
|
+
if result.is_a?(Hash) and result[:error]
|
88
|
+
session[:user_id] = nil
|
89
|
+
return nil
|
90
|
+
end
|
91
|
+
|
92
|
+
# All is well
|
93
|
+
session[:last_access] = Time.now.utc
|
94
|
+
end
|
95
|
+
|
67
96
|
@current_user ||= get_koinz_user(session[:user_id]['uid'])
|
68
97
|
end
|
69
98
|
end
|
data/lib/koinz/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: koinz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gautam Rege
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-25 00:00:00 +05:30
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|