token_master 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/.gitignore +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +23 -0
- data/LICENSE.txt +21 -0
- data/README.md +70 -0
- data/Rakefile +13 -0
- data/lib/generators/rails/templates/migration.rb.erb +12 -0
- data/lib/generators/rails/token_master_generator.rb +39 -0
- data/lib/generators/token_master/install_generator.rb +24 -0
- data/lib/generators/token_master/migration_generator.rb +13 -0
- data/lib/generators/token_master/templates/initializer.rb +30 -0
- data/lib/token_master/config.rb +41 -0
- data/lib/token_master/core.rb +168 -0
- data/lib/token_master/error.rb +36 -0
- data/lib/token_master/model.rb +39 -0
- data/lib/token_master/railtie.rb +17 -0
- data/lib/token_master/version.rb +3 -0
- data/lib/token_master.rb +17 -0
- data/token_master.gemspec +21 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5790941a8c9d0ec6eacb36b1df7c473acc880c51
|
4
|
+
data.tar.gz: affb3fad61df083f6a9d723b638d55b3d8e8a27b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4c88cfdaffea449b8393a25ee549972d4a746328f9b0adf7e25ffe9aaf87be9583d3f7ff0859eba2d7fb272050852f21ff298118456d9b1494eaf83b2b1455dc
|
7
|
+
data.tar.gz: d87767fbaf677e52b5aea2904564e5c7888133e288e747e2071d2c4b4248fc9102a85950a508ffe56b681600759d66a880b06230a7ce2b0e8c6c7d3173871afb
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.0
|
data/.travis.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
language: ruby
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
token_master (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
minitest (5.10.1)
|
10
|
+
rake (10.4.2)
|
11
|
+
yard (0.9.8)
|
12
|
+
|
13
|
+
PLATFORMS
|
14
|
+
ruby
|
15
|
+
|
16
|
+
DEPENDENCIES
|
17
|
+
minitest (~> 5.10.1)
|
18
|
+
rake (~> 10.4.2)
|
19
|
+
token_master!
|
20
|
+
yard
|
21
|
+
|
22
|
+
BUNDLED WITH
|
23
|
+
1.14.5
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 LaunchPad Lab
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/LaunchPadLab/token-master.svg?branch=master)](https://travis-ci.org/LaunchPadLab/token-master)
|
2
|
+
|
3
|
+
# token-master
|
4
|
+
User management logic using tokens
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
```
|
8
|
+
class User < ApplicationRecord
|
9
|
+
include TokenMaster::Core
|
10
|
+
|
11
|
+
token_master :confirm, :foobar
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
```
|
16
|
+
## For confirm
|
17
|
+
|
18
|
+
user = User.confirm_by_token!(token, **kwargs)
|
19
|
+
|
20
|
+
token = user.set_confirm_token!
|
21
|
+
|
22
|
+
user.send_confirm_instructions!
|
23
|
+
|
24
|
+
user.confirm_status
|
25
|
+
|
26
|
+
|
27
|
+
## Same for foobar
|
28
|
+
|
29
|
+
User.foobar_by_token!(token)
|
30
|
+
|
31
|
+
...
|
32
|
+
|
33
|
+
```
|
34
|
+
|
35
|
+
## Setup
|
36
|
+
|
37
|
+
```
|
38
|
+
bundle exec rails generate token_master User confirm foobar
|
39
|
+
```
|
40
|
+
|
41
|
+
This creates a migration file for the following columns:
|
42
|
+
```
|
43
|
+
add_column :users, :confirm_token, :string, default: nil
|
44
|
+
add_column :users, :confirm_created_at, :timestamp, default: nil
|
45
|
+
add_column :users, :confirm_completed_at, :timestamp, default: nil
|
46
|
+
add_column :users, :confirm_sent_at, :timestamp, default: nil
|
47
|
+
|
48
|
+
add_index :users, :confirm_token
|
49
|
+
|
50
|
+
add_column :users, :foobar_token, :string, default: nil
|
51
|
+
add_column :users, :foobar_created_at, :timestamp, default: nil
|
52
|
+
add_column :users, :foobar_completed_at, :timestamp, default: nil
|
53
|
+
add_column :users, :foobar_sent_at, :timestamp, default: nil
|
54
|
+
|
55
|
+
add_index :users, :foobar_token
|
56
|
+
```
|
57
|
+
|
58
|
+
This command also creates or updates the TokenMaster initializer file. The initializer will include methods to add configurations for each tokenable, set to the default configurations. Configurations you can set include:
|
59
|
+
|
60
|
+
- Token Lifetime (`:token_lifetime`, takes an integer
|
61
|
+
- Reuired Params (`:token_lifetime`), takes an array
|
62
|
+
- Token Length(`:token_length`), takes an integer
|
63
|
+
|
64
|
+
```
|
65
|
+
config.add_tokenable_options :confirm, TokenMaster::Config::DEFAULT_VALUES
|
66
|
+
|
67
|
+
## OR
|
68
|
+
|
69
|
+
config.add_tokenable_options :reset, token_lifetime: 1, required_params: [:password, :password_confirmation], token_length: 15
|
70
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
class <%= "#{migration_name.classify.pluralize}" %> < <%= migration_class_name %>
|
2
|
+
def change
|
3
|
+
<% attributes_names.each do |attribute| %>
|
4
|
+
add_column :<%= name.tableize %>, <%= ":#{attribute}_token" %>, :string, default: nil
|
5
|
+
add_column :<%= name.tableize %>, <%= ":#{attribute}_created_at" %>, :timestamp, default: nil
|
6
|
+
add_column :<%= name.tableize %>, <%= ":#{attribute}_sent_at" %>, :timestamp, default: nil
|
7
|
+
add_column :<%= name.tableize %>, <%= ":#{attribute}_completed_at" %>, :timestamp, default: nil
|
8
|
+
|
9
|
+
add_index :<%= name.tableize %>, <%= ":#{attribute}_token" %>
|
10
|
+
<% end %>
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Generators
|
5
|
+
class TokenMasterGenerator < ActiveRecord::Generators::Base
|
6
|
+
desc 'Creates a TokenMaster migration for the specified model.'
|
7
|
+
|
8
|
+
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
9
|
+
|
10
|
+
def self.source_root
|
11
|
+
@source_root ||= File.expand_path('../templates', __FILE__)
|
12
|
+
end
|
13
|
+
|
14
|
+
def copy_migration
|
15
|
+
migration_template 'migration.rb.erb', "db/migrate/#{migration_file_name}", migration_version: migration_class_name
|
16
|
+
end
|
17
|
+
|
18
|
+
def migration_name
|
19
|
+
"add_#{attributes_names[0]}_tokenable_to_#{name.underscore.pluralize}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def migration_class_name
|
23
|
+
if Rails::VERSION::MAJOR >= 5
|
24
|
+
"ActiveRecord::Migration[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
25
|
+
else
|
26
|
+
'ActiveRecord::Migration'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def install_generator
|
31
|
+
Rails::Generators.invoke("token_master:install", attributes_names)
|
32
|
+
end
|
33
|
+
|
34
|
+
def migration_file_name
|
35
|
+
"#{migration_name}.rb"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module TokenMaster
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
desc 'Creates a TokenMaster initializer in your application.'
|
7
|
+
|
8
|
+
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
9
|
+
|
10
|
+
def copy_initializer
|
11
|
+
copy_file 'initializer.rb', 'config/initializers/token_master.rb', skip: true
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_options
|
15
|
+
attributes.each do |tokenable|
|
16
|
+
inject_into_file 'config/initializers/token_master.rb', before: 'end' do <<-RUBY
|
17
|
+
config.add_tokenable_options :#{tokenable}, TokenMaster::Config::DEFAULT_VALUES
|
18
|
+
RUBY
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
module TokenMaster
|
5
|
+
module Generators
|
6
|
+
class MigrationGenerator < Rails::Generators::NamedBase
|
7
|
+
namespace 'token_master'
|
8
|
+
source_root File.expand_path('../templates', __FILE__)
|
9
|
+
|
10
|
+
desc 'Generates a migration file for the given model (NAME) with the specified tokenable columns'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
TokenMaster.config do |config|
|
2
|
+
# Set up your configurations for each tokenable using the methods at the bottom of this file.
|
3
|
+
# Examples:
|
4
|
+
|
5
|
+
# 'config.add_tokenable_options :confirm, TokenMaster::Config::DEFAULT_VALUES' results in:
|
6
|
+
|
7
|
+
# config.confirm_options = {
|
8
|
+
# token_lifetime: 14,
|
9
|
+
# required_parms: [],
|
10
|
+
# token_length: 20
|
11
|
+
# }
|
12
|
+
|
13
|
+
# 'config.add_tokenable_options :reset, token_lifetime: 1, required_params: [:password, :password_confirmation], token_length: 15' results in:
|
14
|
+
|
15
|
+
# config.reset_options = {
|
16
|
+
# token_lifetime: 1,
|
17
|
+
# required_parms: [:password, :password_confirmation],
|
18
|
+
# token_length: 20
|
19
|
+
# }
|
20
|
+
|
21
|
+
# 'config.add_tokenable_options :foo, token_lifetime: 10, required_params: [:email, token_length: config.DEFAULT_VALUES[:token_length]' results in:
|
22
|
+
|
23
|
+
# config.foo_options = {
|
24
|
+
# token_lifetime: 10,
|
25
|
+
# required_parms: [:email],
|
26
|
+
# token_length: 20
|
27
|
+
# }
|
28
|
+
|
29
|
+
#### METHODS FOR YOUR CONFIGURATION BELOW ###
|
30
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module TokenMaster
|
2
|
+
class Config
|
3
|
+
DEFAULT_VALUES = {
|
4
|
+
token_lifetime: 14,
|
5
|
+
required_params: [],
|
6
|
+
token_length: 20
|
7
|
+
}
|
8
|
+
|
9
|
+
attr_accessor :options
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@options = {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_tokenable_options(key, **params)
|
16
|
+
@options[key] = params
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_required_params(key)
|
20
|
+
get_option(key, :required_params)
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_token_lifetime(key)
|
24
|
+
get_option(key, :token_lifetime)
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_token_length(key)
|
28
|
+
get_option(key, :token_length)
|
29
|
+
end
|
30
|
+
|
31
|
+
def options_set?(key)
|
32
|
+
@options.key? key
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def get_option(key, option)
|
38
|
+
@options.dig(key, option) || DEFAULT_VALUES[option]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'token_master/error'
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
module TokenMaster
|
5
|
+
# TODO
|
6
|
+
module Core
|
7
|
+
class << self
|
8
|
+
# TODO
|
9
|
+
def do_by_token!(klass, key, token, **params)
|
10
|
+
check_manageable! klass, key
|
11
|
+
token_column = { token_col(key) => token }
|
12
|
+
model = klass.find_by(token_column)
|
13
|
+
check_token_active! model, key
|
14
|
+
check_params! key, params
|
15
|
+
|
16
|
+
model.update!(
|
17
|
+
params.merge(completed_at_col(key) => Time.now)
|
18
|
+
)
|
19
|
+
model
|
20
|
+
end
|
21
|
+
|
22
|
+
# TODO
|
23
|
+
def force_tokenable!(model, key, **params)
|
24
|
+
check_manageable! model.class, key
|
25
|
+
check_params! key, params
|
26
|
+
|
27
|
+
model.update!(
|
28
|
+
params.merge(completed_at_col(key) => Time.now)
|
29
|
+
)
|
30
|
+
model
|
31
|
+
end
|
32
|
+
|
33
|
+
# TODO
|
34
|
+
def set_token!(model, key, token_length = nil)
|
35
|
+
check_manageable! model.class, key
|
36
|
+
check_configs_set! key
|
37
|
+
token_length ||= TokenMaster.config.get_token_length(key.to_sym)
|
38
|
+
token = generate_token token_length
|
39
|
+
|
40
|
+
model.update({
|
41
|
+
token_col(key) => token,
|
42
|
+
created_at_col(key) => Time.now,
|
43
|
+
sent_at_col(key) => nil,
|
44
|
+
completed_at_col(key) => nil
|
45
|
+
})
|
46
|
+
model.save(validate: false)
|
47
|
+
token
|
48
|
+
end
|
49
|
+
|
50
|
+
# TODO
|
51
|
+
def send_instructions!(model, key)
|
52
|
+
check_manageable! model.class, key
|
53
|
+
check_token_set! model, key
|
54
|
+
check_instructions_sent! model, key
|
55
|
+
|
56
|
+
yield if block_given?
|
57
|
+
|
58
|
+
model.update(sent_at_col(key) => Time.now)
|
59
|
+
model.save(validate: false)
|
60
|
+
end
|
61
|
+
|
62
|
+
# TODO
|
63
|
+
def status(model, key)
|
64
|
+
check_manageable! model.class, key
|
65
|
+
return 'completed' if completed?(model, key)
|
66
|
+
return 'sent' if instructions_sent?(model, key)
|
67
|
+
if token_set?(model, key)
|
68
|
+
return 'expired' unless token_active?(model, key)
|
69
|
+
return 'created'
|
70
|
+
end
|
71
|
+
'no token'
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def token_col(key)
|
77
|
+
"#{key}_token".to_sym
|
78
|
+
end
|
79
|
+
|
80
|
+
def created_at_col(key)
|
81
|
+
"#{key}_created_at".to_sym
|
82
|
+
end
|
83
|
+
|
84
|
+
def sent_at_col(key)
|
85
|
+
"#{key}_sent_at".to_sym
|
86
|
+
end
|
87
|
+
|
88
|
+
def completed_at_col(key)
|
89
|
+
"#{key}_completed_at".to_sym
|
90
|
+
end
|
91
|
+
|
92
|
+
def token_lifetime(key)
|
93
|
+
TokenMaster.config.get_token_lifetime(key.to_sym)
|
94
|
+
end
|
95
|
+
|
96
|
+
def required_params(key)
|
97
|
+
TokenMaster.config.required_params(key.to_sym)
|
98
|
+
end
|
99
|
+
|
100
|
+
def check_manageable!(klass, key)
|
101
|
+
raise NotTokenable, "#{klass} not #{key}able" unless manageable?(klass, key)
|
102
|
+
end
|
103
|
+
|
104
|
+
def manageable?(klass, key)
|
105
|
+
return false unless klass.respond_to? :column_names
|
106
|
+
column_names = klass.column_names
|
107
|
+
%W(
|
108
|
+
#{key}_token
|
109
|
+
#{key}_created_at
|
110
|
+
#{key}_completed_at
|
111
|
+
#{key}_sent_at
|
112
|
+
).all? { |attr| column_names.include? attr }
|
113
|
+
end
|
114
|
+
|
115
|
+
def check_configs_set!(key)
|
116
|
+
raise NotConfigured, 'You have not set the configurations for this tokenable.' unless TokenMaster.config.options_set?(key.to_sym)
|
117
|
+
end
|
118
|
+
|
119
|
+
def check_params!(key, params)
|
120
|
+
required_params = TokenMaster.config.get_required_params(key.to_sym)
|
121
|
+
raise MissingRequiredParams, 'You did not pass in the required params for this tokenable' unless required_params.all? do |k|
|
122
|
+
params.keys.include? k
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def check_token_active!(model, key)
|
127
|
+
raise TokenNotFound, "#{key} token not found" unless model
|
128
|
+
raise TokenCompleted, "#{key} already completed" if completed?(model, key)
|
129
|
+
raise TokenExpired, "#{key} token expired" unless token_active?(model, key)
|
130
|
+
end
|
131
|
+
|
132
|
+
def token_active?(model, key)
|
133
|
+
model.send(token_col(key)) &&
|
134
|
+
model.send(created_at_col(key)) &&
|
135
|
+
Time.now <= (model.send(created_at_col(key)) + ((token_lifetime(key)) * 60 * 60 * 24))
|
136
|
+
end
|
137
|
+
|
138
|
+
def check_instructions_sent!(model, key)
|
139
|
+
raise TokenSent, "#{key} already sent" if instructions_sent?(model, key)
|
140
|
+
end
|
141
|
+
|
142
|
+
def instructions_sent?(model, key)
|
143
|
+
model.send(sent_at_col(key)).present?
|
144
|
+
end
|
145
|
+
|
146
|
+
def token_set?(model, key)
|
147
|
+
model.send(token_col(key)).present?
|
148
|
+
end
|
149
|
+
|
150
|
+
def check_token_set!(model, key)
|
151
|
+
raise TokenNotSet, "#{key}_token not set" unless token_set?(model, key)
|
152
|
+
end
|
153
|
+
|
154
|
+
def completed?(model, key)
|
155
|
+
model.send(completed_at_col(key)).present?
|
156
|
+
end
|
157
|
+
|
158
|
+
def check_completed!(model, key)
|
159
|
+
raise TokenNotCompleted, "#{key} not completed" unless completed?(model, key)
|
160
|
+
end
|
161
|
+
|
162
|
+
def generate_token(length)
|
163
|
+
rlength = (length * 3) / 4
|
164
|
+
SecureRandom.urlsafe_base64(rlength).tr('lIO0', 'sxyz')
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module TokenMaster
|
2
|
+
|
3
|
+
# The base class for all errors raised by TokenMaster
|
4
|
+
class Error < StandardError; end
|
5
|
+
|
6
|
+
# TODO
|
7
|
+
class MissingRequiredParams < Error; end
|
8
|
+
|
9
|
+
# Raised when the attributes for a tokenable do not exist.
|
10
|
+
# This could result from a migration not being run or a spelling error
|
11
|
+
class NotTokenable < Error; end
|
12
|
+
|
13
|
+
# TODO
|
14
|
+
class NotConfigured < Error; end
|
15
|
+
|
16
|
+
# TODO
|
17
|
+
class MissingRequiredParams < Error; end
|
18
|
+
|
19
|
+
# TODO
|
20
|
+
class TokenNotFound < Error; end
|
21
|
+
|
22
|
+
# TODO
|
23
|
+
class TokenCompleted < Error; end
|
24
|
+
|
25
|
+
# TODO
|
26
|
+
class TokenNotCompleted < Error; end
|
27
|
+
|
28
|
+
# TODO
|
29
|
+
class TokenExpired < Error; end
|
30
|
+
|
31
|
+
# TODO
|
32
|
+
class TokenSent < Error; end
|
33
|
+
|
34
|
+
# TODO
|
35
|
+
class TokenNotSet < Error; end
|
36
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module TokenMaster
|
2
|
+
|
3
|
+
# TODO
|
4
|
+
module Model
|
5
|
+
def self.included(base)
|
6
|
+
base.extend(ClassMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
# TODO
|
11
|
+
def token_master(*tokenables)
|
12
|
+
tokenables.each do |tokenable|
|
13
|
+
# instance methods
|
14
|
+
# TODO
|
15
|
+
define_method("set_#{tokenable}_token!") do
|
16
|
+
TokenMaster::Core.set_token!(self, tokenable)
|
17
|
+
end
|
18
|
+
# TODO
|
19
|
+
define_method("send_#{tokenable}_instructions!") do |email|
|
20
|
+
TokenMaster::Core.send_instructions!(self, tokenable, email)
|
21
|
+
end
|
22
|
+
# TODO
|
23
|
+
define_method("#{tokenable}_status") do
|
24
|
+
TokenMaster::Core.status(self, tokenable)
|
25
|
+
end
|
26
|
+
# TODO
|
27
|
+
define_method("force_#{tokenable}!") do |**params|
|
28
|
+
TokenMaster::Core.force_tokenable!(self, tokenable, **params)
|
29
|
+
end
|
30
|
+
# class methods
|
31
|
+
# TODO
|
32
|
+
define_singleton_method("#{tokenable}_by_token!") do |token, **params|
|
33
|
+
TokenMaster::Core.do_by_token!(self, tokenable, token, **params)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'token_master/model'
|
2
|
+
|
3
|
+
module TokenMaster
|
4
|
+
# Automatically include TokenMaster::Model in Rails/ActiveRecord apps.
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
|
7
|
+
initializer 'token_master.active_record' do
|
8
|
+
ActiveSupport.on_load :active_record do
|
9
|
+
if Rails::VERSION::MAJOR >= 5
|
10
|
+
::ApplicationRecord.include(TokenMaster::Model)
|
11
|
+
else
|
12
|
+
::ActiveRecord::Base.include(TokenMaster::Model)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/token_master.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module TokenMaster
|
2
|
+
def self.config
|
3
|
+
@config ||= TokenMaster::Config.new
|
4
|
+
if block_given?
|
5
|
+
yield @config
|
6
|
+
else
|
7
|
+
@config
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'token_master/config'
|
13
|
+
require 'token_master/core'
|
14
|
+
require 'token_master/error'
|
15
|
+
require 'token_master/model'
|
16
|
+
require 'token_master/version'
|
17
|
+
require 'token_master/railtie' if defined?(::Rails)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'token_master/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'token_master'
|
7
|
+
s.version = TokenMaster::VERSION
|
8
|
+
s.date = '2017-02-24'
|
9
|
+
s.summary = 'Token Master!'
|
10
|
+
s.description = 'User management using tokens'
|
11
|
+
s.authors = ['Dave Corwin', 'Ifat Ribon']
|
12
|
+
s.email = 'dave@launchpadlab.com'
|
13
|
+
s.homepage = 'https://github.com/launchpadlab/token-master'
|
14
|
+
s.license = 'MIT'
|
15
|
+
s.files = `git ls-files -z`
|
16
|
+
.split("\x0")
|
17
|
+
.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
|
19
|
+
s.add_development_dependency 'rake', '~> 10.4', '>= 10.4.2'
|
20
|
+
s.add_development_dependency 'minitest', '~> 5.10', '>= 5.10.1'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: token_master
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dave Corwin
|
8
|
+
- Ifat Ribon
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2017-02-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '10.4'
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 10.4.2
|
24
|
+
type: :development
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - "~>"
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '10.4'
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 10.4.2
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: minitest
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.10'
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 5.10.1
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - "~>"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '5.10'
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 5.10.1
|
54
|
+
description: User management using tokens
|
55
|
+
email: dave@launchpadlab.com
|
56
|
+
executables: []
|
57
|
+
extensions: []
|
58
|
+
extra_rdoc_files: []
|
59
|
+
files:
|
60
|
+
- ".gitignore"
|
61
|
+
- ".ruby-version"
|
62
|
+
- ".travis.yml"
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/generators/rails/templates/migration.rb.erb
|
69
|
+
- lib/generators/rails/token_master_generator.rb
|
70
|
+
- lib/generators/token_master/install_generator.rb
|
71
|
+
- lib/generators/token_master/migration_generator.rb
|
72
|
+
- lib/generators/token_master/templates/initializer.rb
|
73
|
+
- lib/token_master.rb
|
74
|
+
- lib/token_master/config.rb
|
75
|
+
- lib/token_master/core.rb
|
76
|
+
- lib/token_master/error.rb
|
77
|
+
- lib/token_master/model.rb
|
78
|
+
- lib/token_master/railtie.rb
|
79
|
+
- lib/token_master/version.rb
|
80
|
+
- token_master.gemspec
|
81
|
+
homepage: https://github.com/launchpadlab/token-master
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.6.6
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Token Master!
|
105
|
+
test_files: []
|