redis-email_signup_verification 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +16 -0
- data/.pryrc +5 -0
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/Gemfile +21 -0
- data/Guardfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +2 -0
- data/lib/redis-email_signup_verification.rb +1 -0
- data/lib/redis/email_signup_verification.rb +6 -0
- data/lib/redis/email_signup_verification/redis_ext.rb +53 -0
- data/lib/redis/email_signup_verification/version.rb +5 -0
- data/redis-email_signup_verification.gemspec +25 -0
- data/spec/lib/redis/email_signup_verification/redis_ext_spec.rb +77 -0
- data/spec/spec_helper.rb +8 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 07cb0bcd1674e2d95847b1d0957a0a7cdc72e7bc
|
4
|
+
data.tar.gz: 41855e0756ce59449a364828bba4f205c36f9e9f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6394ef599c28efb6f9b8b6d18062768872960d49a60af5109dc4c406bd84f5c59c1961b443ec9f8b2fdd77f3ccf0a6aa181a8c47585fa993fc9291bb3ae10960
|
7
|
+
data.tar.gz: 43362fa90543bd09a5c5d6510c2f542792b3766c0a40497b583516f349465e85315c545ffd42af74adf988a8e1a883c0395b113c6296cb393a569472e9b6fe5b
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.pryrc
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
gem 'redis'
|
6
|
+
gem 'bcrypt'
|
7
|
+
|
8
|
+
group :test, :development do
|
9
|
+
gem 'ffaker'
|
10
|
+
gem 'awesome_print'
|
11
|
+
|
12
|
+
gem 'guard'
|
13
|
+
gem 'guard-rspec'
|
14
|
+
gem 'growl'
|
15
|
+
|
16
|
+
gem 'byebug'
|
17
|
+
gem 'pry-rails'
|
18
|
+
gem 'pry-doc'
|
19
|
+
gem 'pry-byebug'
|
20
|
+
gem 'pry-stack_explorer'
|
21
|
+
end
|
data/Guardfile
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
2
|
+
watch(%r{^spec/.+_spec\.rb$})
|
3
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
4
|
+
watch('spec/spec_helper.rb') { "spec" }
|
5
|
+
|
6
|
+
watch(%r{^lib/redis/email_signup_verification/redis_ext.rb$}) { |m| "spec/lib/redis/email_signup_verification/redis_ext_spec.rb" }
|
7
|
+
end
|
8
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 onigra
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Redis::EmailSignupVerification
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/onigra/redis-email_signup_verification.svg?branch=master)](https://travis-ci.org/onigra/redis-email_signup_verification) [![Coverage Status](https://coveralls.io/repos/onigra/redis-email_signup_verification/badge.png?branch=master)](https://coveralls.io/r/onigra/redis-email_signup_verification?branch=master) [![Code Climate](https://codeclimate.com/github/onigra/redis-email_signup_verification/badges/gpa.svg)](https://codeclimate.com/github/onigra/redis-email_signup_verification)
|
4
|
+
|
5
|
+
TODO: Write a gem description
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'redis-email_signup_verification'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install redis-email_signup_verification
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it ( https://github.com/[my-github-username]/redis-email_signup_verification/fork )
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'redis/email_signup_verification'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class Redis
|
2
|
+
class EmailSignupVerification
|
3
|
+
EXPIRE = 259200
|
4
|
+
|
5
|
+
def initialize(opts = {})
|
6
|
+
@redis = opts.delete(:redis) || Redis.new(opts)
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate(email, password, expire: EXPIRE)
|
10
|
+
token = generate_token
|
11
|
+
set_key(email, password, token, expire)
|
12
|
+
token
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(token)
|
16
|
+
get_key token
|
17
|
+
end
|
18
|
+
|
19
|
+
def email(token)
|
20
|
+
@redis.hget(token, "email")
|
21
|
+
end
|
22
|
+
|
23
|
+
def password(token)
|
24
|
+
@redis.hget(token, "password")
|
25
|
+
end
|
26
|
+
|
27
|
+
def created_at(token)
|
28
|
+
Time.parse @redis.hget(token, "created_at")
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def set_key(email, password, token, expire)
|
34
|
+
@redis.hset(token, "email", email)
|
35
|
+
@redis.hset(token, "password", BCrypt::Password.create(password))
|
36
|
+
@redis.hset(token, "created_at", Time.now)
|
37
|
+
@redis.expire(token, expire)
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_key(token)
|
41
|
+
{
|
42
|
+
token: token,
|
43
|
+
email: email(token),
|
44
|
+
password: password(token),
|
45
|
+
created_at: created_at(token)
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def generate_token
|
50
|
+
SecureRandom.urlsafe_base64 40
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'redis/email_signup_verification/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "redis-email_signup_verification"
|
8
|
+
spec.version = Redis::EmailSignupVerification::VERSION
|
9
|
+
spec.authors = ["onigra"]
|
10
|
+
spec.email = ["3280467rec@gmail.com"]
|
11
|
+
spec.summary = %q{Email SignUp Verification By Redis}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = "https://github.com/onigra/redis-email_signup_verification"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "coveralls"
|
25
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path(File.join('../../../', 'spec_helper'), File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe "redis" do
|
4
|
+
before :all do
|
5
|
+
@redis = Redis.new db: 15
|
6
|
+
end
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
@redis.flushdb
|
10
|
+
end
|
11
|
+
|
12
|
+
after :all do
|
13
|
+
@redis.flushdb
|
14
|
+
@redis.quit
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Redis::EmailSignupVerification do
|
18
|
+
let(:email) { Faker::Internet.free_email }
|
19
|
+
let(:password) { Faker::Internet.password }
|
20
|
+
let(:obj) { described_class.new(redis: @redis) }
|
21
|
+
|
22
|
+
describe "#generate" do
|
23
|
+
context "Success" do
|
24
|
+
it "Return verification token" do
|
25
|
+
expect(obj.generate email, password).to be_kind_of String
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "Set expire time" do
|
30
|
+
it "Could set expiry" do
|
31
|
+
token = obj.generate(email, password, expire: 2)
|
32
|
+
sleep 3
|
33
|
+
expect(@redis.exists token).to be_falsy
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#get" do
|
39
|
+
let(:token) { obj.generate email, password }
|
40
|
+
subject { obj.get token }
|
41
|
+
|
42
|
+
it "Return token infomation hash" do
|
43
|
+
expect(subject[:token]).to eq token
|
44
|
+
expect(subject[:email]).to eq email
|
45
|
+
expect(subject[:password]).to be_kind_of String
|
46
|
+
expect(subject[:created_at]).to be_kind_of Time
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#email" do
|
51
|
+
let(:token) { obj.generate email, password }
|
52
|
+
|
53
|
+
it "Token is can get email" do
|
54
|
+
expect(obj.email token).to eq email
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#password" do
|
59
|
+
let(:token) { obj.generate email, password }
|
60
|
+
|
61
|
+
it "Token is can get password and password is encrypted" do
|
62
|
+
encrypted_password = BCrypt::Password.new(obj.password token)
|
63
|
+
|
64
|
+
expect(encrypted_password).to eq password
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#created_at" do
|
69
|
+
let(:token) { obj.generate email, password }
|
70
|
+
|
71
|
+
it "Token is can get created_at" do
|
72
|
+
expect(obj.created_at token).to be_kind_of Time
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redis-email_signup_verification
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- onigra
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: ''
|
70
|
+
email:
|
71
|
+
- 3280467rec@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".coveralls.yml"
|
77
|
+
- ".gitignore"
|
78
|
+
- ".pryrc"
|
79
|
+
- ".rspec"
|
80
|
+
- ".travis.yml"
|
81
|
+
- Gemfile
|
82
|
+
- Guardfile
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- lib/redis-email_signup_verification.rb
|
87
|
+
- lib/redis/email_signup_verification.rb
|
88
|
+
- lib/redis/email_signup_verification/redis_ext.rb
|
89
|
+
- lib/redis/email_signup_verification/version.rb
|
90
|
+
- redis-email_signup_verification.gemspec
|
91
|
+
- spec/lib/redis/email_signup_verification/redis_ext_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
homepage: https://github.com/onigra/redis-email_signup_verification
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.2.2
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Email SignUp Verification By Redis
|
117
|
+
test_files:
|
118
|
+
- spec/lib/redis/email_signup_verification/redis_ext_spec.rb
|
119
|
+
- spec/spec_helper.rb
|
120
|
+
has_rdoc:
|