orthodox 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/authentication/authentication_generator.rb +86 -86
- data/lib/orthodox/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb884d4b62c5307e6c2ac517eb1dc6ebc7c2601ef9c15b3c3f81306f3d15920e
|
4
|
+
data.tar.gz: a8b07923a477e78af67e1dbd28e136d9cafe7f035926c701b451da5b429f9808
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 184a9b18ccad9deb40190f4584c12df441a43348ed0571a4f561611947534bfb27754148c1de3bd551f90d42cf8528c514b5c5403c50de22d314c0a0c61b6c6b
|
7
|
+
data.tar.gz: a9bee7c8a03ac3f4f290ddc13c0a181572ace2990db3db6b7747068c04895072eb272de26dc8359416f60fb9a81c8b69a86086e15a3acd2c8cd1b371ceba2447
|
@@ -1,41 +1,41 @@
|
|
1
1
|
class AuthenticationGenerator < Rails::Generators::NamedBase
|
2
2
|
source_root File.expand_path('templates', __dir__)
|
3
|
-
|
3
|
+
|
4
4
|
desc "Creates authentication views, controllers and models for a given Model"
|
5
|
-
|
5
|
+
|
6
6
|
class_option :skip_views, type: :boolean, default: false
|
7
7
|
|
8
8
|
class_option :skip_tests, type: :boolean, default: false
|
9
|
-
|
9
|
+
|
10
10
|
class_option :two_factor, type: :boolean, default: false
|
11
|
-
|
11
|
+
|
12
12
|
class_option :js, type: :boolean, default: false
|
13
|
-
|
14
|
-
|
13
|
+
|
14
|
+
|
15
15
|
def create_controllers
|
16
|
-
generate "base_controller",
|
17
|
-
template "controllers/sessions_controller.rb.erb",
|
16
|
+
generate "base_controller", plural_name
|
17
|
+
template "controllers/sessions_controller.rb.erb",
|
18
18
|
"app/controllers/#{plural_file_name}/sessions_controller.rb"
|
19
|
-
template "controllers/password_resets_controller.rb.erb",
|
19
|
+
template "controllers/password_resets_controller.rb.erb",
|
20
20
|
"app/controllers/#{plural_file_name}/password_resets_controller.rb"
|
21
21
|
|
22
|
-
if options[:two_factor]
|
23
|
-
template "controllers/tfa_sessions_controller.rb.erb",
|
22
|
+
if options[:two_factor]
|
23
|
+
template "controllers/tfa_sessions_controller.rb.erb",
|
24
24
|
"app/controllers/#{plural_file_name}/tfa_sessions_controller.rb"
|
25
|
-
|
26
|
-
template "controllers/tfas_controller.rb.erb",
|
25
|
+
|
26
|
+
template "controllers/tfas_controller.rb.erb",
|
27
27
|
"app/controllers/#{plural_file_name}/tfas_controller.rb"
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
def extend_controllers
|
32
|
-
inject_into_class "app/controllers/#{plural_name}/base_controller.rb",
|
33
|
-
"#{plural_class_name}::BaseController",
|
32
|
+
inject_into_class "app/controllers/#{plural_name}/base_controller.rb",
|
33
|
+
"#{plural_class_name}::BaseController",
|
34
34
|
" authenticate_model :#{singular_name}, tfa: #{options[:two_factor]}\n"
|
35
35
|
include_module_in_controller("#{plural_name}/base_controller", "Authentication")
|
36
|
-
|
36
|
+
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def ensure_helpers
|
40
40
|
if options[:two_factor]
|
41
41
|
copy_file "helpers/otp_credentials_helper.rb", "app/helpers/otp_credentials_helper.rb"
|
@@ -47,7 +47,7 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
|
|
47
47
|
copy_file "javascript/tfa_forms.js", "app/javascript/packs/tfa_forms.js"
|
48
48
|
end
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
def create_mailer
|
52
52
|
generate "mailer", "#{class_name}Mailer"
|
53
53
|
inject_into_class "app/mailers/#{singular_name}_mailer.rb", "#{class_name}Mailer", <<~RUBY
|
@@ -56,47 +56,47 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
|
|
56
56
|
@#{singular_name} = #{singular_name}
|
57
57
|
mail(to: #{singular_name}.email, subject: "Reset your password")
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
RUBY
|
61
61
|
template "views/mailers/password_reset_link.html.slim.erb",
|
62
62
|
"app/views/#{singular_name}_mailer/password_reset_link.html.slim"
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
def create_models
|
66
66
|
copy_file "models/password_reset_token.rb", "app/models/password_reset_token.rb"
|
67
67
|
if options[:two_factor]
|
68
68
|
template "models/otp_credential.rb.erb", "app/models/otp_credential.rb"
|
69
|
-
end
|
69
|
+
end
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
def extend_models
|
73
73
|
include_module_in_model(class_name, "Authenticateable")
|
74
|
-
include_module_in_model(class_name, "PasswordResetable")
|
74
|
+
include_module_in_model(class_name, "PasswordResetable")
|
75
75
|
if options[:two_factor]
|
76
76
|
include_module_in_model(class_name, "Otpable")
|
77
77
|
end
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
def create_form_objects
|
81
|
-
template "models/session.rb.erb", "app/models/#{singular_name}_session.rb"
|
81
|
+
template "models/session.rb.erb", "app/models/#{singular_name}_session.rb"
|
82
82
|
if options[:two_factor]
|
83
83
|
copy_file "models/tfa_session.rb", "app/models/tfa_session.rb"
|
84
|
-
end
|
84
|
+
end
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
def ensure_concerns
|
88
|
-
template "controllers/concerns/authentication.rb.erb",
|
88
|
+
template "controllers/concerns/authentication.rb.erb",
|
89
89
|
"app/controllers/concerns/authentication.rb"
|
90
|
-
copy_file "models/concerns/authenticateable.rb",
|
91
|
-
"app/models/concerns/authenticateable.rb"
|
92
|
-
copy_file "models/concerns/password_resetable.rb",
|
93
|
-
"app/models/concerns/password_resetable.rb"
|
90
|
+
copy_file "models/concerns/authenticateable.rb",
|
91
|
+
"app/models/concerns/authenticateable.rb"
|
92
|
+
copy_file "models/concerns/password_resetable.rb",
|
93
|
+
"app/models/concerns/password_resetable.rb"
|
94
94
|
|
95
95
|
if options[:two_factor]
|
96
|
-
copy_file "controllers/concerns/two_factor_authentication.rb",
|
97
|
-
"app/controllers/concerns/two_factor_authentication.rb"
|
98
|
-
|
99
|
-
copy_file "models/concerns/otpable.rb", "app/models/concerns/otpable.rb"
|
96
|
+
copy_file "controllers/concerns/two_factor_authentication.rb",
|
97
|
+
"app/controllers/concerns/two_factor_authentication.rb"
|
98
|
+
|
99
|
+
copy_file "models/concerns/otpable.rb", "app/models/concerns/otpable.rb"
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
@@ -111,64 +111,64 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
|
|
111
111
|
secret:string{32} \
|
112
112
|
authable:references{polymorphic} \
|
113
113
|
recovery_codes:json"
|
114
|
-
end
|
114
|
+
end
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
def create_view_templates
|
118
118
|
return if options[:skip_views]
|
119
|
-
template "views/sessions/new.html.slim.erb",
|
120
|
-
"app/views/#{plural_name}/sessions/new.html.slim"
|
119
|
+
template "views/sessions/new.html.slim.erb",
|
120
|
+
"app/views/#{plural_name}/sessions/new.html.slim"
|
121
|
+
|
122
|
+
template "views/password_resets/new.html.slim.erb",
|
123
|
+
"app/views/#{plural_name}/password_resets/new.html.slim"
|
121
124
|
|
122
|
-
template "views/password_resets/
|
123
|
-
"app/views/#{plural_name}/password_resets/
|
125
|
+
template "views/password_resets/edit.html.slim.erb",
|
126
|
+
"app/views/#{plural_name}/password_resets/edit.html.slim"
|
124
127
|
|
125
|
-
template "views/password_resets/edit.html.slim.erb",
|
126
|
-
"app/views/#{plural_name}/password_resets/edit.html.slim"
|
127
|
-
|
128
128
|
if options[:two_factor]
|
129
|
-
template "views/tfa_sessions/new.html.slim.erb",
|
130
|
-
"app/views/#{plural_name}/tfa_sessions/new.html.slim"
|
131
|
-
template "views/tfas/show.html.slim.erb",
|
132
|
-
"app/views/#{plural_name}/tfas/show.html.slim"
|
133
|
-
|
129
|
+
template "views/tfa_sessions/new.html.slim.erb",
|
130
|
+
"app/views/#{plural_name}/tfa_sessions/new.html.slim"
|
131
|
+
template "views/tfas/show.html.slim.erb",
|
132
|
+
"app/views/#{plural_name}/tfas/show.html.slim"
|
133
|
+
|
134
134
|
end
|
135
135
|
end
|
136
|
-
|
136
|
+
|
137
137
|
def create_specs
|
138
138
|
return if options[:skip_tests]
|
139
|
-
|
139
|
+
|
140
140
|
copy_file "spec/support/factory_bot.rb", "spec/support/factory_bot.rb"
|
141
|
-
|
142
|
-
template "spec/system/authentication_spec.rb.erb",
|
143
|
-
"spec/system/#{plural_name}/authentication_spec.rb"
|
144
|
-
|
145
|
-
template "spec/system/password_resets_spec.rb.erb",
|
146
|
-
"spec/system/#{plural_name}/password_resets_spec.rb"
|
147
|
-
|
148
|
-
template "spec/models/session_spec.rb.erb",
|
149
|
-
"spec/models/#{singular_name}_session_spec.rb"
|
150
|
-
|
151
|
-
copy_file "spec/models/password_reset_token_spec.rb",
|
141
|
+
|
142
|
+
template "spec/system/authentication_spec.rb.erb",
|
143
|
+
"spec/system/#{plural_name}/authentication_spec.rb"
|
144
|
+
|
145
|
+
template "spec/system/password_resets_spec.rb.erb",
|
146
|
+
"spec/system/#{plural_name}/password_resets_spec.rb"
|
147
|
+
|
148
|
+
template "spec/models/session_spec.rb.erb",
|
149
|
+
"spec/models/#{singular_name}_session_spec.rb"
|
150
|
+
|
151
|
+
copy_file "spec/models/password_reset_token_spec.rb",
|
152
152
|
"spec/models/password_reset_token_spec.rb"
|
153
|
-
|
153
|
+
|
154
154
|
if options[:two_factor]
|
155
|
-
copy_file "spec/support/authentication_helpers.rb",
|
155
|
+
copy_file "spec/support/authentication_helpers.rb",
|
156
156
|
"spec/support/authentication_helpers.rb"
|
157
157
|
template "spec/models/tfa_session_spec.rb.erb", "spec/models/tfa_session_spec.rb"
|
158
|
-
copy_file "spec/models/otp_credential_spec.rb",
|
159
|
-
"spec/models/otp_credential_spec.rb"
|
160
|
-
template "spec/system/tfa_authentication_spec.rb.erb",
|
161
|
-
"spec/system/#{plural_name}/tfa_authentication_spec.rb"
|
162
|
-
|
158
|
+
copy_file "spec/models/otp_credential_spec.rb",
|
159
|
+
"spec/models/otp_credential_spec.rb"
|
160
|
+
template "spec/system/tfa_authentication_spec.rb.erb",
|
161
|
+
"spec/system/#{plural_name}/tfa_authentication_spec.rb"
|
162
|
+
|
163
163
|
end
|
164
164
|
end
|
165
|
-
|
165
|
+
|
166
166
|
def create_factories
|
167
167
|
generate "factory_bot:model", "otp_credential"
|
168
168
|
generate "factory_bot:model", "password_reset_token"
|
169
|
-
generate "factory_bot:model", "#{singular_name}_session email:email password:password"
|
169
|
+
generate "factory_bot:model", "#{singular_name}_session email:email password:password"
|
170
170
|
end
|
171
|
-
|
171
|
+
|
172
172
|
def ensure_gems
|
173
173
|
gem "validates_email_format_of", version: "~> 1.6"
|
174
174
|
gem "slim-rails"
|
@@ -179,39 +179,39 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
|
|
179
179
|
gem "rqrcode", require: false
|
180
180
|
end
|
181
181
|
end
|
182
|
-
|
182
|
+
|
183
183
|
def create_routes
|
184
184
|
route <<~RUBY
|
185
185
|
namespace :#{plural_name} do
|
186
|
-
|
186
|
+
|
187
187
|
resource :session, only: [:new, :create, :destroy]
|
188
|
-
|
188
|
+
|
189
189
|
#{"resource :tfa_session, only: [:new, :create]" if options[:two_factor]}
|
190
|
-
|
190
|
+
|
191
191
|
resource :tfa, only: [:create, :show, :destroy]
|
192
|
-
|
192
|
+
|
193
193
|
resources :password_resets, only: [:new, :create, :edit, :update], param: :token
|
194
|
-
|
194
|
+
|
195
195
|
end
|
196
196
|
RUBY
|
197
197
|
end
|
198
|
-
|
198
|
+
|
199
199
|
private
|
200
|
-
|
200
|
+
|
201
201
|
def plural_class_name
|
202
202
|
class_name.pluralize
|
203
203
|
end
|
204
204
|
|
205
205
|
def include_module_in_controller(controller_name, module_name)
|
206
206
|
class_name = controller_name.classify
|
207
|
-
inject_into_class "app/controllers/#{controller_name}.rb", class_name,
|
207
|
+
inject_into_class "app/controllers/#{controller_name}.rb", class_name,
|
208
208
|
" include #{module_name}\n"
|
209
|
-
|
209
|
+
|
210
210
|
end
|
211
|
-
|
211
|
+
|
212
212
|
def include_module_in_model(model_name, module_name)
|
213
|
-
inject_into_class "app/models/#{model_name.underscore}.rb", model_name,
|
213
|
+
inject_into_class "app/models/#{model_name.underscore}.rb", model_name,
|
214
214
|
" include #{module_name}\n"
|
215
|
-
|
215
|
+
|
216
216
|
end
|
217
217
|
end
|
data/lib/orthodox/version.rb
CHANGED