authentication-zero 0.0.23 → 0.0.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +3 -1
  4. data/lib/authentication_zero/version.rb +1 -1
  5. data/lib/generators/authentication/authentication_generator.rb +56 -26
  6. data/lib/generators/authentication/templates/{app/controllers → controllers}/api/cancellations_controller.rb.tt +0 -0
  7. data/lib/generators/authentication/templates/{app/controllers → controllers}/api/emails_controller.rb.tt +0 -0
  8. data/lib/generators/authentication/templates/{app/controllers → controllers}/api/password_resets_controller.rb.tt +2 -1
  9. data/lib/generators/authentication/templates/{app/controllers → controllers}/api/passwords_controller.rb.tt +0 -0
  10. data/lib/generators/authentication/templates/{app/controllers → controllers}/api/registrations_controller.rb.tt +0 -0
  11. data/lib/generators/authentication/templates/{app/controllers → controllers}/api/sessions_controller.rb.tt +0 -0
  12. data/lib/generators/authentication/templates/{app/controllers → controllers}/html/cancellations_controller.rb.tt +0 -0
  13. data/lib/generators/authentication/templates/{app/controllers → controllers}/html/emails_controller.rb.tt +0 -0
  14. data/lib/generators/authentication/templates/{app/controllers → controllers}/html/password_resets_controller.rb.tt +2 -1
  15. data/lib/generators/authentication/templates/{app/controllers → controllers}/html/passwords_controller.rb.tt +0 -0
  16. data/lib/generators/authentication/templates/{app/controllers → controllers}/html/registrations_controller.rb.tt +0 -0
  17. data/lib/generators/authentication/templates/{app/controllers → controllers}/html/sessions_controller.rb.tt +0 -0
  18. data/lib/generators/authentication/templates/{app/views → erb}/cancellations/new.html.erb.tt +0 -0
  19. data/lib/generators/authentication/templates/{app/views → erb}/email_mailer/changed.html.erb.tt +0 -0
  20. data/lib/generators/authentication/templates/{app/views → erb}/email_mailer/changed.text.erb.tt +0 -0
  21. data/lib/generators/authentication/templates/{app/views → erb}/emails/edit.html.erb.tt +0 -0
  22. data/lib/generators/authentication/templates/{app/views → erb}/password_mailer/changed.html.erb.tt +0 -0
  23. data/lib/generators/authentication/templates/{app/views → erb}/password_mailer/changed.text.erb.tt +0 -0
  24. data/lib/generators/authentication/templates/{app/views → erb}/password_mailer/reset.html.erb.tt +0 -0
  25. data/lib/generators/authentication/templates/{app/views → erb}/password_mailer/reset.text.erb.tt +0 -0
  26. data/lib/generators/authentication/templates/{app/views → erb}/password_resets/edit.html.erb.tt +0 -0
  27. data/lib/generators/authentication/templates/{app/views → erb}/password_resets/new.html.erb.tt +0 -0
  28. data/lib/generators/authentication/templates/{app/views → erb}/passwords/edit.html.erb.tt +0 -0
  29. data/lib/generators/authentication/templates/{app/views → erb}/registrations/new.html.erb.tt +0 -0
  30. data/lib/generators/authentication/templates/{app/views → erb}/sessions/new.html.erb.tt +0 -0
  31. data/lib/generators/authentication/templates/{app/mailers → mailers}/email_mailer.rb.tt +0 -0
  32. data/lib/generators/authentication/templates/{app/mailers → mailers}/password_mailer.rb.tt +1 -1
  33. data/lib/generators/authentication/templates/{app/models → models}/current.rb.tt +0 -0
  34. data/lib/generators/authentication/templates/{app/models → models}/model.rb.tt +0 -0
  35. data/lib/generators/authentication/templates/test_unit/controllers/api/password_resets_controller_test.rb.tt +2 -2
  36. data/lib/generators/authentication/templates/test_unit/controllers/html/password_resets_controller_test.rb.tt +2 -2
  37. data/lib/generators/authentication/templates/test_unit/system/password_resets_test.rb.tt +1 -1
  38. metadata +30 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78818129456d7a394a2a456605b007a2d0d68203038bb79ac0a8d9b74a9de59d
4
- data.tar.gz: 7a7b8485f5c7cb9d3573e1768e25b40ba2de04fcf27d97d2383696ffabdb2249
3
+ metadata.gz: 69456b50110f6870da499c900b547905e2e2fa01fa52986facfa491d821cde04
4
+ data.tar.gz: f72563012edb915900884a5366226114f71001b6e9f1c6344032c6badde97542
5
5
  SHA512:
6
- metadata.gz: 23bf695588244691a1a9db956f0f096e785ecd83bba969d05c7ee109b00a3a97c30a6ad13b3f874ac1f783f49181b0bdd92ff7f9cfa31b05ae223af1734ab420
7
- data.tar.gz: 0b360acf0cb305053ca5610cb2a7de73ba3a2b2a091090ddd770f7ca99daa0e2ad48e5eebdba9d1e216e13418f4ff6c93802403f5c5f12de0ee7e0c0de42fb01
6
+ metadata.gz: 196723b836ad2dd346eb82db9b24ced90117bcb03d457858efa6ef20b86ee29bc31926750ca6bd5bfea8765be1bf940f3821f11e023847a2884c01bc4bb7fb50
7
+ data.tar.gz: 9d8a6716734676a35cfe9c3db895a7dab12c07c277acff45ee5a78f9a923957e001d3db81aa197bfa15a097da13bd4afdab86e34031cd6fee51d65268129121f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- authentication-zero (0.0.23)
4
+ authentication-zero (0.0.24)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -27,7 +27,7 @@ The purpose of authentication zero is to generate a pre-built authentication sys
27
27
  - [Action mailer](https://api.rubyonrails.org/classes/ActionMailer/Base.html): Action Mailer allows you to send email from your application using a mailer model and views.
28
28
  - [Log filtering](https://guides.rubyonrails.org/action_controller_overview.html#log-filtering): Parameters 'token' and 'password' are marked [FILTERED] in the log.
29
29
  - [Functional Tests](https://guides.rubyonrails.org/testing.html#functional-tests-for-your-controllers): In Rails, testing the various actions of a controller is a form of writing functional tests.
30
- - [System Testing][https://guides.rubyonrails.org/testing.html#system-testing]: System tests allow you to test user interactions with your application, running tests in either a real or a headless browser.
30
+ - [System Testing](https://guides.rubyonrails.org/testing.html#system-testing): System tests allow you to test user interactions with your application, running tests in either a real or a headless browser.
31
31
 
32
32
  ## Installation
33
33
 
@@ -83,6 +83,8 @@ config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
83
83
  $ rails generate authentication user
84
84
  ```
85
85
 
86
+ Then run `bundle install` again!
87
+
86
88
  ## Development
87
89
 
88
90
  To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
@@ -1,3 +1,3 @@
1
1
  module AuthenticationZero
2
- VERSION = "0.0.23"
2
+ VERSION = "0.0.24"
3
3
  end
@@ -1,28 +1,40 @@
1
1
  require "rails/generators/active_record"
2
2
 
3
3
  class AuthenticationGenerator < Rails::Generators::NamedBase
4
- include ActiveRecord::Generators::Migration
5
-
6
4
  class_option :api, type: :boolean, desc: "Generates API authentication"
5
+
6
+ class_option :migration, type: :boolean
7
+ class_option :test_framework, type: :string, desc: "Test framework to be invoked"
8
+
9
+ class_option :fixture, type: :boolean
7
10
  class_option :system_tests, type: :string, desc: "Skip system test files"
8
11
 
12
+ class_option :skip_routes, type: :boolean
13
+ class_option :template_engine, type: :string, desc: "Template engine to be invoked"
14
+
9
15
  source_root File.expand_path("templates", __dir__)
10
16
 
11
17
  def add_bcrypt
12
- uncomment_lines 'Gemfile', /bcrypt/
18
+ uncomment_lines "Gemfile", /bcrypt/
13
19
  end
14
20
 
15
- def create_migrations
16
- invoke "migration", ["create_#{table_name}", "email:string:uniq", "password_digest:string", "session_token:string:uniq"]
21
+ def create_migration
22
+ if options.migration
23
+ invoke "migration", ["create_#{table_name}", "email:string:uniq", "password:digest", "session_token:string:uniq"]
24
+ end
17
25
  end
18
26
 
19
- def create_models
20
- template "app/models/model.rb", "app/models/#{file_name}.rb"
21
- template "app/models/current.rb", "app/models/current.rb"
27
+ def create_model
28
+ template "models/model.rb", "app/models/#{file_name}.rb"
29
+ template "models/current.rb", "app/models/current.rb"
22
30
  end
23
31
 
32
+ hook_for :fixture_replacement
33
+
24
34
  def create_fixture_file
25
- template "test_unit/fixtures.yml", "test/fixtures/#{fixture_file_name}.yml"
35
+ if options.fixture
36
+ template "#{test_framework}/fixtures.yml", "test/fixtures/#{fixture_file_name}.yml"
37
+ end
26
38
  end
27
39
 
28
40
  def add_application_controller_methods
@@ -57,42 +69,60 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
57
69
  end
58
70
 
59
71
  def create_controllers
60
- directory "app/controllers/#{format_folder}", "app/controllers"
72
+ directory "controllers/#{format_folder}", "app/controllers"
61
73
  end
62
74
 
63
75
  def create_views
64
76
  if options.api
65
- directory "app/views/email_mailer", "app/views/email_mailer"
66
- directory "app/views/password_mailer", "app/views/password_mailer"
77
+ directory "#{template_engine}/email_mailer", "app/views/email_mailer"
78
+ directory "#{template_engine}/password_mailer", "app/views/password_mailer"
67
79
  else
68
- directory "app/views", "app/views"
80
+ directory "#{template_engine}", "app/views"
69
81
  end
70
82
  end
71
83
 
72
84
  def create_mailers
73
- template "app/mailers/email_mailer.rb", "app/mailers/email_mailer.rb"
74
- template "app/mailers/password_mailer.rb", "app/mailers/password_mailer.rb"
85
+ template "mailers/email_mailer.rb", "app/mailers/email_mailer.rb"
86
+ template "mailers/password_mailer.rb", "app/mailers/password_mailer.rb"
75
87
  end
76
88
 
77
89
  def add_routes
78
- route "resource :password_resets, only: [:new, :edit, :create, :update]"
79
- route "resource :cancellations, only: [:new, :create]"
80
- route "resource :passwords, only: [:edit, :update]"
81
- route "resource :emails, only: [:edit, :update]"
82
- route "delete 'sign_out', to: 'sessions#destroy'"
83
- route "post 'sign_up', to: 'registrations#create'"
84
- route "get 'sign_up', to: 'registrations#new'" unless options.api?
85
- route "post 'sign_in', to: 'sessions#create'"
86
- route "get 'sign_in', to: 'sessions#new'" unless options.api?
90
+ unless options.skip_routes
91
+ route "resource :password_resets, only: [:new, :edit, :create, :update]"
92
+ route "resource :cancellations, only: [:new, :create]"
93
+ route "resource :passwords, only: [:edit, :update]"
94
+ route "resource :emails, only: [:edit, :update]"
95
+ route "delete 'sign_out', to: 'sessions#destroy'"
96
+ route "post 'sign_up', to: 'registrations#create'"
97
+ route "get 'sign_up', to: 'registrations#new'" unless options.api?
98
+ route "post 'sign_in', to: 'sessions#create'"
99
+ route "get 'sign_in', to: 'sessions#new'" unless options.api?
100
+ end
87
101
  end
88
102
 
89
103
  def create_test_files
90
- directory "test_unit/controllers/#{format_folder}", "test/controllers"
91
- directory "test_unit/system", "test/system" if !options.api? && options[:system_tests]
104
+ directory "#{test_framework}/controllers/#{format_folder}", "test/controllers"
105
+ directory "#{system_tests}/system", "test/system" if system_tests?
92
106
  end
93
107
 
94
108
  private
95
109
  def format_folder
96
110
  options.api ? "api" : "html"
97
111
  end
112
+
113
+ def template_engine
114
+ options.template_engine
115
+ end
116
+
117
+ def test_framework
118
+ options.test_framework
119
+ end
120
+
121
+ def system_tests
122
+ options.system_tests
123
+ end
124
+
125
+ def system_tests?
126
+ !options.api? && options.system_tests
127
+ end
98
128
  end
@@ -1,5 +1,6 @@
1
1
  class PasswordResetsController < ApplicationController
2
2
  skip_before_action :authenticate
3
+
3
4
  before_action :set_<%= singular_table_name %>, only: %i[ edit update ]
4
5
 
5
6
  def edit
@@ -24,7 +25,7 @@ class PasswordResetsController < ApplicationController
24
25
 
25
26
  private
26
27
  def set_<%= singular_table_name %>
27
- @<%= singular_table_name %> = <%= class_name %>.find_signed!(params[:token], purpose: "password_reset")
28
+ @<%= singular_table_name %> = <%= class_name %>.find_signed!(params[:token], purpose: :password_reset)
28
29
  rescue ActiveSupport::MessageVerifier::InvalidSignature
29
30
  render json: { error: "Your token has expired, please request a new one" }, status: :bad_request
30
31
  end
@@ -1,5 +1,6 @@
1
1
  class PasswordResetsController < ApplicationController
2
2
  skip_before_action :authenticate
3
+
3
4
  before_action :set_<%= singular_table_name %>, only: %i[ edit update ]
4
5
 
5
6
  def new
@@ -27,7 +28,7 @@ class PasswordResetsController < ApplicationController
27
28
 
28
29
  private
29
30
  def set_<%= singular_table_name %>
30
- @<%= singular_table_name %> = <%= class_name %>.find_signed!(params[:token], purpose: "password_reset")
31
+ @<%= singular_table_name %> = <%= class_name %>.find_signed!(params[:token], purpose: :password_reset)
31
32
  rescue ActiveSupport::MessageVerifier::InvalidSignature
32
33
  redirect_to new_password_resets_path, alert: "Your token has expired, please request a new one"
33
34
  end
@@ -4,7 +4,7 @@ class PasswordMailer < ApplicationMailer
4
4
  end
5
5
 
6
6
  def reset
7
- @signed_id = params[:<%= singular_table_name %>].signed_id(purpose: "password_reset", expires_in: 20.minutes)
7
+ @signed_id = params[:<%= singular_table_name %>].signed_id(purpose: :password_reset, expires_in: 20.minutes)
8
8
  mail to: params[:<%= singular_table_name %>].email
9
9
  end
10
10
  end
@@ -3,8 +3,8 @@ require "test_helper"
3
3
  class PasswordResetsControllerTest < ActionDispatch::IntegrationTest
4
4
  setup do
5
5
  @<%= singular_table_name %> = <%= table_name %>(:lazaro_nixon)
6
- @sid = @<%= singular_table_name %>.signed_id(purpose: "password_reset", expires_in: 20.minutes)
7
- @sid_exp = @<%= singular_table_name %>.signed_id(purpose: "password_reset", expires_in: 0.minutes)
6
+ @sid = @<%= singular_table_name %>.signed_id(purpose: :password_reset, expires_in: 20.minutes)
7
+ @sid_exp = @<%= singular_table_name %>.signed_id(purpose: :password_reset, expires_in: 0.minutes)
8
8
  end
9
9
 
10
10
  test "should get edit" do
@@ -3,8 +3,8 @@ require "test_helper"
3
3
  class PasswordResetsControllerTest < ActionDispatch::IntegrationTest
4
4
  setup do
5
5
  @<%= singular_table_name %> = <%= table_name %>(:lazaro_nixon)
6
- @sid = @<%= singular_table_name %>.signed_id(purpose: "password_reset", expires_in: 20.minutes)
7
- @sid_exp = @<%= singular_table_name %>.signed_id(purpose: "password_reset", expires_in: 0.minutes)
6
+ @sid = @<%= singular_table_name %>.signed_id(purpose: :password_reset, expires_in: 20.minutes)
7
+ @sid_exp = @<%= singular_table_name %>.signed_id(purpose: :password_reset, expires_in: 0.minutes)
8
8
  end
9
9
 
10
10
  test "should get new" do
@@ -3,7 +3,7 @@ require "application_system_test_case"
3
3
  class PasswordResetsTest < ApplicationSystemTestCase
4
4
  setup do
5
5
  @<%= singular_table_name %> = <%= table_name %>(:lazaro_nixon)
6
- @sid = @<%= singular_table_name %>.signed_id(purpose: "password_reset", expires_in: 20.minutes)
6
+ @sid = @<%= singular_table_name %>.signed_id(purpose: :password_reset, expires_in: 20.minutes)
7
7
  end
8
8
 
9
9
  test "sending a password reset email" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authentication-zero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.23
4
+ version: 0.0.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nixon
@@ -31,35 +31,35 @@ files:
31
31
  - lib/authentication_zero/version.rb
32
32
  - lib/generators/authentication/USAGE
33
33
  - lib/generators/authentication/authentication_generator.rb
34
- - lib/generators/authentication/templates/app/controllers/api/cancellations_controller.rb.tt
35
- - lib/generators/authentication/templates/app/controllers/api/emails_controller.rb.tt
36
- - lib/generators/authentication/templates/app/controllers/api/password_resets_controller.rb.tt
37
- - lib/generators/authentication/templates/app/controllers/api/passwords_controller.rb.tt
38
- - lib/generators/authentication/templates/app/controllers/api/registrations_controller.rb.tt
39
- - lib/generators/authentication/templates/app/controllers/api/sessions_controller.rb.tt
40
- - lib/generators/authentication/templates/app/controllers/html/cancellations_controller.rb.tt
41
- - lib/generators/authentication/templates/app/controllers/html/emails_controller.rb.tt
42
- - lib/generators/authentication/templates/app/controllers/html/password_resets_controller.rb.tt
43
- - lib/generators/authentication/templates/app/controllers/html/passwords_controller.rb.tt
44
- - lib/generators/authentication/templates/app/controllers/html/registrations_controller.rb.tt
45
- - lib/generators/authentication/templates/app/controllers/html/sessions_controller.rb.tt
46
- - lib/generators/authentication/templates/app/mailers/email_mailer.rb.tt
47
- - lib/generators/authentication/templates/app/mailers/password_mailer.rb.tt
48
- - lib/generators/authentication/templates/app/models/current.rb.tt
49
- - lib/generators/authentication/templates/app/models/model.rb.tt
50
- - lib/generators/authentication/templates/app/views/cancellations/new.html.erb.tt
51
- - lib/generators/authentication/templates/app/views/email_mailer/changed.html.erb.tt
52
- - lib/generators/authentication/templates/app/views/email_mailer/changed.text.erb.tt
53
- - lib/generators/authentication/templates/app/views/emails/edit.html.erb.tt
54
- - lib/generators/authentication/templates/app/views/password_mailer/changed.html.erb.tt
55
- - lib/generators/authentication/templates/app/views/password_mailer/changed.text.erb.tt
56
- - lib/generators/authentication/templates/app/views/password_mailer/reset.html.erb.tt
57
- - lib/generators/authentication/templates/app/views/password_mailer/reset.text.erb.tt
58
- - lib/generators/authentication/templates/app/views/password_resets/edit.html.erb.tt
59
- - lib/generators/authentication/templates/app/views/password_resets/new.html.erb.tt
60
- - lib/generators/authentication/templates/app/views/passwords/edit.html.erb.tt
61
- - lib/generators/authentication/templates/app/views/registrations/new.html.erb.tt
62
- - lib/generators/authentication/templates/app/views/sessions/new.html.erb.tt
34
+ - lib/generators/authentication/templates/controllers/api/cancellations_controller.rb.tt
35
+ - lib/generators/authentication/templates/controllers/api/emails_controller.rb.tt
36
+ - lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt
37
+ - lib/generators/authentication/templates/controllers/api/passwords_controller.rb.tt
38
+ - lib/generators/authentication/templates/controllers/api/registrations_controller.rb.tt
39
+ - lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
40
+ - lib/generators/authentication/templates/controllers/html/cancellations_controller.rb.tt
41
+ - lib/generators/authentication/templates/controllers/html/emails_controller.rb.tt
42
+ - lib/generators/authentication/templates/controllers/html/password_resets_controller.rb.tt
43
+ - lib/generators/authentication/templates/controllers/html/passwords_controller.rb.tt
44
+ - lib/generators/authentication/templates/controllers/html/registrations_controller.rb.tt
45
+ - lib/generators/authentication/templates/controllers/html/sessions_controller.rb.tt
46
+ - lib/generators/authentication/templates/erb/cancellations/new.html.erb.tt
47
+ - lib/generators/authentication/templates/erb/email_mailer/changed.html.erb.tt
48
+ - lib/generators/authentication/templates/erb/email_mailer/changed.text.erb.tt
49
+ - lib/generators/authentication/templates/erb/emails/edit.html.erb.tt
50
+ - lib/generators/authentication/templates/erb/password_mailer/changed.html.erb.tt
51
+ - lib/generators/authentication/templates/erb/password_mailer/changed.text.erb.tt
52
+ - lib/generators/authentication/templates/erb/password_mailer/reset.html.erb.tt
53
+ - lib/generators/authentication/templates/erb/password_mailer/reset.text.erb.tt
54
+ - lib/generators/authentication/templates/erb/password_resets/edit.html.erb.tt
55
+ - lib/generators/authentication/templates/erb/password_resets/new.html.erb.tt
56
+ - lib/generators/authentication/templates/erb/passwords/edit.html.erb.tt
57
+ - lib/generators/authentication/templates/erb/registrations/new.html.erb.tt
58
+ - lib/generators/authentication/templates/erb/sessions/new.html.erb.tt
59
+ - lib/generators/authentication/templates/mailers/email_mailer.rb.tt
60
+ - lib/generators/authentication/templates/mailers/password_mailer.rb.tt
61
+ - lib/generators/authentication/templates/models/current.rb.tt
62
+ - lib/generators/authentication/templates/models/model.rb.tt
63
63
  - lib/generators/authentication/templates/test_unit/controllers/api/cancellations_controller_test.rb.tt
64
64
  - lib/generators/authentication/templates/test_unit/controllers/api/emails_controller_test.rb.tt
65
65
  - lib/generators/authentication/templates/test_unit/controllers/api/password_resets_controller_test.rb.tt