singularity 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 generate_token(length)
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
- session_token = generate_token(32)
45
- token_expiration = 1800 # 30 minutes # JUNK
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
- session["_session_id"] = session_id
48
- session["_token"] = session_token
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
 
@@ -1,3 +1,3 @@
1
1
  module Singularity
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
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.5
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-08-07 00:00:00.000000000 Z
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