mac_generators 0.2.1 → 0.3.1
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 +5 -5
- data/Rakefile +12 -16
- data/lib/generators/authentication/email/email_generator.rb +62 -63
- data/lib/generators/authentication/email/templates/create_identities.rb +1 -2
- data/lib/generators/authentication/email/templates/database_authentication.rb +2 -0
- data/lib/generators/authentication/email/templates/identities_controller.rb +4 -2
- data/lib/generators/authentication/email/templates/identity.rb +2 -0
- data/lib/generators/authentication/email/templates/sessions_controller.rb +2 -0
- data/lib/generators/authentication/email/templates/warden.rb +3 -1
- data/lib/generators/authentication/omniauth/omniauth_generator.rb +69 -68
- data/lib/generators/authentication/omniauth/templates/authentication_domain.rb +1 -1
- data/lib/generators/authentication/omniauth/templates/create_identities.rb +1 -1
- data/lib/generators/bootstrap/bootstrap_generator.rb +13 -13
- data/lib/mac_generators/version.rb +1 -1
- data/test/dummy/Rakefile +1 -1
- data/test/dummy/app/assets/config/manifest.js +3 -0
- data/test/dummy/app/controllers/application_controller.rb +4 -4
- data/test/dummy/config.ru +1 -1
- data/test/dummy/config/application.rb +3 -4
- data/test/dummy/config/boot.rb +4 -4
- data/test/dummy/config/environment.rb +1 -1
- data/test/dummy/config/environments/development.rb +1 -1
- data/test/dummy/config/environments/production.rb +2 -2
- data/test/dummy/config/environments/test.rb +1 -1
- data/test/dummy/config/initializers/secret_token.rb +1 -1
- data/test/dummy/config/initializers/session_store.rb +1 -1
- data/test/dummy/config/routes.rb +3 -3
- data/test/dummy/log/test.log +2981 -0
- data/test/dummy/script/rails +3 -3
- data/test/dummy/tmp/Gemfile +2 -2
- data/test/dummy/tmp/app/controllers/application_controller.rb +17 -16
- data/test/dummy/tmp/config/initializers/authentication_domain.rb +1 -1
- data/test/dummy/tmp/config/routes.rb +2 -2
- data/test/dummy/tmp/db/migrate/create_identities.rb +1 -1
- data/test/generators/authentication_email_generator_test.rb +64 -66
- data/test/generators/authentication_omniauth_generator_test.rb +46 -46
- data/test/support/generators_test_helper.rb +4 -4
- data/test/test_helper.rb +2 -24
- metadata +39 -54
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/test.sqlite3 +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: baf8524f87d52021b03e6b6f5af70ab0c486f18e1b11839f40d6f5c3200e976f
|
4
|
+
data.tar.gz: 115b302ed421d852463e02b599cd100ecc2b2d4cceebb4d7619171637dea4753
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 895e123dc7242cb28ecec463ca019d67f4a6eac100bd6d8a0a27ab9704ca6366ec9aa5dfb4133a50e7ee84e775a64c341d554f801e15b63d7506baecc9dcd6c0
|
7
|
+
data.tar.gz: 99cfa1f0f0b26b31bc6fe9d3eda78fd320a1fe9331847590e7cef0c74aa7bf76f1b7a13b7d933e47368cdb6eda90cbea3e0161e0588df085650b47156c530c61
|
data/Rakefile
CHANGED
@@ -1,32 +1,28 @@
|
|
1
1
|
begin
|
2
|
-
require
|
2
|
+
require "bundler/setup"
|
3
3
|
rescue LoadError
|
4
|
-
puts
|
4
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
5
5
|
end
|
6
6
|
|
7
|
-
require
|
7
|
+
require "rdoc/task"
|
8
8
|
|
9
9
|
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
-
rdoc.rdoc_dir =
|
11
|
-
rdoc.title
|
12
|
-
rdoc.options <<
|
13
|
-
rdoc.rdoc_files.include(
|
14
|
-
rdoc.rdoc_files.include(
|
10
|
+
rdoc.rdoc_dir = "rdoc"
|
11
|
+
rdoc.title = "MacGenerators"
|
12
|
+
rdoc.options << "--line-numbers"
|
13
|
+
rdoc.rdoc_files.include("README.rdoc")
|
14
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
17
|
Bundler::GemHelper.install_tasks
|
21
18
|
|
22
|
-
require
|
19
|
+
require "rake/testtask"
|
23
20
|
|
24
21
|
Rake::TestTask.new(:test) do |t|
|
25
|
-
t.libs <<
|
26
|
-
t.libs <<
|
27
|
-
t.pattern =
|
22
|
+
t.libs << "lib"
|
23
|
+
t.libs << "test"
|
24
|
+
t.pattern = "test/**/*_test.rb"
|
28
25
|
t.verbose = false
|
29
26
|
end
|
30
27
|
|
31
|
-
|
32
28
|
task default: :test
|
@@ -1,29 +1,29 @@
|
|
1
1
|
module Authentication
|
2
2
|
module Generators
|
3
3
|
class EmailGenerator < Rails::Generators::Base
|
4
|
-
source_root File.expand_path(
|
5
|
-
argument :resource_name, :
|
6
|
-
class_option :haml, type: :boolean, default: false, description:
|
4
|
+
source_root File.expand_path("../templates", __FILE__)
|
5
|
+
argument :resource_name, type: :string, default: "identity"
|
6
|
+
class_option :haml, type: :boolean, default: false, description: "Generate haml templates"
|
7
7
|
|
8
8
|
def copy_controller_files
|
9
|
-
template
|
10
|
-
template
|
9
|
+
template "identities_controller.rb", File.join("app/controllers", "#{resource_pluralize}_controller.rb")
|
10
|
+
template "sessions_controller.rb", "app/controllers/sessions_controller.rb"
|
11
11
|
end
|
12
12
|
|
13
13
|
def copy_view_files
|
14
14
|
if options[:haml]
|
15
|
-
template
|
16
|
-
template
|
15
|
+
template "haml/identity_new.html.haml", "app/views/#{resource_pluralize}/new.html.haml"
|
16
|
+
template "haml/session_new.html.haml", "app/views/sessions/new.html.haml"
|
17
17
|
else
|
18
|
-
template
|
19
|
-
template
|
18
|
+
template "erb/identity_new.html.erb", "app/views/#{resource_pluralize}/new.html.erb"
|
19
|
+
template "erb/session_new.html.erb", "app/views/sessions/new.html.erb"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
def add_routes
|
24
|
-
route "get 'sign_up'
|
25
|
-
route "get 'log_in'
|
26
|
-
route "delete 'log_out'
|
24
|
+
route "get 'sign_up', to: '#{resource_pluralize}#new', as: :sign_up"
|
25
|
+
route "get 'log_in', to: 'sessions#new', as: :log_in"
|
26
|
+
route "delete 'log_out', to: 'sessions#destroy', as: :log_out"
|
27
27
|
|
28
28
|
route "resource :#{resource_name}, only: [:create, :new]"
|
29
29
|
route "resource :sessions, only: [:create, :new]"
|
@@ -31,51 +31,49 @@ module Authentication
|
|
31
31
|
|
32
32
|
def generate_user
|
33
33
|
if Dir["db/migrate/*create_#{resource_pluralize}.rb"].empty?
|
34
|
-
template
|
34
|
+
template "create_identities.rb", "db/migrate/#{migration_name}"
|
35
35
|
end
|
36
|
-
template
|
36
|
+
template "identity.rb", "app/models/#{resource_name}.rb"
|
37
37
|
end
|
38
38
|
|
39
39
|
def add_helper_methods
|
40
|
-
insert_into_file
|
41
|
-
|
40
|
+
insert_into_file "app/controllers/application_controller.rb", after: /::Base/ do
|
41
|
+
<<~EOS
|
42
42
|
|
43
|
+
helper_method :current_#{resource_name}, :#{resource_name}_signed_in?, :warden_message
|
43
44
|
|
44
|
-
|
45
|
+
protected
|
46
|
+
def current_#{resource_name}
|
47
|
+
warden.user(scope: :#{resource_name})
|
48
|
+
end
|
45
49
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
+
def #{resource_name}_signed_in?
|
51
|
+
warden.authenticate?(scope: :#{resource_name})
|
52
|
+
end
|
50
53
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
+
def authenticate!
|
55
|
+
redirect_to root_path, notice: t('.not_logged') unless #{resource_name}_signed_in?
|
56
|
+
end
|
54
57
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
def warden_message
|
60
|
-
warden.message
|
61
|
-
end
|
58
|
+
def warden_message
|
59
|
+
warden.message
|
60
|
+
end
|
62
61
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
62
|
+
def warden
|
63
|
+
request.env['warden']
|
64
|
+
end
|
65
|
+
EOS
|
67
66
|
end
|
68
|
-
|
69
67
|
end
|
70
68
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
69
|
+
def add_gems
|
70
|
+
gem "warden", "~> 1.2.0"
|
71
|
+
gem "bcrypt"
|
72
|
+
end
|
75
73
|
|
76
|
-
|
77
|
-
|
78
|
-
|
74
|
+
def add_translations
|
75
|
+
insert_into_file "config/locales/en.yml", after: "en:" do
|
76
|
+
<<-EOS
|
79
77
|
|
80
78
|
sessions:
|
81
79
|
new:
|
@@ -90,33 +88,34 @@ protected
|
|
90
88
|
create: 'Create #{resource_name}'
|
91
89
|
create:
|
92
90
|
sign_up: 'Welcome to your new account!'
|
93
|
-
|
91
|
+
EOS
|
92
|
+
end
|
94
93
|
end
|
95
|
-
end
|
96
94
|
|
97
|
-
|
98
|
-
|
99
|
-
|
95
|
+
def copy_warden_file
|
96
|
+
template "warden.rb", File.join("config", "initializers", "warden.rb")
|
97
|
+
end
|
100
98
|
|
101
|
-
|
102
|
-
|
103
|
-
|
99
|
+
def copy_warden_strategies
|
100
|
+
template "database_authentication.rb", File.join("lib", "strategies", "database_authentication.rb")
|
101
|
+
end
|
104
102
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
103
|
+
def instructions
|
104
|
+
message = "There are a few manual steps that you need to take care of\n\n"
|
105
|
+
message << "1. Run bundle command to install new gems.\n"
|
106
|
+
message << "2. Be sure that to have definition for root in your routes.\n"
|
107
|
+
message << "3. Run rake db:migrate to add your #{resource_pluralize} table.\n"
|
108
|
+
message << "4. Inspect warden initializer at config/initializers/warden.rb\n"
|
109
|
+
message << " and update the failure_app if need it.\n"
|
110
|
+
message << "5. Inspect generated files and learn how authentication was implemented.\n\n"
|
113
111
|
|
114
|
-
|
115
|
-
|
112
|
+
puts message
|
113
|
+
end
|
114
|
+
|
115
|
+
private
|
116
116
|
|
117
|
-
private
|
118
117
|
def migration_name
|
119
|
-
date = (DateTime.now.strftime "%Y %m %d %H %M %S").
|
118
|
+
date = (DateTime.now.strftime "%Y %m %d %H %M %S").delete(" ")
|
120
119
|
"#{date}_create_#{resource_pluralize}.rb"
|
121
120
|
end
|
122
121
|
|
@@ -1,8 +1,7 @@
|
|
1
|
-
class Create<%= resource_pluralize.capitalize %> < ActiveRecord::Migration
|
1
|
+
class Create<%= resource_pluralize.capitalize %> < ActiveRecord::Migration[6.0]
|
2
2
|
def change
|
3
3
|
create_table :<%= resource_pluralize %> do |t|
|
4
4
|
t.string :email
|
5
|
-
t.string :password_hash
|
6
5
|
t.string :password_digest
|
7
6
|
|
8
7
|
t.timestamps
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class <%= resource_pluralize.capitalize %>Controller < ApplicationController
|
2
4
|
|
3
5
|
def new
|
@@ -15,9 +17,9 @@ class <%= resource_pluralize.capitalize %>Controller < ApplicationController
|
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
18
|
-
private
|
20
|
+
private
|
21
|
+
|
19
22
|
def <%= resource_name %>_params
|
20
23
|
params.require(:<%= resource_name %>).permit :email, :password, :password_confirmation
|
21
24
|
end
|
22
|
-
|
23
25
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative File.join(__FILE__, "..", "..", "..", "lib", "strategies", "database_authentication.rb")
|
2
4
|
Rails.application.config.middleware.use Warden::Manager do |manager|
|
3
5
|
manager.default_strategies :database_authentication
|
4
6
|
|
@@ -1,65 +1,65 @@
|
|
1
1
|
module Authentication
|
2
2
|
module Generators
|
3
3
|
class OmniauthGenerator < Rails::Generators::Base
|
4
|
-
source_root File.expand_path(
|
5
|
-
argument :resource_name, :
|
4
|
+
source_root File.expand_path("../templates", __FILE__)
|
5
|
+
argument :resource_name, type: :string, default: "identity"
|
6
6
|
|
7
7
|
def copy_controller_files
|
8
|
-
template
|
8
|
+
template "sessions_controller.rb", "app/controllers/sessions_controller.rb"
|
9
9
|
end
|
10
10
|
|
11
11
|
def add_routes
|
12
|
-
route "get 'auth/:provider/callback'
|
13
|
-
route "delete '/sessions/destroy'
|
12
|
+
route "get 'auth/:provider/callback', to: 'sessions#create', as: :log_in"
|
13
|
+
route "delete '/sessions/destroy', to: 'sessions#destroy', as: :log_out"
|
14
14
|
end
|
15
15
|
|
16
16
|
def generate_user
|
17
17
|
if Dir["db/migrate/*create_#{resource_pluralize}.rb"].empty?
|
18
|
-
template
|
18
|
+
template "create_identities.rb", "db/migrate/#{migration_name}"
|
19
19
|
end
|
20
|
-
template
|
20
|
+
template "identity.rb", "app/models/#{resource_name}.rb"
|
21
21
|
end
|
22
22
|
|
23
23
|
def add_helper_methods
|
24
|
-
insert_into_file
|
25
|
-
|
24
|
+
insert_into_file "app/controllers/application_controller.rb", after: /:exception/ do
|
25
|
+
<<~EOS
|
26
26
|
|
27
27
|
|
28
|
-
|
28
|
+
helper_method :current_#{resource_name}, :#{resource_name}_signed_in?, :warden_message
|
29
29
|
|
30
|
-
protected
|
31
|
-
def current_#{resource_name}
|
32
|
-
warden.user(scope: :#{resource_name})
|
33
|
-
end
|
30
|
+
protected
|
34
31
|
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
def current_#{resource_name}
|
33
|
+
warden.user(scope: :#{resource_name})
|
34
|
+
end
|
38
35
|
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
def #{resource_name}_signed_in?
|
37
|
+
warden.authenticate?(scope: :#{resource_name})
|
38
|
+
end
|
42
39
|
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
def authenticate!
|
41
|
+
redirect_to root_path, notice: t('.not_logged') unless #{resource_name}_signed_in?
|
42
|
+
end
|
46
43
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
EOS
|
51
|
-
end
|
44
|
+
def warden_message
|
45
|
+
warden.message
|
46
|
+
end
|
52
47
|
|
48
|
+
def warden
|
49
|
+
request.env['warden']
|
50
|
+
end
|
51
|
+
EOS
|
52
|
+
end
|
53
53
|
end
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
def add_gems
|
56
|
+
gem "warden", "~> 1.2.0"
|
57
|
+
gem "omniauth"
|
58
|
+
end
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
def add_translations
|
61
|
+
insert_into_file "config/locales/en.yml", after: "en:" do
|
62
|
+
<<-EOS
|
63
63
|
|
64
64
|
sessions:
|
65
65
|
new:
|
@@ -69,47 +69,48 @@ protected
|
|
69
69
|
logged_in: 'Welcome back!'
|
70
70
|
destroy:
|
71
71
|
logged_out: 'See you later!'
|
72
|
-
|
72
|
+
EOS
|
73
|
+
end
|
73
74
|
end
|
74
|
-
end
|
75
75
|
|
76
|
-
|
77
|
-
|
78
|
-
|
76
|
+
def copy_warden_file
|
77
|
+
template "warden.rb", File.join("config", "initializers", "warden.rb")
|
78
|
+
end
|
79
79
|
|
80
|
-
|
81
|
-
|
82
|
-
|
80
|
+
def copy_configuration
|
81
|
+
template "authentication_domain.rb", File.join("config", "initializers", "authentication_domain.rb")
|
82
|
+
end
|
83
83
|
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
def copy_omniauth_configuration
|
85
|
+
template "omniauth.rb", File.join("config", "initializers", "omniauth.rb")
|
86
|
+
end
|
87
87
|
|
88
|
-
|
89
|
-
|
90
|
-
|
88
|
+
def copy_warden_strategies
|
89
|
+
template "oauth_authentication.rb", File.join("lib", "strategies", "oauth_authentication.rb")
|
90
|
+
end
|
91
91
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
92
|
+
def instructions
|
93
|
+
message = "There are a few manual steps that you need to take care of\n\n"
|
94
|
+
message << "1. Add an omniauth provider gem like twitter, facebook, etc..\n"
|
95
|
+
message << "2. Modify config/initializers/omniauth.rb and setup your provider\n"
|
96
|
+
message << " and your provider credentials.\n"
|
97
|
+
message << "3. Run bundle command to install new gems.\n"
|
98
|
+
message << "4. If you want to restrict access to a specific email domain.\n"
|
99
|
+
message << " modify config/initializers/authentication_domain.rb and add \n"
|
100
|
+
message << " your allowed domain.\n"
|
101
|
+
message << "5. Inspect warden initializer at config/initializers/warden.rb\n"
|
102
|
+
message << " and update the failure_app.\n"
|
103
|
+
message << "6. Be sure that to have definition for root in your routes.\n"
|
104
|
+
message << "7. Run rake db:migrate to add your #{resource_pluralize} table.\n"
|
105
|
+
message << "8. Inspect generated files and learn how authentication was implemented.\n\n"
|
106
|
+
|
107
|
+
puts message
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
109
111
|
|
110
|
-
private
|
111
112
|
def migration_name
|
112
|
-
date = (DateTime.now.strftime "%Y %m %d %H %M %S").
|
113
|
+
date = (DateTime.now.strftime "%Y %m %d %H %M %S").delete(" ")
|
113
114
|
"#{date}_create_#{resource_pluralize}.rb"
|
114
115
|
end
|
115
116
|
|