token_authenticate_me 0.4.3 → 0.5.0
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.
- checksums.yaml +4 -4
- data/{LICENSE → MIT-LICENSE} +1 -1
- data/Rakefile +27 -11
- data/app/controllers/token_authenticate_me/api/v1/base_controller.rb +9 -0
- data/app/controllers/token_authenticate_me/api/v1/invites_controller.rb +14 -0
- data/app/controllers/token_authenticate_me/api/v1/password_resets_controller.rb +11 -0
- data/app/controllers/token_authenticate_me/api/v1/sessions_controller.rb +11 -0
- data/app/controllers/token_authenticate_me/api/v1/users_controller.rb +17 -0
- data/app/controllers/token_authenticate_me/application_controller.rb +5 -0
- data/app/helpers/token_authenticate_me/application_helper.rb +4 -0
- data/app/mailers/token_authenticate_me_mailer.rb +16 -9
- data/app/models/token_authenticate_me/invite.rb +11 -0
- data/app/models/token_authenticate_me/session.rb +8 -0
- data/app/models/token_authenticate_me/user.rb +11 -0
- data/app/views/token_authenticate_me_mailer/invite_user_email.html.erb +0 -0
- data/config/routes.rb +23 -0
- data/db/migrate/20160620184327_create_token_authenticate_me_invites.rb +14 -0
- data/db/migrate/20160621211347_create_token_authenticate_me_users.rb +18 -0
- data/db/migrate/20160622203801_create_token_authenticate_me_sessions.rb +14 -0
- data/lib/generators/token_authenticate_me/controllers/controllers_generator.rb +1 -76
- data/lib/generators/token_authenticate_me/install/install_generator.rb +9 -3
- data/lib/generators/token_authenticate_me/models/models_generator.rb +1 -59
- data/lib/generators/token_authenticate_me/policies/policies_generator.rb +15 -0
- data/lib/generators/token_authenticate_me/policies/templates/invite_policy.rb +31 -0
- data/lib/generators/token_authenticate_me/policies/templates/user_policy.rb +23 -0
- data/lib/tasks/token_authenticate_me_tasks.rake +4 -0
- data/lib/token_authenticate_me.rb +11 -0
- data/lib/token_authenticate_me/concerns/controllers/invitable.rb +58 -0
- data/lib/token_authenticate_me/concerns/controllers/password_resetable.rb +97 -0
- data/lib/token_authenticate_me/concerns/controllers/sessionable.rb +55 -0
- data/lib/token_authenticate_me/concerns/controllers/token_authenticateable.rb +45 -0
- data/lib/token_authenticate_me/concerns/models/authenticatable.rb +102 -0
- data/lib/token_authenticate_me/concerns/models/invitable.rb +20 -0
- data/lib/token_authenticate_me/concerns/models/sessionable.rb +44 -0
- data/lib/token_authenticate_me/configuration.rb +16 -0
- data/lib/token_authenticate_me/engine.rb +2 -2
- data/lib/token_authenticate_me/models.rb +4 -0
- data/lib/token_authenticate_me/version.rb +1 -1
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/{spec/internal → test/dummy}/app/controllers/application_controller.rb +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +25 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +3 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/log/test.log +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/fixtures/token_authenticate_me/invites.yml +11 -0
- data/test/fixtures/token_authenticate_me/sessions.yml +11 -0
- data/test/fixtures/token_authenticate_me/users.yml +11 -0
- data/test/integration/navigation_test.rb +7 -0
- data/test/models/token_authenticate_me/invite_test.rb +9 -0
- data/test/models/token_authenticate_me/session_test.rb +9 -0
- data/test/models/token_authenticate_me/user_test.rb +9 -0
- data/test/test_helper.rb +21 -0
- data/test/token_authenticate_me_test.rb +7 -0
- metadata +129 -160
- data/.editorconfig +0 -41
- data/.gitignore +0 -4
- data/.rubocop.yml +0 -8
- data/CHANGELOG.md +0 -2
- data/Gemfile +0 -7
- data/config.ru +0 -7
- data/lib/generators/token_authenticate_me/controllers/templates/password_reset.rb +0 -6
- data/lib/generators/token_authenticate_me/controllers/templates/sessions.rb +0 -6
- data/lib/generators/token_authenticate_me/controllers/templates/users.rb +0 -8
- data/lib/generators/token_authenticate_me/models/templates/authentication_migration.rb +0 -20
- data/lib/generators/token_authenticate_me/models/templates/authentication_model.rb +0 -11
- data/lib/generators/token_authenticate_me/models/templates/session_migration.rb +0 -17
- data/lib/generators/token_authenticate_me/models/templates/session_model.rb +0 -12
- data/lib/token_authenticate_me/controllers/password_resetable.rb +0 -95
- data/lib/token_authenticate_me/controllers/sessionable.rb +0 -53
- data/lib/token_authenticate_me/controllers/token_authenticateable.rb +0 -52
- data/lib/token_authenticate_me/models/authenticatable.rb +0 -93
- data/lib/token_authenticate_me/models/sessionable.rb +0 -36
- data/spec/acceptance/password_reset_api_spec.rb +0 -111
- data/spec/acceptance/session_api_spec.rb +0 -95
- data/spec/acceptance/users_api_spec.rb +0 -70
- data/spec/internal/app/controllers/password_resets_controller.rb +0 -5
- data/spec/internal/app/controllers/sessions_controller.rb +0 -5
- data/spec/internal/app/controllers/users_controller.rb +0 -7
- data/spec/internal/app/models/session.rb +0 -11
- data/spec/internal/app/models/user.rb +0 -11
- data/spec/internal/app/policies/user_policy.rb +0 -29
- data/spec/internal/app/serializers/user_serializer.rb +0 -3
- data/spec/internal/config/database.yml +0 -3
- data/spec/internal/config/routes.rb +0 -13
- data/spec/internal/db/fixtures/users.rb +0 -11
- data/spec/internal/db/schema.rb +0 -19
- data/spec/spec_helper.rb +0 -38
- data/token_authenticate_me.gemspec +0 -32
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1087edb3550d6663aca459479247a58c0514d2e9
|
|
4
|
+
data.tar.gz: 9d69f52a17b61cc10402402abf176f4a32b06687
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c829821e5da0cf0fc69ce6c590a02faacee62a348bdf1ecdc56ad31c4f4bd7579bb7f3aafbab5b77c6d64d2bfbba761f7059dc07a2c843a4ab81efae0d9de09c
|
|
7
|
+
data.tar.gz: 9b3232882436db6f0c1eba180baa8fd025305466fce0a8406d7d35aaea462cadcc57a0c416d73a9f65d24554f4fcd85bdf978e3dc5b8ac636be1676f930eb4e4
|
data/{LICENSE → MIT-LICENSE}
RENAMED
data/Rakefile
CHANGED
|
@@ -1,17 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
begin
|
|
2
|
+
require 'bundler/setup'
|
|
3
|
+
rescue LoadError
|
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
5
|
+
end
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
require 'rdoc/task'
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
11
|
+
rdoc.title = 'TokenAuthenticateMe'
|
|
12
|
+
rdoc.options << '--line-numbers'
|
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
11
15
|
end
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
|
|
18
|
+
load 'rails/tasks/engine.rake'
|
|
14
19
|
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
load 'rails/tasks/statistics.rake'
|
|
21
|
+
|
|
22
|
+
Bundler::GemHelper.install_tasks
|
|
23
|
+
|
|
24
|
+
require 'rake/testtask'
|
|
25
|
+
|
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
|
27
|
+
t.libs << 'lib'
|
|
28
|
+
t.libs << 'test'
|
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
|
30
|
+
t.verbose = false
|
|
17
31
|
end
|
|
32
|
+
|
|
33
|
+
task default: :test
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'token_authenticate_me/concerns/controllers/invitable'
|
|
2
|
+
|
|
3
|
+
module TokenAuthenticateMe
|
|
4
|
+
module Api
|
|
5
|
+
module V1
|
|
6
|
+
class InvitesController < BaseController
|
|
7
|
+
include TokenAuthenticateMe::Concerns::Controllers::Invitable
|
|
8
|
+
|
|
9
|
+
model TokenAuthenticateMe::Invite
|
|
10
|
+
serializer TokenAuthenticateMe::InviteSerializer
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'token_authenticate_me/concerns/controllers/password_resetable'
|
|
2
|
+
|
|
3
|
+
module TokenAuthenticateMe
|
|
4
|
+
module Api
|
|
5
|
+
module V1
|
|
6
|
+
class PasswordResetsController < BaseController
|
|
7
|
+
include TokenAuthenticateMe::Concerns::Controllers::PasswordResetable
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'token_authenticate_me/concerns/controllers/token_authenticateable'
|
|
2
|
+
|
|
3
|
+
module TokenAuthenticateMe
|
|
4
|
+
module Api
|
|
5
|
+
module V1
|
|
6
|
+
class UsersController < BaseController
|
|
7
|
+
include ApiMe
|
|
8
|
+
include TokenAuthenticateMe::Concerns::Controllers::TokenAuthenticateable
|
|
9
|
+
|
|
10
|
+
skip_before_action :authenticate, only: [:create]
|
|
11
|
+
|
|
12
|
+
model TokenAuthenticateMe::User
|
|
13
|
+
serializer TokenAuthenticateMe::UserSerializer
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
class TokenAuthenticateMeMailer < ActionMailer::Base
|
|
2
|
-
SIGNUP_PATH = '/sign-up'
|
|
3
|
-
RESET_PATH = '/reset-password/:token/'
|
|
4
|
-
|
|
5
2
|
def valid_user_reset_password_email(root_url, user)
|
|
6
3
|
@root_url = root_url
|
|
7
4
|
@user = user
|
|
8
|
-
@
|
|
9
|
-
|
|
10
|
-
@token_reset_path = token_reset_path
|
|
5
|
+
@token_reset_path = token_reset_path(@user)
|
|
11
6
|
|
|
12
7
|
mail(to: user.email, subject: 'Password Reset')
|
|
13
8
|
end
|
|
@@ -15,14 +10,26 @@ class TokenAuthenticateMeMailer < ActionMailer::Base
|
|
|
15
10
|
def invalid_user_reset_password_email(root_url, email)
|
|
16
11
|
@root_url = root_url
|
|
17
12
|
@email = email
|
|
18
|
-
@signup_path =
|
|
13
|
+
@signup_path = TokenAuthenticateMe.configuration.signup_path
|
|
19
14
|
|
|
20
15
|
mail(to: email, subject: 'Password Reset Error')
|
|
21
16
|
end
|
|
22
17
|
|
|
18
|
+
def invite_user_email(root_url, invite)
|
|
19
|
+
@root_url = root_url
|
|
20
|
+
@email = invite.email
|
|
21
|
+
@invite_path = invite_path(invite)
|
|
22
|
+
|
|
23
|
+
mail(to: email, subject: 'Invitation To Join')
|
|
24
|
+
end
|
|
25
|
+
|
|
23
26
|
private
|
|
24
27
|
|
|
25
|
-
def token_reset_path
|
|
26
|
-
|
|
28
|
+
def token_reset_path(user)
|
|
29
|
+
TokenAuthenticateMe.reset_path.sub(/:token/, user.reset_password_token)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def invite_path(invite)
|
|
33
|
+
TokenAuthenticateMe.configuration.invite_path.sub(/:id/, invite.to_s)
|
|
27
34
|
end
|
|
28
35
|
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'token_authenticate_me/concerns/models/invitable'
|
|
2
|
+
|
|
3
|
+
module TokenAuthenticateMe
|
|
4
|
+
class Invite < ActiveRecord::Base
|
|
5
|
+
include TokenAuthenticateMe::Concerns::Models::Invitable
|
|
6
|
+
|
|
7
|
+
def accept!(current_user)
|
|
8
|
+
# no-op, override for app specific accept logic
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'token_authenticate_me/concerns/models/authenticatable'
|
|
2
|
+
|
|
3
|
+
module TokenAuthenticateMe
|
|
4
|
+
class User < ActiveRecord::Base
|
|
5
|
+
include TokenAuthenticateMe::Concerns::Models::Authenticatable
|
|
6
|
+
|
|
7
|
+
def self.policy_class
|
|
8
|
+
TokenAuthenticateMe::UserPolicy
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
File without changes
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
TokenAuthenticateMe::Engine.routes.draw do
|
|
2
|
+
namespace :api do
|
|
3
|
+
namespace :v1 do
|
|
4
|
+
resource :session, only: [:create, :show, :destroy]
|
|
5
|
+
resource :users
|
|
6
|
+
|
|
7
|
+
resources :invites, except: [:update] do
|
|
8
|
+
member do
|
|
9
|
+
get 'accept'
|
|
10
|
+
get 'decline'
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
resources(
|
|
15
|
+
:password_resets,
|
|
16
|
+
only: [:create, :update],
|
|
17
|
+
constraints: {
|
|
18
|
+
id: TokenAuthenticateMe::UUID_REGEX
|
|
19
|
+
}
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
class CreateTokenAuthenticateMeInvites < ActiveRecord::Migration
|
|
2
|
+
def change
|
|
3
|
+
enable_extension 'uuid-ossp'
|
|
4
|
+
|
|
5
|
+
create_table(:token_authenticate_me_invites, id: :uuid) do |t|
|
|
6
|
+
t.string :email, null: false
|
|
7
|
+
t.boolean :accepted, default: nil
|
|
8
|
+
t.jsonb :meta, null: false, default: '{}'
|
|
9
|
+
t.integer :creator_id, index: true
|
|
10
|
+
|
|
11
|
+
t.timestamps null: false
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class CreateTokenAuthenticateMeUsers < ActiveRecord::Migration
|
|
2
|
+
def change
|
|
3
|
+
create_table :token_authenticate_me_users do |t|
|
|
4
|
+
t.string :username, null: false
|
|
5
|
+
t.string :email, null: false
|
|
6
|
+
t.string :password_digest, null: false
|
|
7
|
+
t.string :reset_password_token
|
|
8
|
+
t.datetime :reset_password_token_exp
|
|
9
|
+
|
|
10
|
+
t.timestamps null: false
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
add_index :token_authenticate_me_users, :email, unique: true
|
|
14
|
+
add_index :token_authenticate_me_users, :username, unique: true
|
|
15
|
+
add_index :token_authenticate_me_users, :reset_password_token, unique: true
|
|
16
|
+
add_foreign_key :token_authenticate_me_invites, :token_authenticate_me_users, column: :creator_id
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
class CreateTokenAuthenticateMeSessions < ActiveRecord::Migration
|
|
2
|
+
def change
|
|
3
|
+
create_table :token_authenticate_me_sessions do |t|
|
|
4
|
+
t.string :key, null: false
|
|
5
|
+
t.datetime :expiration
|
|
6
|
+
t.integer :user_id
|
|
7
|
+
|
|
8
|
+
t.timestamps null: false
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
add_index :token_authenticate_me_sessions, :key, unique: true
|
|
12
|
+
add_foreign_key :token_authenticate_me_sessions, :token_authenticate_me_users, column: :user_id
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -1,82 +1,7 @@
|
|
|
1
|
-
# TODO: Update so path (/api) isn't fixed
|
|
2
1
|
module TokenAuthenticateMe
|
|
3
2
|
module Generators
|
|
4
|
-
class ControllersGenerator < ::Rails::Generators::
|
|
3
|
+
class ControllersGenerator < ::Rails::Generators::Base
|
|
5
4
|
source_root File.expand_path('../templates', __FILE__)
|
|
6
|
-
check_class_collision suffix: 'Controller'
|
|
7
|
-
|
|
8
|
-
def create_sessions_controller
|
|
9
|
-
template 'sessions.rb', 'app/controllers/api/sessions_controller.rb'
|
|
10
|
-
|
|
11
|
-
# Inject /api/sesssion route into routes file
|
|
12
|
-
insert_after_api(" resource :session, only: [:create, :show, :destroy]\n")
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def create_password_reset_controller # rubocop:disable Metrics/MethodLength
|
|
16
|
-
template 'password_reset.rb', 'app/controllers/api/password_resets_controller.rb'
|
|
17
|
-
insert_after_api(<<-ROUTE
|
|
18
|
-
resources(
|
|
19
|
-
:password_resets,
|
|
20
|
-
only: [:create, :update],
|
|
21
|
-
constraints: {
|
|
22
|
-
id: TokenAuthenticateMe::UUID_REGEX
|
|
23
|
-
}
|
|
24
|
-
)
|
|
25
|
-
ROUTE
|
|
26
|
-
)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def create_users_controller
|
|
30
|
-
template 'users.rb', 'app/controllers/api/v1/users_controller.rb'
|
|
31
|
-
insert_after_version(" resources :users\n")
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
private
|
|
35
|
-
|
|
36
|
-
def insert_after_api(string)
|
|
37
|
-
maybe_create_api_v1_namespace
|
|
38
|
-
|
|
39
|
-
in_root do
|
|
40
|
-
insert_into_file(
|
|
41
|
-
'config/routes.rb',
|
|
42
|
-
string,
|
|
43
|
-
after: "namespace :api do\n"
|
|
44
|
-
)
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def insert_after_version(string)
|
|
49
|
-
maybe_create_api_v1_namespace
|
|
50
|
-
|
|
51
|
-
in_root do
|
|
52
|
-
insert_into_file(
|
|
53
|
-
'config/routes.rb',
|
|
54
|
-
string,
|
|
55
|
-
after: "namespace :v1 do\n"
|
|
56
|
-
)
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def maybe_create_api_v1_namespace
|
|
61
|
-
in_root do
|
|
62
|
-
unless File.readlines('config/routes.rb').grep('namespace :api do')
|
|
63
|
-
route <<-ROUTE
|
|
64
|
-
namespace :api do
|
|
65
|
-
namespace :v1 do
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
ROUTE
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def inject_before_actions_into_users_controllers
|
|
74
|
-
inject_into_class(
|
|
75
|
-
Rails.root.join('app', 'controllers', 'api', 'v1', 'users_controller.rb'),
|
|
76
|
-
UsersController,
|
|
77
|
-
" skip_before_action :authenticate, only: [:create]\n"
|
|
78
|
-
)
|
|
79
|
-
end
|
|
80
5
|
end
|
|
81
6
|
end
|
|
82
7
|
end
|
|
@@ -2,10 +2,16 @@ module TokenAuthenticateMe
|
|
|
2
2
|
module Generators
|
|
3
3
|
class InstallGenerator < Rails::Generators::Base
|
|
4
4
|
def run_generators
|
|
5
|
-
|
|
5
|
+
rake 'token_authenticate_me:install:migrations'
|
|
6
|
+
generate 'token_authenticate_me:models'
|
|
7
|
+
generate 'token_authenticate_me:controllers'
|
|
8
|
+
generate 'token_authenticate_me:policies'
|
|
9
|
+
generate 'serializer token_authenticate_me/user username email created_at updated_at'
|
|
10
|
+
generate 'serializer token_authenticate_me/invite email accepted meta creator:has_one created_at updated_at'
|
|
11
|
+
end
|
|
6
12
|
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
def mount_engine_routes
|
|
14
|
+
route 'mount TokenAuthenticateMe::Engine => TokenAuthenticateMe.configuration.mount_path'
|
|
9
15
|
end
|
|
10
16
|
end
|
|
11
17
|
end
|
|
@@ -1,67 +1,9 @@
|
|
|
1
1
|
module TokenAuthenticateMe
|
|
2
2
|
module Generators
|
|
3
|
-
class ModelsGenerator < ::Rails::Generators::
|
|
3
|
+
class ModelsGenerator < ::Rails::Generators::Base
|
|
4
4
|
include Rails::Generators::Migration
|
|
5
5
|
|
|
6
6
|
source_root File.expand_path('../templates', __FILE__)
|
|
7
|
-
check_class_collision suffix: ''
|
|
8
|
-
|
|
9
|
-
def self.next_migration_number(dirname)
|
|
10
|
-
next_migration_number = current_migration_number(dirname) + 1
|
|
11
|
-
ActiveRecord::Migration.next_migration_number(next_migration_number)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def create_authentication_model_file
|
|
15
|
-
template 'authentication_model.rb', File.join('app/models', 'user.rb')
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def create_authentication_migration_file
|
|
19
|
-
# When the switch is made to allow resource names to be specified, could use something like:
|
|
20
|
-
# migration_file_name = "#{next_migration_number}_#{plural_name}.rb"
|
|
21
|
-
# migration_template(
|
|
22
|
-
# 'authentication_migration.rb',
|
|
23
|
-
# File.join('db/migrations', migration_file_name)
|
|
24
|
-
# )
|
|
25
|
-
migration_template(
|
|
26
|
-
'authentication_migration.rb',
|
|
27
|
-
File.join('db/migrate', 'create_users.rb')
|
|
28
|
-
)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def create_session_model_file
|
|
32
|
-
template 'session_model.rb', File.join('app/models', 'session.rb')
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def create_session_migration_file
|
|
36
|
-
# When the switch is made to allow resource names to be specified, could use something like:
|
|
37
|
-
# migration_file_name = "#{next_migration_number}_#{singular_name}_sessions.rb"
|
|
38
|
-
# migration_template(
|
|
39
|
-
# 'authentication_migration.rb',
|
|
40
|
-
# File.join('db/migrations', migration_file_name)
|
|
41
|
-
# )
|
|
42
|
-
migration_template(
|
|
43
|
-
'session_migration.rb',
|
|
44
|
-
File.join('db/migrate', 'create_sessions.rb')
|
|
45
|
-
)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
private
|
|
49
|
-
|
|
50
|
-
def authenticate_model_singular_name
|
|
51
|
-
'user' # singular_name
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def session_model_plural_name
|
|
55
|
-
'sessions' # "#{singular_name}_sessions"
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def session_model_singular_name
|
|
59
|
-
'session' # "#{singular_name}_session"
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def next_migration_number
|
|
63
|
-
self.class.next_migration_number('db/migrations')
|
|
64
|
-
end
|
|
65
7
|
end
|
|
66
8
|
end
|
|
67
9
|
end
|