singularity 0.0.5 → 0.0.6
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/singularity.rb +10 -12
- data/lib/singularity/version.rb +1 -1
- metadata +2 -2
data/lib/singularity.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'redis_hash'
|
3
|
+
require 'securerandom'
|
3
4
|
|
4
5
|
require_relative 'global_user'
|
5
6
|
|
@@ -26,14 +27,7 @@ module Singularity
|
|
26
27
|
|
27
28
|
class << self
|
28
29
|
|
29
|
-
def
|
30
|
-
chars = ['a'..'z','A'..'Z',0..9].map(&:to_a).flatten
|
31
|
-
token = ''
|
32
|
-
length.times { token << chars.sample.to_s }
|
33
|
-
token
|
34
|
-
end
|
35
|
-
|
36
|
-
def generate_session_token(session_id, session)
|
30
|
+
def generate_session_token(session_id, session, options = {})
|
37
31
|
if session.key?("_token_expires") && session["_token_expires"].to_i > Time.now.to_i
|
38
32
|
unless session.nil? || session["_session_id"] != session_id
|
39
33
|
return session["_token"]
|
@@ -41,12 +35,16 @@ module Singularity
|
|
41
35
|
redis.del token_key(session['_token'])
|
42
36
|
end
|
43
37
|
end
|
44
|
-
|
45
|
-
|
38
|
+
|
39
|
+
session_token = SecureRandom.hex(32)
|
40
|
+
token_expiration = options.fetch(:expires, 1800)
|
41
|
+
|
46
42
|
redis.setex token_key(session_token), token_expiration, session_id
|
47
|
-
|
48
|
-
session["
|
43
|
+
|
44
|
+
session["_session_id"] = session_id
|
45
|
+
session["_token"] = session_token
|
49
46
|
session["_token_expires"] = Time.now.to_i + token_expiration
|
47
|
+
|
50
48
|
session_token
|
51
49
|
end
|
52
50
|
|
data/lib/singularity/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: singularity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-10-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: redis-native_hash
|