redis-email_activation_token 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7501bd54b29af74272aaf40bc26c4588140f0e3
|
4
|
+
data.tar.gz: 06cbd9553d6dd05bf6811ed189064feaf4051d2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8717bed253c68e3b10bc3c201d628ec1a0b1a287dcf8af0a64cedc09be1febd6f9d82dbdbcc20503725d342a1b5097dc38268715f5e4a5cf232f9035439facd7
|
7
|
+
data.tar.gz: 947625b41e6e9ebfcbcd677f2d1e7921e0c2fa79a90dc1de0dc39e19491a96cf78d8c984f68bd5691181c796d28d0251cc8d52b62b7371d1ac723577165a7759
|
@@ -2,43 +2,42 @@ require 'redis'
|
|
2
2
|
|
3
3
|
class Redis
|
4
4
|
class EmailActivationToken
|
5
|
-
|
6
|
-
|
7
|
-
def initialize(email, opts = {})
|
8
|
-
@email = email
|
9
|
-
@expire = opts.delete(:expire) || 259200 # default 3 days
|
5
|
+
def initialize(opts = {})
|
10
6
|
@redis = opts.delete(:redis) || Redis.new(opts)
|
7
|
+
end
|
11
8
|
|
12
|
-
|
9
|
+
def generate(email, expire: 259200)
|
10
|
+
token = generate_token
|
11
|
+
set_key(email, token, expire)
|
12
|
+
token
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
17
|
-
false
|
18
|
-
else
|
19
|
-
set_key
|
20
|
-
get
|
21
|
-
end
|
15
|
+
def get(token)
|
16
|
+
get_key token
|
22
17
|
end
|
23
18
|
|
24
|
-
def
|
25
|
-
@redis.
|
19
|
+
def get_email(token)
|
20
|
+
@redis.hget(token, "email")
|
26
21
|
end
|
27
22
|
|
28
|
-
def
|
29
|
-
@redis.
|
23
|
+
def get_created_at(token)
|
24
|
+
Time.parse @redis.hget(token, "created_at")
|
30
25
|
end
|
31
26
|
|
32
27
|
private
|
33
28
|
|
34
|
-
def set_key
|
35
|
-
@redis.
|
36
|
-
@redis.
|
29
|
+
def set_key(email, token, expire)
|
30
|
+
@redis.hset(token, "email", email)
|
31
|
+
@redis.hset(token, "created_at", Time.now)
|
32
|
+
@redis.expire(token, expire)
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_key(token)
|
36
|
+
{ token: token, email: get_email(token), created_at: get_created_at(token) }
|
37
37
|
end
|
38
38
|
|
39
39
|
def generate_token
|
40
40
|
SecureRandom.urlsafe_base64
|
41
41
|
end
|
42
|
-
|
43
42
|
end
|
44
43
|
end
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["3280467rec@gmail.com"]
|
11
11
|
spec.summary = %q{Create email activation token by redis}
|
12
12
|
spec.description = %q{}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://github.com/onigra/redis-email_activation_token"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -2,7 +2,7 @@ require File.expand_path(File.join('../../../', 'spec_helper'), File.dirname(__F
|
|
2
2
|
|
3
3
|
describe "redis" do
|
4
4
|
before :all do
|
5
|
-
@redis = Redis.new :
|
5
|
+
@redis = Redis.new db: 15
|
6
6
|
end
|
7
7
|
|
8
8
|
before :each do
|
@@ -10,70 +10,57 @@ describe "redis" do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
after :all do
|
13
|
+
@redis.flushdb
|
13
14
|
@redis.quit
|
14
15
|
end
|
15
16
|
|
16
17
|
describe Redis::EmailActivationToken do
|
17
|
-
let(:
|
18
|
+
let(:email) { Faker::Internet.free_email }
|
19
|
+
let(:obj) { described_class.new(redis: @redis) }
|
18
20
|
|
19
|
-
describe "#create" do
|
20
|
-
context "nothing" do
|
21
|
-
subject { obj.create }
|
22
21
|
|
22
|
+
describe "#generate" do
|
23
|
+
context "Success" do
|
23
24
|
it "Return Activation Token" do
|
24
|
-
|
25
|
+
expect(obj.generate email).to be_kind_of String
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
|
-
context "
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
context "Set expire time" do
|
30
|
+
it "Could set expiry" do
|
31
|
+
token = obj.generate(email, expire: 2)
|
32
|
+
sleep 3
|
33
|
+
expect(@redis.exists token).to be_falsy
|
34
|
+
end
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
35
|
-
describe "#
|
36
|
-
|
37
|
-
|
38
|
-
it { is_expected.to be_falsy }
|
39
|
-
end
|
38
|
+
describe "#get" do
|
39
|
+
let(:token) { obj.generate email }
|
40
|
+
subject { obj.get token }
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
subject
|
44
|
-
|
42
|
+
it "Return token infomation hash" do
|
43
|
+
expect(subject[:token]).to eq token
|
44
|
+
expect(subject[:email]).to eq email
|
45
|
+
expect(subject[:created_at]).to be_kind_of Time
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
|
-
describe "#
|
49
|
-
|
50
|
-
subject { obj.get }
|
51
|
-
it { is_expected.to be_falsy }
|
52
|
-
end
|
53
|
-
|
54
|
-
context "exists" do
|
55
|
-
before { obj.create }
|
56
|
-
subject { obj.get }
|
49
|
+
describe "#get_email" do
|
50
|
+
let(:token) { obj.generate email }
|
57
51
|
|
58
|
-
|
59
|
-
|
60
|
-
end
|
52
|
+
it "Token is can get email" do
|
53
|
+
expect(obj.get_email token).to eq email
|
61
54
|
end
|
62
55
|
end
|
63
56
|
|
64
|
-
describe "
|
65
|
-
let(:
|
66
|
-
|
67
|
-
it "expite == 5" do
|
68
|
-
expect(obj.expire).to eq 5
|
69
|
-
end
|
57
|
+
describe "#get_created_at" do
|
58
|
+
let(:token) { obj.generate email }
|
70
59
|
|
71
|
-
it "
|
72
|
-
obj.
|
73
|
-
sleep 6
|
74
|
-
expect(obj.exists?).to be_falsy
|
60
|
+
it "Token is can get created_at" do
|
61
|
+
expect(obj.get_created_at token).to be_kind_of Time
|
75
62
|
end
|
76
63
|
end
|
77
|
-
end
|
78
64
|
|
65
|
+
end
|
79
66
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-email_activation_token
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- onigra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -90,7 +90,7 @@ files:
|
|
90
90
|
- redis-email_activation_token.gemspec
|
91
91
|
- spec/lib/redis/email_activation_token/redis_ext_spec.rb
|
92
92
|
- spec/spec_helper.rb
|
93
|
-
homepage:
|
93
|
+
homepage: https://github.com/onigra/redis-email_activation_token
|
94
94
|
licenses:
|
95
95
|
- MIT
|
96
96
|
metadata: {}
|