authentication-zero 0.0.21 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +5 -8
- data/lib/authentication_zero/version.rb +1 -1
- data/lib/generators/authentication/USAGE +7 -2
- data/lib/generators/authentication/authentication_generator.rb +99 -56
- data/lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt +3 -2
- data/lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt +1 -1
- data/lib/generators/authentication/templates/controllers/html/password_resets_controller.rb.tt +2 -1
- data/lib/generators/authentication/templates/controllers/html/registrations_controller.rb.tt +1 -1
- data/lib/generators/authentication/templates/controllers/html/sessions_controller.rb.tt +2 -2
- data/lib/generators/authentication/templates/{views → erb}/cancellations/new.html.erb.tt +0 -0
- data/lib/generators/authentication/templates/{views → erb}/email_mailer/changed.html.erb.tt +0 -0
- data/lib/generators/authentication/templates/{views → erb}/email_mailer/changed.text.erb.tt +0 -0
- data/lib/generators/authentication/templates/{views → erb}/emails/edit.html.erb.tt +0 -0
- data/lib/generators/authentication/templates/{views → erb}/password_mailer/changed.html.erb.tt +0 -0
- data/lib/generators/authentication/templates/{views → erb}/password_mailer/changed.text.erb.tt +0 -0
- data/lib/generators/authentication/templates/{views → erb}/password_mailer/reset.html.erb.tt +0 -0
- data/lib/generators/authentication/templates/{views → erb}/password_mailer/reset.text.erb.tt +0 -0
- data/lib/generators/authentication/templates/{views → erb}/password_resets/edit.html.erb.tt +0 -0
- data/lib/generators/authentication/templates/{views → erb}/password_resets/new.html.erb.tt +0 -0
- data/lib/generators/authentication/templates/{views → erb}/passwords/edit.html.erb.tt +0 -0
- data/lib/generators/authentication/templates/{views → erb}/registrations/new.html.erb.tt +0 -0
- data/lib/generators/authentication/templates/{views → erb}/sessions/new.html.erb.tt +0 -0
- data/lib/generators/authentication/templates/mailers/password_mailer.rb.tt +1 -1
- data/lib/generators/authentication/templates/models/{resource.rb.tt → model.rb.tt} +16 -3
- data/lib/generators/authentication/templates/test_unit/controllers/api/cancellations_controller_test.rb.tt +20 -0
- data/lib/generators/authentication/templates/test_unit/controllers/api/emails_controller_test.rb.tt +29 -0
- data/lib/generators/authentication/templates/test_unit/controllers/api/password_resets_controller_test.rb.tt +46 -0
- data/lib/generators/authentication/templates/test_unit/controllers/api/passwords_controller_test.rb.tt +29 -0
- data/lib/generators/authentication/templates/test_unit/controllers/api/registrations_controller_test.rb.tt +11 -0
- data/lib/generators/authentication/templates/test_unit/controllers/api/sessions_controller_test.rb.tt +29 -0
- data/lib/generators/authentication/templates/test_unit/controllers/html/cancellations_controller_test.rb.tt +24 -0
- data/lib/generators/authentication/templates/test_unit/controllers/html/emails_controller_test.rb.tt +33 -0
- data/lib/generators/authentication/templates/test_unit/controllers/html/password_resets_controller_test.rb.tt +49 -0
- data/lib/generators/authentication/templates/test_unit/controllers/html/passwords_controller_test.rb.tt +33 -0
- data/lib/generators/authentication/templates/test_unit/controllers/html/registrations_controller_test.rb.tt +18 -0
- data/lib/generators/authentication/templates/test_unit/controllers/html/sessions_controller_test.rb.tt +45 -0
- data/lib/generators/authentication/templates/test_unit/fixtures.yml.tt +6 -0
- data/lib/generators/authentication/templates/test_unit/system/cancellations_test.rb.tt +23 -0
- data/lib/generators/authentication/templates/test_unit/system/emails_test.rb.tt +26 -0
- data/lib/generators/authentication/templates/test_unit/system/password_resets_test.rb.tt +28 -0
- data/lib/generators/authentication/templates/test_unit/system/passwords_test.rb.tt +27 -0
- data/lib/generators/authentication/templates/test_unit/system/registrations_test.rb.tt +15 -0
- data/lib/generators/authentication/templates/test_unit/system/sessions_test.rb.tt +32 -0
- metadata +35 -17
- data/lib/generators/authentication/templates/migration.rb.tt +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30572c49dd754b2b621acf5adad550f2ad179f3bb3af559748e296b16b04c529
|
4
|
+
data.tar.gz: 569ac3a9411562d1a2bf5ee049b3cbf1350fc43cc1a2a5e837ca421f7994ae63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a78c56a451d289464bb25e4d86f1765a5c74c032f2c19aaa7268cb3653680fdb7bae3242c911f3d7d6402d3cd22d771ab9cef1316866b8fd6d89ecf6991d2772
|
7
|
+
data.tar.gz: 7e245a32b1150f57ceb6941cdffce360cf9ac67d49ef583b4e5e1d6ee0afcb0d593b7c2afb67e66369f77ede9f8c347203d109537e26c184fd25ce1c8ddb0765
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -19,31 +19,26 @@ The purpose of authentication zero is to generate a pre-built authentication sys
|
|
19
19
|
|
20
20
|
- [has_secure_password](https://api.rubyonrails.org/classes/ActiveModel/SecurePassword/ClassMethods.html#method-i-has_secure_password): Adds methods to set and authenticate against a BCrypt password.
|
21
21
|
- [has_secure_token](https://api.rubyonrails.org/classes/ActiveRecord/SecureToken/ClassMethods.html#method-i-has_secure_token): Adds methods to generate unique tokens.
|
22
|
-
- [
|
22
|
+
- [signed cookies](https://api.rubyonrails.org/classes/ActionDispatch/Cookies.html): Returns a jar that'll automatically generate a signed representation of cookie value and verify it when reading from the cookie again.
|
23
23
|
- [httponly cookies](https://api.rubyonrails.org/classes/ActionDispatch/Cookies.html): A cookie with the httponly attribute is inaccessible to the JavaScript, this precaution helps mitigate cross-site scripting (XSS) attacks.
|
24
24
|
- [signed_id](https://api.rubyonrails.org/classes/ActiveRecord/SignedId.html): Returns a signed id that is tamper proof, so it's safe to send in an email or otherwise share with the outside world.
|
25
25
|
- [Current attributes](https://api.rubyonrails.org/classes/ActiveSupport/CurrentAttributes.html): Abstract super class that provides a thread-isolated attributes singleton, which resets automatically before and after each request.
|
26
26
|
- [Callbacks](https://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html): We use callbacks to send emails after changing an email or password.
|
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
|
+
- [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.
|
29
31
|
|
30
32
|
## Installation
|
31
33
|
|
32
34
|
Add this lines to your application's Gemfile:
|
33
35
|
|
34
36
|
```ruby
|
35
|
-
gem "bcrypt"
|
36
37
|
gem "authentication-zero"
|
37
38
|
```
|
38
39
|
|
39
40
|
Then run `bundle install`
|
40
41
|
|
41
|
-
First, you need to [set up active record encryption](https://guides.rubyonrails.org/active_record_encryption.html#setup), you must generate your keys and put them in your credentials:
|
42
|
-
```
|
43
|
-
$ rails db:encryption:init
|
44
|
-
$ rails credentials:edit
|
45
|
-
```
|
46
|
-
|
47
42
|
You'll need to set the root path in your routes.rb, for this example let's use the following:
|
48
43
|
|
49
44
|
```ruby
|
@@ -88,6 +83,8 @@ config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
|
|
88
83
|
$ rails generate authentication user
|
89
84
|
```
|
90
85
|
|
86
|
+
Then run `bundle install` again!
|
87
|
+
|
91
88
|
## Development
|
92
89
|
|
93
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,6 +1,11 @@
|
|
1
1
|
Description:
|
2
|
-
The purpose of authentication zero is to generate a pre-built
|
3
|
-
|
2
|
+
The purpose of authentication zero is to generate a pre-built
|
3
|
+
authentication system into a rails application that
|
4
|
+
follows both security and rails best practices.
|
5
|
+
|
6
|
+
By generating code into the user's application
|
7
|
+
instead of using a library, the user has complete freedom
|
8
|
+
to modify the authentication system so it works best with their app.
|
4
9
|
|
5
10
|
Example:
|
6
11
|
bin/rails generate authentication user
|
@@ -1,84 +1,127 @@
|
|
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"
|
7
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
|
10
|
+
class_option :system_tests, type: :string, desc: "Skip system test files"
|
11
|
+
|
12
|
+
class_option :skip_routes, type: :boolean
|
13
|
+
class_option :template_engine, type: :string, desc: "Template engine to be invoked"
|
14
|
+
|
8
15
|
source_root File.expand_path("templates", __dir__)
|
9
16
|
|
10
|
-
def
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
def add_bcrypt
|
18
|
+
uncomment_lines "Gemfile", /bcrypt/
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_migration
|
22
|
+
if options.migration
|
23
|
+
invoke "migration", ["create_#{table_name}", "email:string:uniq", "password:digest", "session_token:string:uniq"]
|
15
24
|
end
|
16
25
|
end
|
17
26
|
|
18
|
-
def
|
19
|
-
template "
|
20
|
-
template "
|
27
|
+
def create_models
|
28
|
+
template "models/model.rb", "app/models/#{file_name}.rb"
|
29
|
+
template "models/current.rb", "app/models/current.rb"
|
30
|
+
end
|
31
|
+
|
32
|
+
hook_for :fixture_replacement
|
33
|
+
|
34
|
+
def create_fixture_file
|
35
|
+
if options.fixture
|
36
|
+
template "#{test_framework}/fixtures.yml", "test/fixtures/#{fixture_file_name}.yml"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_application_controller_methods
|
41
|
+
api_code = <<~CODE
|
42
|
+
include ActionController::HttpAuthentication::Token::ControllerMethods
|
43
|
+
|
44
|
+
before_action :authenticate
|
45
|
+
|
46
|
+
private
|
47
|
+
def authenticate
|
48
|
+
authenticate_or_request_with_http_token do |token, _options|
|
49
|
+
Current.#{singular_table_name} = #{class_name}.find_signed_session_token(token)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
CODE
|
53
|
+
|
54
|
+
html_code = <<~CODE
|
55
|
+
before_action :authenticate
|
56
|
+
|
57
|
+
private
|
58
|
+
def authenticate
|
59
|
+
if #{singular_table_name} = #{class_name}.find_by_session_token(cookies.signed[:session_token])
|
60
|
+
Current.#{singular_table_name} = #{singular_table_name}
|
61
|
+
else
|
62
|
+
redirect_to sign_in_path, alert: "You need to sign in or sign up before continuing"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
CODE
|
66
|
+
|
67
|
+
inject_code = options.api? ? api_code : html_code
|
68
|
+
inject_into_class "app/controllers/application_controller.rb", "ApplicationController", optimize_indentation(inject_code, 2), verbose: false
|
69
|
+
end
|
70
|
+
|
71
|
+
def create_controllers
|
72
|
+
directory "controllers/#{format_folder}", "app/controllers"
|
21
73
|
end
|
22
74
|
|
23
75
|
def create_views
|
24
76
|
if options.api
|
25
|
-
directory "
|
26
|
-
directory "
|
77
|
+
directory "#{template_engine}/email_mailer", "app/views/email_mailer"
|
78
|
+
directory "#{template_engine}/password_mailer", "app/views/password_mailer"
|
27
79
|
else
|
28
|
-
directory "
|
80
|
+
directory "#{template_engine}", "app/views"
|
29
81
|
end
|
30
82
|
end
|
31
83
|
|
32
|
-
def
|
33
|
-
|
34
|
-
template "models/resource.rb", "app/models/#{singular_table_name}.rb"
|
84
|
+
def create_mailers
|
85
|
+
directory "mailers", "app/mailers"
|
35
86
|
end
|
36
87
|
|
37
|
-
def
|
38
|
-
|
88
|
+
def add_routes
|
89
|
+
unless options.skip_routes
|
90
|
+
route "resource :password_resets, only: [:new, :edit, :create, :update]"
|
91
|
+
route "resource :cancellations, only: [:new, :create]"
|
92
|
+
route "resource :passwords, only: [:edit, :update]"
|
93
|
+
route "resource :emails, only: [:edit, :update]"
|
94
|
+
route "delete 'sign_out', to: 'sessions#destroy'"
|
95
|
+
route "post 'sign_up', to: 'registrations#create'"
|
96
|
+
route "get 'sign_up', to: 'registrations#new'" unless options.api?
|
97
|
+
route "post 'sign_in', to: 'sessions#create'"
|
98
|
+
route "get 'sign_in', to: 'sessions#new'" unless options.api?
|
99
|
+
end
|
39
100
|
end
|
40
101
|
|
41
|
-
def
|
42
|
-
|
43
|
-
|
44
|
-
route "resource :passwords, only: [:edit, :update]"
|
45
|
-
route "resource :emails, only: [:edit, :update]"
|
46
|
-
route "delete 'sign_out', to: 'sessions#destroy'"
|
47
|
-
route "post 'sign_up', to: 'registrations#create'"
|
48
|
-
route "get 'sign_up', to: 'registrations#new'" unless options.api?
|
49
|
-
route "post 'sign_in', to: 'sessions#create'"
|
50
|
-
route "get 'sign_in', to: 'sessions#new'" unless options.api?
|
102
|
+
def create_test_files
|
103
|
+
directory "#{test_framework}/controllers/#{format_folder}", "test/controllers"
|
104
|
+
directory "#{system_tests}/system", "test/system" if system_tests?
|
51
105
|
end
|
52
106
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
107
|
+
private
|
108
|
+
def format_folder
|
109
|
+
options.api ? "api" : "html"
|
110
|
+
end
|
57
111
|
|
58
|
-
|
112
|
+
def template_engine
|
113
|
+
options.template_engine
|
114
|
+
end
|
59
115
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
before_action :authenticate
|
71
|
-
|
72
|
-
private
|
73
|
-
def authenticate
|
74
|
-
if #{singular_table_name} = #{class_name}.find_by_session_token(cookies[:session_token])
|
75
|
-
Current.#{singular_table_name} = #{singular_table_name}
|
76
|
-
else
|
77
|
-
redirect_to sign_in_path, alert: "You need to sign in or sign up before continuing"
|
78
|
-
end
|
79
|
-
end
|
80
|
-
CODE
|
81
|
-
end
|
116
|
+
def test_framework
|
117
|
+
options.test_framework
|
118
|
+
end
|
119
|
+
|
120
|
+
def system_tests
|
121
|
+
options.system_tests
|
122
|
+
end
|
123
|
+
|
124
|
+
def system_tests?
|
125
|
+
!options.api? && options.system_tests
|
82
126
|
end
|
83
|
-
end
|
84
127
|
end
|
data/lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt
CHANGED
@@ -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
|
@@ -10,7 +11,7 @@ class PasswordResetsController < ApplicationController
|
|
10
11
|
if @<%= singular_table_name %> = <%= class_name %>.find_by_email(params[:email])
|
11
12
|
PasswordMailer.with(<%= singular_table_name %>: @<%= singular_table_name %>).reset.deliver_later
|
12
13
|
else
|
13
|
-
render json: { error: "The email address doesn't exist in our database" }, status: :
|
14
|
+
render json: { error: "The email address doesn't exist in our database" }, status: :not_found
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
@@ -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:
|
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
|
@@ -5,7 +5,7 @@ class SessionsController < ApplicationController
|
|
5
5
|
@<%= singular_table_name %> = <%= class_name %>.find_by_email(params[:email])
|
6
6
|
|
7
7
|
if @<%= singular_table_name %>.try(:authenticate, params[:password])
|
8
|
-
render json: { session_token: @<%= singular_table_name %>.
|
8
|
+
render json: { session_token: @<%= singular_table_name %>.signed_session_token }, status: :ok
|
9
9
|
else
|
10
10
|
render json: { error: "Invalid email or password" }, status: :unauthorized
|
11
11
|
end
|
data/lib/generators/authentication/templates/controllers/html/password_resets_controller.rb.tt
CHANGED
@@ -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:
|
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
|
data/lib/generators/authentication/templates/controllers/html/registrations_controller.rb.tt
CHANGED
@@ -9,7 +9,7 @@ class RegistrationsController < ApplicationController
|
|
9
9
|
@<%= singular_table_name %> = <%= class_name %>.new(<%= "#{singular_table_name}_params" %>)
|
10
10
|
|
11
11
|
if @<%= singular_table_name %>.save
|
12
|
-
cookies[:session_token] = { value: @<%= singular_table_name %>.session_token, httponly: true }
|
12
|
+
cookies.signed[:session_token] = { value: @<%= singular_table_name %>.session_token, httponly: true }
|
13
13
|
redirect_to root_path, notice: "Welcome! You have signed up successfully"
|
14
14
|
else
|
15
15
|
render :new, status: :unprocessable_entity
|
@@ -10,9 +10,9 @@ class SessionsController < ApplicationController
|
|
10
10
|
|
11
11
|
if @<%= singular_table_name %>.try(:authenticate, params[:password])
|
12
12
|
if params[:remember_me] == "1"
|
13
|
-
cookies.permanent[:session_token] = { value: @<%= singular_table_name %>.session_token, httponly: true }
|
13
|
+
cookies.signed.permanent[:session_token] = { value: @<%= singular_table_name %>.session_token, httponly: true }
|
14
14
|
else
|
15
|
-
cookies[:session_token] = { value: @<%= singular_table_name %>.session_token, httponly: true }
|
15
|
+
cookies.signed[:session_token] = { value: @<%= singular_table_name %>.session_token, httponly: true }
|
16
16
|
end
|
17
17
|
|
18
18
|
redirect_to root_path, notice: "Signed in successfully"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/generators/authentication/templates/{views → erb}/password_mailer/changed.html.erb.tt
RENAMED
File without changes
|
data/lib/generators/authentication/templates/{views → erb}/password_mailer/changed.text.erb.tt
RENAMED
File without changes
|
data/lib/generators/authentication/templates/{views → erb}/password_mailer/reset.html.erb.tt
RENAMED
File without changes
|
data/lib/generators/authentication/templates/{views → erb}/password_mailer/reset.text.erb.tt
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -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:
|
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
|
@@ -1,13 +1,11 @@
|
|
1
1
|
class <%= class_name %> < ApplicationRecord
|
2
|
-
has_secure_password :password
|
3
2
|
has_secure_token :session_token
|
3
|
+
has_secure_password
|
4
4
|
|
5
5
|
validates :email, presence: true, uniqueness: true
|
6
6
|
validates :email, format: { with: /\A[^@\s]+@[^@\s]+\z/ }
|
7
7
|
validates_length_of :password, minimum: 8, allow_blank: true
|
8
8
|
|
9
|
-
encrypts :session_token, deterministic: true
|
10
|
-
|
11
9
|
before_validation do
|
12
10
|
self.email = email.downcase.strip
|
13
11
|
end
|
@@ -23,4 +21,19 @@ class <%= class_name %> < ApplicationRecord
|
|
23
21
|
PasswordMailer.with(<%= singular_table_name %>: self).changed.deliver_later
|
24
22
|
end
|
25
23
|
end
|
24
|
+
<% if options.api? %>
|
25
|
+
def signed_session_token
|
26
|
+
Rails.application.message_verifier(:session_token).generate(session_token)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.find_signed_session_token(signed_session_token)
|
30
|
+
if session_token = Rails.application.message_verifier(:session_token).verified(signed_session_token)
|
31
|
+
find_by_session_token(session_token)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def as_json(options = {})
|
36
|
+
super(options.merge(except: [:password_digest, :session_token]))
|
37
|
+
end
|
38
|
+
<% end -%>
|
26
39
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class CancellationsControllerTest < ActionDispatch::IntegrationTest
|
4
|
+
setup do
|
5
|
+
@<%= singular_table_name %>, @token = sign_in_as(<%= table_name %>(:lazaro_nixon))
|
6
|
+
end
|
7
|
+
|
8
|
+
test "should create cancellation" do
|
9
|
+
assert_difference("<%= class_name %>.count", -1) do
|
10
|
+
post cancellations_url, headers: { "Authorization" => "Bearer #{@token}" }
|
11
|
+
end
|
12
|
+
|
13
|
+
assert_response :no_content
|
14
|
+
end
|
15
|
+
|
16
|
+
def sign_in_as(<%= singular_table_name %>)
|
17
|
+
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "secret123" })
|
18
|
+
[<%= singular_table_name %>, response.parsed_body["session_token"]]
|
19
|
+
end
|
20
|
+
end
|
data/lib/generators/authentication/templates/test_unit/controllers/api/emails_controller_test.rb.tt
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class EmailsControllerTest < ActionDispatch::IntegrationTest
|
4
|
+
setup do
|
5
|
+
@<%= singular_table_name %>, @token = sign_in_as(<%= table_name %>(:lazaro_nixon))
|
6
|
+
end
|
7
|
+
|
8
|
+
test "should update email" do
|
9
|
+
assert_enqueued_email_with EmailMailer, :changed, args: { change: [@<%= singular_table_name %>.email, "new_email@hey.com"] } do
|
10
|
+
patch emails_url, params: { current_password: "secret123", email: "new_email@hey.com" }, headers: { "Authorization" => "Bearer #{@token}" }
|
11
|
+
end
|
12
|
+
|
13
|
+
assert_response :success
|
14
|
+
end
|
15
|
+
|
16
|
+
test "should not update email with wrong current password" do
|
17
|
+
assert_no_enqueued_emails do
|
18
|
+
patch emails_url, params: { current_password: "wrong_password", email: @<%= singular_table_name %>.email }, headers: { "Authorization" => "Bearer #{@token}" }
|
19
|
+
end
|
20
|
+
|
21
|
+
assert_response :bad_request
|
22
|
+
assert_equal "The current password you entered is incorrect", response.parsed_body["error"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def sign_in_as(<%= singular_table_name %>)
|
26
|
+
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "secret123" })
|
27
|
+
[<%= singular_table_name %>, response.parsed_body["session_token"]]
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class PasswordResetsControllerTest < ActionDispatch::IntegrationTest
|
4
|
+
setup do
|
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)
|
8
|
+
end
|
9
|
+
|
10
|
+
test "should get edit" do
|
11
|
+
get edit_password_resets_url(token: @sid)
|
12
|
+
|
13
|
+
assert_response :not_found
|
14
|
+
assert_equal "Open this link in your device", response.parsed_body["error"]
|
15
|
+
end
|
16
|
+
|
17
|
+
test "should send a password reset email" do
|
18
|
+
assert_enqueued_email_with PasswordMailer, :reset, args: { <%= singular_table_name %>: @<%= singular_table_name %> } do
|
19
|
+
post password_resets_url, params: { email: @<%= singular_table_name %>.email }
|
20
|
+
end
|
21
|
+
|
22
|
+
assert_response :no_content
|
23
|
+
end
|
24
|
+
|
25
|
+
test "should not send a password reset email to a nonexistent email" do
|
26
|
+
assert_no_enqueued_emails do
|
27
|
+
post password_resets_url, params: { email: "invalid_email@hey.com" }
|
28
|
+
end
|
29
|
+
|
30
|
+
assert_response :not_found
|
31
|
+
assert_equal "The email address doesn't exist in our database", response.parsed_body["error"]
|
32
|
+
end
|
33
|
+
|
34
|
+
test "should update password" do
|
35
|
+
patch password_resets_url, params: { token: @sid, password: "new_password", password_confirmation: "new_password" }
|
36
|
+
|
37
|
+
assert_response :success
|
38
|
+
end
|
39
|
+
|
40
|
+
test "should not update password with expired token" do
|
41
|
+
patch password_resets_url, params: { token: @sid_exp, password: "new_password", password_confirmation: "new_password" }
|
42
|
+
|
43
|
+
assert_response :bad_request
|
44
|
+
assert_equal "Your token has expired, please request a new one", response.parsed_body["error"]
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class PasswordsControllerTest < ActionDispatch::IntegrationTest
|
4
|
+
setup do
|
5
|
+
@<%= singular_table_name %>, @token = sign_in_as(<%= table_name %>(:lazaro_nixon))
|
6
|
+
end
|
7
|
+
|
8
|
+
test "should update password" do
|
9
|
+
assert_enqueued_email_with PasswordMailer, :changed, args: { <%= singular_table_name %>: @<%= singular_table_name %> } do
|
10
|
+
patch passwords_url, params: { current_password: "secret123", password: "new_password", password_confirmation: "new_password" }, headers: { "Authorization" => "Bearer #{@token}" }
|
11
|
+
end
|
12
|
+
|
13
|
+
assert_response :success
|
14
|
+
end
|
15
|
+
|
16
|
+
test "should not update password with wrong current password" do
|
17
|
+
assert_no_enqueued_emails do
|
18
|
+
patch passwords_url, params: { current_password: "wrong_password", password: "new_password", password_confirmation: "new_password" }, headers: { "Authorization" => "Bearer #{@token}" }
|
19
|
+
end
|
20
|
+
|
21
|
+
assert_response :bad_request
|
22
|
+
assert_equal "The current password you entered is incorrect", response.parsed_body["error"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def sign_in_as(<%= singular_table_name %>)
|
26
|
+
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "secret123" })
|
27
|
+
[<%= singular_table_name %>, response.parsed_body["session_token"]]
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class RegistrationsControllerTest < ActionDispatch::IntegrationTest
|
4
|
+
test "should sign up" do
|
5
|
+
assert_difference("<%= class_name %>.count") do
|
6
|
+
post sign_up_url, params: { email: "lazaronixon@hey.com", password: "secret123", password_confirmation: "secret123" }
|
7
|
+
end
|
8
|
+
|
9
|
+
assert_response :created
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class SessionsControllerTest < ActionDispatch::IntegrationTest
|
4
|
+
setup do
|
5
|
+
@<%= singular_table_name %> = <%= table_name %>(:lazaro_nixon)
|
6
|
+
end
|
7
|
+
|
8
|
+
test "should sign in" do
|
9
|
+
post sign_in_url, params: { email: @<%= singular_table_name %>.email, password: "secret123" }
|
10
|
+
assert_response :success
|
11
|
+
end
|
12
|
+
|
13
|
+
test "should not sign in with wrong credentials" do
|
14
|
+
post sign_in_url, params: { email: @<%= singular_table_name %>.email, password: "wrong_password" }
|
15
|
+
assert_response :unauthorized
|
16
|
+
end
|
17
|
+
|
18
|
+
test "should sign out" do
|
19
|
+
<%= singular_table_name %>, token = sign_in_as(@<%= singular_table_name %>)
|
20
|
+
|
21
|
+
delete sign_out_url, headers: { "Authorization" => "Bearer #{token}" }
|
22
|
+
assert_response :no_content
|
23
|
+
end
|
24
|
+
|
25
|
+
def sign_in_as(<%= singular_table_name %>)
|
26
|
+
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "secret123" })
|
27
|
+
[<%= singular_table_name %>, response.parsed_body["session_token"]]
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class CancellationsControllerTest < ActionDispatch::IntegrationTest
|
4
|
+
setup do
|
5
|
+
@<%= singular_table_name %> = sign_in_as(<%= table_name %>(:lazaro_nixon))
|
6
|
+
end
|
7
|
+
|
8
|
+
test "should get new" do
|
9
|
+
get new_cancellations_url
|
10
|
+
assert_response :success
|
11
|
+
end
|
12
|
+
|
13
|
+
test "should create cancellation" do
|
14
|
+
assert_difference("<%= class_name %>.count", -1) do
|
15
|
+
post cancellations_url
|
16
|
+
end
|
17
|
+
|
18
|
+
assert_redirected_to sign_in_url
|
19
|
+
end
|
20
|
+
|
21
|
+
def sign_in_as(<%= singular_table_name %>)
|
22
|
+
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "secret123" }); user
|
23
|
+
end
|
24
|
+
end
|
data/lib/generators/authentication/templates/test_unit/controllers/html/emails_controller_test.rb.tt
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class EmailsControllerTest < ActionDispatch::IntegrationTest
|
4
|
+
setup do
|
5
|
+
@<%= singular_table_name %> = sign_in_as(<%= table_name %>(:lazaro_nixon))
|
6
|
+
end
|
7
|
+
|
8
|
+
test "should get edit" do
|
9
|
+
get edit_emails_url
|
10
|
+
assert_response :success
|
11
|
+
end
|
12
|
+
|
13
|
+
test "should update email" do
|
14
|
+
assert_enqueued_email_with EmailMailer, :changed, args: { change: [@<%= singular_table_name %>.email, "new_email@hey.com"] } do
|
15
|
+
patch emails_url, params: { current_password: "secret123", <%= singular_table_name %>: { email: "new_email@hey.com" } }
|
16
|
+
end
|
17
|
+
|
18
|
+
assert_redirected_to root_path
|
19
|
+
end
|
20
|
+
|
21
|
+
test "should not update email with wrong current password" do
|
22
|
+
assert_no_enqueued_emails do
|
23
|
+
patch emails_url, params: { current_password: "wrong_password", <%= singular_table_name %>: { email: @<%= singular_table_name %>.email } }
|
24
|
+
end
|
25
|
+
|
26
|
+
assert_redirected_to edit_emails_path
|
27
|
+
assert_equal "The current password you entered is incorrect", flash[:alert]
|
28
|
+
end
|
29
|
+
|
30
|
+
def sign_in_as(<%= singular_table_name %>)
|
31
|
+
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "secret123" }); user
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class PasswordResetsControllerTest < ActionDispatch::IntegrationTest
|
4
|
+
setup do
|
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)
|
8
|
+
end
|
9
|
+
|
10
|
+
test "should get new" do
|
11
|
+
get new_password_resets_url
|
12
|
+
assert_response :success
|
13
|
+
end
|
14
|
+
|
15
|
+
test "should get edit" do
|
16
|
+
get edit_password_resets_url(token: @sid)
|
17
|
+
assert_response :success
|
18
|
+
end
|
19
|
+
|
20
|
+
test "should send a password reset email" do
|
21
|
+
assert_enqueued_email_with PasswordMailer, :reset, args: { <%= singular_table_name %>: @<%= singular_table_name %> } do
|
22
|
+
post password_resets_url, params: { email: @<%= singular_table_name %>.email }
|
23
|
+
end
|
24
|
+
|
25
|
+
assert_redirected_to sign_in_path
|
26
|
+
end
|
27
|
+
|
28
|
+
test "should not send a password reset email to a nonexistent email" do
|
29
|
+
assert_no_enqueued_emails do
|
30
|
+
post password_resets_url, params: { email: "invalid_email@hey.com" }
|
31
|
+
end
|
32
|
+
|
33
|
+
assert_redirected_to new_password_resets_url(email_hint: "invalid_email@hey.com")
|
34
|
+
assert_equal "The email address doesn't exist in our database", flash[:alert]
|
35
|
+
end
|
36
|
+
|
37
|
+
test "should update password" do
|
38
|
+
patch password_resets_url, params: { token: @sid, <%= singular_table_name %>: { password: "new_password", password_confirmation: "new_password" } }
|
39
|
+
|
40
|
+
assert_redirected_to sign_in_path
|
41
|
+
end
|
42
|
+
|
43
|
+
test "should not update password with expired token" do
|
44
|
+
patch password_resets_url, params: { token: @sid_exp, password: "new_password", password_confirmation: "new_password" }
|
45
|
+
|
46
|
+
assert_redirected_to new_password_resets_path
|
47
|
+
assert_equal "Your token has expired, please request a new one", flash[:alert]
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class PasswordsControllerTest < ActionDispatch::IntegrationTest
|
4
|
+
setup do
|
5
|
+
@<%= singular_table_name %> = sign_in_as(<%= table_name %>(:lazaro_nixon))
|
6
|
+
end
|
7
|
+
|
8
|
+
test "should get edit" do
|
9
|
+
get edit_passwords_url
|
10
|
+
assert_response :success
|
11
|
+
end
|
12
|
+
|
13
|
+
test "should update password" do
|
14
|
+
assert_enqueued_email_with PasswordMailer, :changed, args: { <%= singular_table_name %>: @<%= singular_table_name %> } do
|
15
|
+
patch passwords_url, params: { current_password: "secret123", <%= singular_table_name %>: { password: "new_password", password_confirmation: "new_password" } }
|
16
|
+
end
|
17
|
+
|
18
|
+
assert_redirected_to root_path
|
19
|
+
end
|
20
|
+
|
21
|
+
test "should not update password with wrong current password" do
|
22
|
+
assert_no_enqueued_emails do
|
23
|
+
patch passwords_url, params: { current_password: "wrong_password", <%= singular_table_name %>: { password: "new_password", password_confirmation: "new_password" } }
|
24
|
+
end
|
25
|
+
|
26
|
+
assert_redirected_to edit_passwords_path
|
27
|
+
assert_equal "The current password you entered is incorrect", flash[:alert]
|
28
|
+
end
|
29
|
+
|
30
|
+
def sign_in_as(<%= singular_table_name %>)
|
31
|
+
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "secret123" }); user
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class RegistrationsControllerTest < ActionDispatch::IntegrationTest
|
4
|
+
test "should get new" do
|
5
|
+
get sign_up_url
|
6
|
+
assert_response :success
|
7
|
+
end
|
8
|
+
|
9
|
+
test "should sign up" do
|
10
|
+
assert_difference("<%= class_name %>.count") do
|
11
|
+
post sign_up_url, params: { <%= singular_table_name %>: { email: "lazaronixon@hey.com", password: "secret123", password_confirmation: "secret123" } }
|
12
|
+
end
|
13
|
+
assert_redirected_to root_url
|
14
|
+
|
15
|
+
follow_redirect!
|
16
|
+
assert_response :success
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class SessionsControllerTest < ActionDispatch::IntegrationTest
|
4
|
+
setup do
|
5
|
+
@<%= singular_table_name %> = <%= table_name %>(:lazaro_nixon)
|
6
|
+
end
|
7
|
+
|
8
|
+
test "should get new" do
|
9
|
+
get sign_in_url
|
10
|
+
assert_response :success
|
11
|
+
end
|
12
|
+
|
13
|
+
test "should sign in" do
|
14
|
+
post sign_in_url, params: { email: @<%= singular_table_name %>.email, password: "secret123" }
|
15
|
+
assert_redirected_to root_url
|
16
|
+
|
17
|
+
get root_url
|
18
|
+
assert_response :success
|
19
|
+
end
|
20
|
+
|
21
|
+
test "should not sign in with wrong credentials" do
|
22
|
+
post sign_in_url, params: { email: @<%= singular_table_name %>.email, password: "wrong_password" }
|
23
|
+
assert_redirected_to sign_in_url(email_hint: @<%= singular_table_name %>.email)
|
24
|
+
assert_equal "Invalid email or password", flash[:alert]
|
25
|
+
|
26
|
+
get root_url
|
27
|
+
assert_redirected_to sign_in_path
|
28
|
+
assert_equal "You need to sign in or sign up before continuing", flash[:alert]
|
29
|
+
end
|
30
|
+
|
31
|
+
test "should sign out" do
|
32
|
+
sign_in_as @<%= singular_table_name %>
|
33
|
+
|
34
|
+
delete sign_out_url
|
35
|
+
assert_redirected_to sign_in_path
|
36
|
+
|
37
|
+
get root_path
|
38
|
+
assert_redirected_to sign_in_path
|
39
|
+
assert_equal "You need to sign in or sign up before continuing", flash[:alert]
|
40
|
+
end
|
41
|
+
|
42
|
+
def sign_in_as(<%= singular_table_name %>)
|
43
|
+
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "secret123" }); user
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "application_system_test_case"
|
2
|
+
|
3
|
+
class CancellationsTest < ApplicationSystemTestCase
|
4
|
+
setup do
|
5
|
+
@<%= singular_table_name %> = sign_in_as(<%= table_name %>(:lazaro_nixon))
|
6
|
+
end
|
7
|
+
|
8
|
+
test "cancelling my account" do
|
9
|
+
click_on "Cancel my account & delete my data"
|
10
|
+
click_on "OK, close my account"
|
11
|
+
|
12
|
+
assert_text "Bye! Your account has been successfully cancelled"
|
13
|
+
end
|
14
|
+
|
15
|
+
def sign_in_as(<%= singular_table_name %>)
|
16
|
+
visit sign_in_url
|
17
|
+
fill_in :email, with: <%= singular_table_name %>.email
|
18
|
+
fill_in :password, with: "secret123"
|
19
|
+
click_on "Sign in"
|
20
|
+
|
21
|
+
return <%= singular_table_name %>
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "application_system_test_case"
|
2
|
+
|
3
|
+
class EmailsTest < ApplicationSystemTestCase
|
4
|
+
setup do
|
5
|
+
@<%= singular_table_name %> = sign_in_as(<%= table_name %>(:lazaro_nixon))
|
6
|
+
end
|
7
|
+
|
8
|
+
test "updating the email" do
|
9
|
+
click_on "Change email"
|
10
|
+
|
11
|
+
fill_in "Current password", with: "secret123"
|
12
|
+
fill_in "New email", with: "new_email@hey.com"
|
13
|
+
click_on "Save changes"
|
14
|
+
|
15
|
+
assert_text "Your email has been changed successfully"
|
16
|
+
end
|
17
|
+
|
18
|
+
def sign_in_as(<%= singular_table_name %>)
|
19
|
+
visit sign_in_url
|
20
|
+
fill_in :email, with: <%= singular_table_name %>.email
|
21
|
+
fill_in :password, with: "secret123"
|
22
|
+
click_on "Sign in"
|
23
|
+
|
24
|
+
return <%= singular_table_name %>
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "application_system_test_case"
|
2
|
+
|
3
|
+
class PasswordResetsTest < ApplicationSystemTestCase
|
4
|
+
setup do
|
5
|
+
@<%= singular_table_name %> = <%= table_name %>(:lazaro_nixon)
|
6
|
+
@sid = @<%= singular_table_name %>.signed_id(purpose: :password_reset, expires_in: 20.minutes)
|
7
|
+
end
|
8
|
+
|
9
|
+
test "sending a password reset email" do
|
10
|
+
visit sign_in_url
|
11
|
+
click_on "Forgot your password?"
|
12
|
+
|
13
|
+
fill_in "Email", with: @<%= singular_table_name %>.email
|
14
|
+
click_on "Send password reset email"
|
15
|
+
|
16
|
+
assert_text "You will receive an email with instructions on how to reset your password in a few minutes"
|
17
|
+
end
|
18
|
+
|
19
|
+
test "updating password" do
|
20
|
+
visit edit_password_resets_url(token: @sid)
|
21
|
+
|
22
|
+
fill_in "New password", with: "new_password"
|
23
|
+
fill_in "Confirm new password", with: "new_password"
|
24
|
+
click_on "Save changes"
|
25
|
+
|
26
|
+
assert_text "Your password was reset successfully. Please sign in"
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "application_system_test_case"
|
2
|
+
|
3
|
+
class PasswordsTest < ApplicationSystemTestCase
|
4
|
+
setup do
|
5
|
+
@<%= singular_table_name %> = sign_in_as(<%= table_name %>(:lazaro_nixon))
|
6
|
+
end
|
7
|
+
|
8
|
+
test "updating the password" do
|
9
|
+
click_on "Change password"
|
10
|
+
|
11
|
+
fill_in "Current password", with: "secret123"
|
12
|
+
fill_in "New password", with: "new_password"
|
13
|
+
fill_in "Confirm new password", with: "new_password"
|
14
|
+
click_on "Save changes"
|
15
|
+
|
16
|
+
assert_text "Your password has been changed successfully"
|
17
|
+
end
|
18
|
+
|
19
|
+
def sign_in_as(<%= singular_table_name %>)
|
20
|
+
visit sign_in_url
|
21
|
+
fill_in :email, with: <%= singular_table_name %>.email
|
22
|
+
fill_in :password, with: "secret123"
|
23
|
+
click_on "Sign in"
|
24
|
+
|
25
|
+
return <%= singular_table_name %>
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "application_system_test_case"
|
2
|
+
|
3
|
+
class RegistrationsTest < ApplicationSystemTestCase
|
4
|
+
test "signing up" do
|
5
|
+
visit sign_in_url
|
6
|
+
click_on "Sign up"
|
7
|
+
|
8
|
+
fill_in "Email", with: "lazaronixon@hey.com"
|
9
|
+
fill_in "Password", with: "new_password"
|
10
|
+
fill_in "Password confirmation", with: "new_password"
|
11
|
+
click_on "Sign up"
|
12
|
+
|
13
|
+
assert_text "Welcome! You have signed up successfully"
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "application_system_test_case"
|
2
|
+
|
3
|
+
class SessionsTest < ApplicationSystemTestCase
|
4
|
+
setup do
|
5
|
+
@<%= singular_table_name %> = <%= table_name %>(:lazaro_nixon)
|
6
|
+
end
|
7
|
+
|
8
|
+
test "signing in" do
|
9
|
+
visit sign_in_url
|
10
|
+
fill_in "Email", with: @<%= singular_table_name %>.email
|
11
|
+
fill_in "Password", with: "secret123"
|
12
|
+
click_on "Sign in"
|
13
|
+
|
14
|
+
assert_text "Signed in successfully"
|
15
|
+
end
|
16
|
+
|
17
|
+
test "signing out" do
|
18
|
+
sign_in_as @<%= singular_table_name %>
|
19
|
+
|
20
|
+
click_on "Log out"
|
21
|
+
assert_text "Signed out successfully"
|
22
|
+
end
|
23
|
+
|
24
|
+
def sign_in_as(<%= singular_table_name %>)
|
25
|
+
visit sign_in_url
|
26
|
+
fill_in :email, with: <%= singular_table_name %>.email
|
27
|
+
fill_in :password, with: "secret123"
|
28
|
+
click_on "Sign in"
|
29
|
+
|
30
|
+
return <%= singular_table_name %>
|
31
|
+
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authentication-zero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nixon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -43,24 +43,42 @@ files:
|
|
43
43
|
- lib/generators/authentication/templates/controllers/html/passwords_controller.rb.tt
|
44
44
|
- lib/generators/authentication/templates/controllers/html/registrations_controller.rb.tt
|
45
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
|
46
59
|
- lib/generators/authentication/templates/mailers/email_mailer.rb.tt
|
47
60
|
- lib/generators/authentication/templates/mailers/password_mailer.rb.tt
|
48
|
-
- lib/generators/authentication/templates/migration.rb.tt
|
49
61
|
- lib/generators/authentication/templates/models/current.rb.tt
|
50
|
-
- lib/generators/authentication/templates/models/
|
51
|
-
- lib/generators/authentication/templates/
|
52
|
-
- lib/generators/authentication/templates/
|
53
|
-
- lib/generators/authentication/templates/
|
54
|
-
- lib/generators/authentication/templates/
|
55
|
-
- lib/generators/authentication/templates/
|
56
|
-
- lib/generators/authentication/templates/
|
57
|
-
- lib/generators/authentication/templates/
|
58
|
-
- lib/generators/authentication/templates/
|
59
|
-
- lib/generators/authentication/templates/
|
60
|
-
- lib/generators/authentication/templates/
|
61
|
-
- lib/generators/authentication/templates/
|
62
|
-
- lib/generators/authentication/templates/
|
63
|
-
- lib/generators/authentication/templates/
|
62
|
+
- lib/generators/authentication/templates/models/model.rb.tt
|
63
|
+
- lib/generators/authentication/templates/test_unit/controllers/api/cancellations_controller_test.rb.tt
|
64
|
+
- lib/generators/authentication/templates/test_unit/controllers/api/emails_controller_test.rb.tt
|
65
|
+
- lib/generators/authentication/templates/test_unit/controllers/api/password_resets_controller_test.rb.tt
|
66
|
+
- lib/generators/authentication/templates/test_unit/controllers/api/passwords_controller_test.rb.tt
|
67
|
+
- lib/generators/authentication/templates/test_unit/controllers/api/registrations_controller_test.rb.tt
|
68
|
+
- lib/generators/authentication/templates/test_unit/controllers/api/sessions_controller_test.rb.tt
|
69
|
+
- lib/generators/authentication/templates/test_unit/controllers/html/cancellations_controller_test.rb.tt
|
70
|
+
- lib/generators/authentication/templates/test_unit/controllers/html/emails_controller_test.rb.tt
|
71
|
+
- lib/generators/authentication/templates/test_unit/controllers/html/password_resets_controller_test.rb.tt
|
72
|
+
- lib/generators/authentication/templates/test_unit/controllers/html/passwords_controller_test.rb.tt
|
73
|
+
- lib/generators/authentication/templates/test_unit/controllers/html/registrations_controller_test.rb.tt
|
74
|
+
- lib/generators/authentication/templates/test_unit/controllers/html/sessions_controller_test.rb.tt
|
75
|
+
- lib/generators/authentication/templates/test_unit/fixtures.yml.tt
|
76
|
+
- lib/generators/authentication/templates/test_unit/system/cancellations_test.rb.tt
|
77
|
+
- lib/generators/authentication/templates/test_unit/system/emails_test.rb.tt
|
78
|
+
- lib/generators/authentication/templates/test_unit/system/password_resets_test.rb.tt
|
79
|
+
- lib/generators/authentication/templates/test_unit/system/passwords_test.rb.tt
|
80
|
+
- lib/generators/authentication/templates/test_unit/system/registrations_test.rb.tt
|
81
|
+
- lib/generators/authentication/templates/test_unit/system/sessions_test.rb.tt
|
64
82
|
homepage: https://github.com/lazaronixon/authentication-zero
|
65
83
|
licenses:
|
66
84
|
- MIT
|
@@ -1,14 +0,0 @@
|
|
1
|
-
class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
|
2
|
-
def change
|
3
|
-
create_table :<%= table_name %> do |t|
|
4
|
-
t.string :email, null: false
|
5
|
-
t.string :password_digest, null: false
|
6
|
-
t.string :session_token, null: false
|
7
|
-
|
8
|
-
t.timestamps
|
9
|
-
end
|
10
|
-
|
11
|
-
add_index :<%= table_name %>, :email, unique: true
|
12
|
-
add_index :<%= table_name %>, :session_token, unique: true
|
13
|
-
end
|
14
|
-
end
|