authentication-zero 2.15.9 → 2.16.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/CI.yml +70 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +3 -56
- data/lib/authentication_zero/version.rb +1 -1
- data/lib/generators/authentication/authentication_generator.rb +11 -0
- data/lib/generators/authentication/templates/controllers/api/identity/email_verifications_controller.rb.tt +1 -1
- data/lib/generators/authentication/templates/controllers/html/home_controller.rb.tt +4 -0
- data/lib/generators/authentication/templates/erb/home/index.html.erb.tt +35 -0
- data/lib/generators/authentication/templates/models/user.rb.tt +2 -2
- data/lib/generators/authentication/templates/test_unit/application_system_test_case.rb.tt +1 -1
- data/lib/generators/authentication/templates/test_unit/mailers/session_mailer_test.rb.tt +13 -0
- data/lib/generators/authentication/templates/test_unit/mailers/user_mailer_test.rb.tt +19 -0
- metadata +8 -5
- data/lib/generators/authentication/templates/erb/session_mailer/signed_in_notification.text.erb.tt +0 -17
- data/lib/generators/authentication/templates/erb/user_mailer/email_verification.text.erb.tt +0 -13
- data/lib/generators/authentication/templates/erb/user_mailer/password_reset.text.erb.tt +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7dd52b852437d965454115d4fbb2d80f6b97f04dbe0d77e8a4524a4fb6052a89
|
4
|
+
data.tar.gz: 297f4bc57d8612d77c89eae113b558014f9b3b174eeebd13c2c6d73d78d7cad5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e43b09a82b8a63605a3c7ddb2d139890c5bd5153db25b8c5a535f570cf796a12f1e2520add1231bf72d95b4821871c0da72adc21e6a09b4597e5e9e65db9407f
|
7
|
+
data.tar.gz: d2d50163045d57ee8b87a0277b0f023d4d35d603637bc94bcae7c78f914afde8131ba725095627256fe93f77ca5484adb8b2247cf238b80bc3e57175db625b38
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub. They are
|
2
|
+
# provided by a third-party and are governed by separate terms of service,
|
3
|
+
# privacy policy, and support documentation.
|
4
|
+
#
|
5
|
+
# This workflow will install a prebuilt Ruby version, install dependencies, and
|
6
|
+
# run tests and linters.
|
7
|
+
name: "Generate sample app and run tests"
|
8
|
+
on:
|
9
|
+
push:
|
10
|
+
branches: ["master"]
|
11
|
+
pull_request:
|
12
|
+
branches: ["master"]
|
13
|
+
jobs:
|
14
|
+
test_html:
|
15
|
+
name: 🧪 Run HTML Tests
|
16
|
+
runs-on: ubuntu-latest
|
17
|
+
env:
|
18
|
+
RAILS_ENV: test
|
19
|
+
steps:
|
20
|
+
- name: Checkout code
|
21
|
+
uses: actions/checkout@v3
|
22
|
+
|
23
|
+
- name: Install Ruby and gems
|
24
|
+
uses: ruby/setup-ruby@v1
|
25
|
+
with:
|
26
|
+
bundler-cache: true
|
27
|
+
|
28
|
+
- name: Install the latest Rails gem
|
29
|
+
run: gem install rails
|
30
|
+
|
31
|
+
- name: Create fresh Rails app then run generator and tests
|
32
|
+
env:
|
33
|
+
CI: true
|
34
|
+
run: |
|
35
|
+
rails new test-app
|
36
|
+
cd test-app
|
37
|
+
bundle add authentication-zero --github ${{ github.repository }} --branch ${{ github.ref_name }}
|
38
|
+
bin/rails generate authentication
|
39
|
+
bundle install
|
40
|
+
bin/rails db:migrate
|
41
|
+
bin/rails test
|
42
|
+
bin/rails test:system
|
43
|
+
test_api:
|
44
|
+
name: 🧪 Run API Tests
|
45
|
+
runs-on: ubuntu-latest
|
46
|
+
env:
|
47
|
+
RAILS_ENV: test
|
48
|
+
steps:
|
49
|
+
- name: Checkout code
|
50
|
+
uses: actions/checkout@v3
|
51
|
+
|
52
|
+
- name: Install Ruby and gems
|
53
|
+
uses: ruby/setup-ruby@v1
|
54
|
+
with:
|
55
|
+
bundler-cache: true
|
56
|
+
|
57
|
+
- name: Install the latest Rails gem
|
58
|
+
run: gem install rails
|
59
|
+
|
60
|
+
- name: Create fresh Rails app then run generator and tests
|
61
|
+
env:
|
62
|
+
CI: true
|
63
|
+
run: |
|
64
|
+
rails new test-app --api
|
65
|
+
cd test-app
|
66
|
+
bundle add authentication-zero --github ${{ github.repository }} --branch ${{ github.ref_name }}
|
67
|
+
bin/rails generate authentication
|
68
|
+
bundle install
|
69
|
+
bin/rails db:migrate
|
70
|
+
bin/rails test
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.1.2
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -40,70 +40,17 @@ The purpose of authentication zero is to generate a pre-built authentication sys
|
|
40
40
|
|
41
41
|
## Installation
|
42
42
|
|
43
|
-
Add this lines to your application's Gemfile:
|
44
|
-
|
45
|
-
```ruby
|
46
|
-
gem "authentication-zero"
|
47
|
-
```
|
48
|
-
|
49
|
-
Then run `bundle install`
|
50
|
-
|
51
|
-
You'll need to set the root path in your routes.rb, for this example let's use the following:
|
52
|
-
|
53
|
-
```ruby
|
54
|
-
root "home#index"
|
55
|
-
```
|
56
|
-
|
57
|
-
```
|
58
|
-
rails generate controller home index
|
59
|
-
```
|
60
|
-
|
61
|
-
Add these lines to your `app/views/home/index.html.erb`:
|
62
|
-
|
63
|
-
```html+erb
|
64
|
-
<p style="color: green"><%= notice %></p>
|
65
|
-
|
66
|
-
<p>Signed as <%= Current.user.email %></p>
|
67
|
-
|
68
|
-
<div>
|
69
|
-
<%= link_to "Change email address", edit_identity_email_path %>
|
70
|
-
</div>
|
71
|
-
|
72
|
-
<div>
|
73
|
-
<%= link_to "Change password", edit_password_path %>
|
74
|
-
</div>
|
75
|
-
|
76
|
-
<div>
|
77
|
-
<%= link_to "Devices & Sessions", sessions_path %>
|
78
|
-
</div>
|
79
|
-
|
80
|
-
<div>
|
81
|
-
<%# link_to "Activity Log", authentications_events_path %>
|
82
|
-
</div>
|
83
|
-
|
84
|
-
<div>
|
85
|
-
<%# link_to "Two-Factor Authentication", new_two_factor_authentication_totp_path %>
|
86
|
-
</div>
|
87
|
-
|
88
|
-
<br>
|
89
|
-
|
90
|
-
<%= button_to "Log out", Current.session, method: :delete %>
|
91
43
|
```
|
92
|
-
|
93
|
-
And you'll need to set up the default URL options for the mailer in each environment. Here is a possible configuration for `config/environments/development.rb`:
|
94
|
-
|
95
|
-
```ruby
|
96
|
-
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
|
44
|
+
$ bundle add authentication-zero
|
97
45
|
```
|
98
46
|
|
99
47
|
## Usage
|
100
48
|
|
101
49
|
```
|
102
|
-
rails generate authentication
|
50
|
+
$ rails generate authentication
|
51
|
+
$ bundle install
|
103
52
|
```
|
104
53
|
|
105
|
-
Then run `bundle install` again!
|
106
|
-
|
107
54
|
## Development
|
108
55
|
|
109
56
|
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).
|
@@ -34,6 +34,11 @@ class AuthenticationGenerator < Rails::Generators::Base
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
def add_environment_configurations
|
38
|
+
application "config.action_mailer.default_url_options = { host: \"localhost\", port: 3000 }", env: "development"
|
39
|
+
application "config.action_mailer.default_url_options = { host: \"localhost\", port: 3000 }", env: "test"
|
40
|
+
end
|
41
|
+
|
37
42
|
def create_configuration_files
|
38
43
|
copy_file "config/redis/shared.yml", "config/redis/shared.yml" if redis?
|
39
44
|
copy_file "config/initializers/omniauth.rb", "config/initializers/omniauth.rb" if omniauthable?
|
@@ -68,6 +73,7 @@ class AuthenticationGenerator < Rails::Generators::Base
|
|
68
73
|
template "controllers/#{format_folder}/sessions_controller.rb", "app/controllers/sessions_controller.rb"
|
69
74
|
template "controllers/#{format_folder}/passwords_controller.rb", "app/controllers/passwords_controller.rb"
|
70
75
|
template "controllers/#{format_folder}/registrations_controller.rb", "app/controllers/registrations_controller.rb"
|
76
|
+
template "controllers/#{format_folder}/home_controller.rb", "app/controllers/home_controller.rb" unless options.api?
|
71
77
|
template "controllers/#{format_folder}/sessions/sudos_controller.rb", "app/controllers/sessions/sudos_controller.rb" if options.sudoable?
|
72
78
|
template "controllers/#{format_folder}/sessions/omniauth_controller.rb", "app/controllers/sessions/omniauth_controller.rb" if omniauthable?
|
73
79
|
template "controllers/#{format_folder}/authentications/events_controller.rb", "app/controllers/authentications/events_controller.rb" if options.trackable?
|
@@ -81,6 +87,8 @@ class AuthenticationGenerator < Rails::Generators::Base
|
|
81
87
|
directory "erb/user_mailer", "app/views/user_mailer"
|
82
88
|
directory "erb/session_mailer", "app/views/session_mailer"
|
83
89
|
|
90
|
+
directory "erb/home", "app/views/home"
|
91
|
+
|
84
92
|
directory "erb/identity", "app/views/identity"
|
85
93
|
directory "erb/passwords", "app/views/passwords"
|
86
94
|
directory "erb/registrations", "app/views/registrations"
|
@@ -100,6 +108,8 @@ class AuthenticationGenerator < Rails::Generators::Base
|
|
100
108
|
end
|
101
109
|
|
102
110
|
def add_routes
|
111
|
+
route "root 'home#index'" unless options.api?
|
112
|
+
|
103
113
|
if omniauthable?
|
104
114
|
route "post '/auth/:provider/callback', to: 'sessions/omniauth#create'"
|
105
115
|
route "get '/auth/:provider/callback', to: 'sessions/omniauth#create'"
|
@@ -129,6 +139,7 @@ class AuthenticationGenerator < Rails::Generators::Base
|
|
129
139
|
|
130
140
|
def create_test_files
|
131
141
|
directory "test_unit/controllers/#{format_folder}", "test/controllers"
|
142
|
+
directory "test_unit/mailers/", "test/mailers"
|
132
143
|
directory "test_unit/system", "test/system" unless options.api?
|
133
144
|
template "test_unit/test_helper.rb", "test/test_helper.rb", force: true
|
134
145
|
template "test_unit/application_system_test_case.rb", "test/application_system_test_case.rb", force: true unless options.api?
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<p style="color: green"><%%= notice %></p>
|
2
|
+
|
3
|
+
<%% if Current.user.present? %>
|
4
|
+
<p>Signed as <%%= Current.user.email %></p>
|
5
|
+
|
6
|
+
<div>
|
7
|
+
<%%= link_to "Change email address", edit_identity_email_path %>
|
8
|
+
</div>
|
9
|
+
|
10
|
+
<div>
|
11
|
+
<%%= link_to "Change password", edit_password_path %>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<div>
|
15
|
+
<%%= link_to "Devices & Sessions", sessions_path %>
|
16
|
+
</div>
|
17
|
+
|
18
|
+
<%- if options.trackable? -%>
|
19
|
+
<div>
|
20
|
+
<%# link_to "Activity Log", authentications_events_path %>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
<%- end -%>
|
24
|
+
<%- if two_factor? -%>
|
25
|
+
<div>
|
26
|
+
<%# link_to "Two-Factor Authentication", new_two_factor_authentication_totp_path %>
|
27
|
+
</div>
|
28
|
+
|
29
|
+
<%- end -%>
|
30
|
+
<br>
|
31
|
+
|
32
|
+
<%%= button_to "Log out", Current.session, method: :delete %>
|
33
|
+
<%% else %>
|
34
|
+
Please <%%= link_to "sign in", sign_in_path %> or <%%= link_to "sign up", sign_up_path %>.
|
35
|
+
<%% end %>
|
@@ -19,10 +19,10 @@ class User < ApplicationRecord
|
|
19
19
|
<%- end -%>
|
20
20
|
|
21
21
|
before_validation do
|
22
|
-
self.email = email
|
22
|
+
self.email = email&.downcase&.strip
|
23
23
|
end
|
24
24
|
|
25
|
-
before_validation if:
|
25
|
+
before_validation if: -> { email_changed? && persisted? } do
|
26
26
|
self.verified = false
|
27
27
|
end
|
28
28
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
3
|
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
4
|
-
driven_by :selenium, using: :
|
4
|
+
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]
|
5
5
|
|
6
6
|
def sign_in_as(user)
|
7
7
|
visit sign_in_url
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class SessionMailerTest < ActionMailer::TestCase
|
4
|
+
setup do
|
5
|
+
@session = users(:lazaro_nixon).sessions.create!
|
6
|
+
end
|
7
|
+
|
8
|
+
test "signed_in_notification" do
|
9
|
+
mail = SessionMailer.with(session: @session).signed_in_notification
|
10
|
+
assert_equal "New sign-in to your account", mail.subject
|
11
|
+
assert_equal [@session.user.email], mail.to
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class UserMailerTest < ActionMailer::TestCase
|
4
|
+
setup do
|
5
|
+
@user = users(:lazaro_nixon)
|
6
|
+
end
|
7
|
+
|
8
|
+
test "password_reset" do
|
9
|
+
mail = UserMailer.with(user: @user).password_reset
|
10
|
+
assert_equal "Reset your password", mail.subject
|
11
|
+
assert_equal [@user.email], mail.to
|
12
|
+
end
|
13
|
+
|
14
|
+
test "email_verification" do
|
15
|
+
mail = UserMailer.with(user: @user).email_verification
|
16
|
+
assert_equal "Verify your email", mail.subject
|
17
|
+
assert_equal [@user.email], mail.to
|
18
|
+
end
|
19
|
+
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: 2.
|
4
|
+
version: 2.16.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nixon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -18,8 +18,10 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- ".github/FUNDING.yml"
|
21
|
+
- ".github/workflows/CI.yml"
|
21
22
|
- ".gitignore"
|
22
23
|
- ".rubocop.yml"
|
24
|
+
- ".ruby-version"
|
23
25
|
- CHANGELOG.md
|
24
26
|
- CODE_OF_CONDUCT.md
|
25
27
|
- Gemfile
|
@@ -47,6 +49,7 @@ files:
|
|
47
49
|
- lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
|
48
50
|
- lib/generators/authentication/templates/controllers/html/application_controller.rb.tt
|
49
51
|
- lib/generators/authentication/templates/controllers/html/authentications/events_controller.rb.tt
|
52
|
+
- lib/generators/authentication/templates/controllers/html/home_controller.rb.tt
|
50
53
|
- lib/generators/authentication/templates/controllers/html/identity/email_verifications_controller.rb.tt
|
51
54
|
- lib/generators/authentication/templates/controllers/html/identity/emails_controller.rb.tt
|
52
55
|
- lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt
|
@@ -58,22 +61,20 @@ files:
|
|
58
61
|
- lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenges_controller.rb.tt
|
59
62
|
- lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
|
60
63
|
- lib/generators/authentication/templates/erb/authentications/events/index.html.erb.tt
|
64
|
+
- lib/generators/authentication/templates/erb/home/index.html.erb.tt
|
61
65
|
- lib/generators/authentication/templates/erb/identity/emails/edit.html.erb.tt
|
62
66
|
- lib/generators/authentication/templates/erb/identity/password_resets/edit.html.erb.tt
|
63
67
|
- lib/generators/authentication/templates/erb/identity/password_resets/new.html.erb.tt
|
64
68
|
- lib/generators/authentication/templates/erb/passwords/edit.html.erb.tt
|
65
69
|
- lib/generators/authentication/templates/erb/registrations/new.html.erb.tt
|
66
70
|
- lib/generators/authentication/templates/erb/session_mailer/signed_in_notification.html.erb.tt
|
67
|
-
- lib/generators/authentication/templates/erb/session_mailer/signed_in_notification.text.erb.tt
|
68
71
|
- lib/generators/authentication/templates/erb/sessions/index.html.erb.tt
|
69
72
|
- lib/generators/authentication/templates/erb/sessions/new.html.erb.tt
|
70
73
|
- lib/generators/authentication/templates/erb/sessions/sudos/new.html.erb.tt
|
71
74
|
- lib/generators/authentication/templates/erb/two_factor_authentication/challenges/new.html.erb.tt
|
72
75
|
- lib/generators/authentication/templates/erb/two_factor_authentication/totps/new.html.erb.tt
|
73
76
|
- lib/generators/authentication/templates/erb/user_mailer/email_verification.html.erb.tt
|
74
|
-
- lib/generators/authentication/templates/erb/user_mailer/email_verification.text.erb.tt
|
75
77
|
- lib/generators/authentication/templates/erb/user_mailer/password_reset.html.erb.tt
|
76
|
-
- lib/generators/authentication/templates/erb/user_mailer/password_reset.text.erb.tt
|
77
78
|
- lib/generators/authentication/templates/mailers/session_mailer.rb.tt
|
78
79
|
- lib/generators/authentication/templates/mailers/user_mailer.rb.tt
|
79
80
|
- lib/generators/authentication/templates/migrations/create_email_verification_tokens_migration.rb.tt
|
@@ -100,6 +101,8 @@ files:
|
|
100
101
|
- lib/generators/authentication/templates/test_unit/controllers/html/passwords_controller_test.rb.tt
|
101
102
|
- lib/generators/authentication/templates/test_unit/controllers/html/registrations_controller_test.rb.tt
|
102
103
|
- lib/generators/authentication/templates/test_unit/controllers/html/sessions_controller_test.rb.tt
|
104
|
+
- lib/generators/authentication/templates/test_unit/mailers/session_mailer_test.rb.tt
|
105
|
+
- lib/generators/authentication/templates/test_unit/mailers/user_mailer_test.rb.tt
|
103
106
|
- lib/generators/authentication/templates/test_unit/system/identity/emails_test.rb.tt
|
104
107
|
- lib/generators/authentication/templates/test_unit/system/identity/password_resets_test.rb.tt
|
105
108
|
- lib/generators/authentication/templates/test_unit/system/passwords_test.rb.tt
|
data/lib/generators/authentication/templates/erb/session_mailer/signed_in_notification.text.erb.tt
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
Hey there,
|
2
|
-
|
3
|
-
A new device just signed in to your account (<%%= @session.user.email %>).
|
4
|
-
|
5
|
-
<%%= @session.user_agent %>
|
6
|
-
|
7
|
-
<%%= @session.created_at %>
|
8
|
-
|
9
|
-
<%%= @session.ip_address %>
|
10
|
-
|
11
|
-
If this was you, carry on. We could notify you about sign-ins from this device again.
|
12
|
-
|
13
|
-
If you don't recognize this device, someone else may have accessed your account. You should immediately [change your password]<%%= new_identity_password_reset_url %>.
|
14
|
-
|
15
|
-
Tip: It's a good idea to periodically review all of the [devices and sessions]<%%= sessions_url %> in your account for suspicious activity.
|
16
|
-
|
17
|
-
<p>Have questions or need help? Just reply to this email and our support team will help you sort it out.
|
@@ -1,13 +0,0 @@
|
|
1
|
-
Hey there,
|
2
|
-
|
3
|
-
This is to confirm that <%%= @user.email %> is the email you want to use on your account. If you ever lose your password, that's where we'll email a reset link.
|
4
|
-
|
5
|
-
You must <%= code_verifiable? ? "put the code" : "hit the link" %> below to confirm that you received this email.
|
6
|
-
|
7
|
-
<%- if code_verifiable? -%>
|
8
|
-
<%%= @user.verification_code.value %>
|
9
|
-
<%- else -%>
|
10
|
-
[Yes, use this email for my account]<%%= edit_identity_email_verification_url(sid: @signed_id) %>
|
11
|
-
<%- end -%>
|
12
|
-
|
13
|
-
Have questions or need help? Just reply to this email and our support team will help you sort it out.
|
@@ -1,9 +0,0 @@
|
|
1
|
-
Hey there,
|
2
|
-
|
3
|
-
Can't remember your password for <%%= @user.email %>? That's OK, it happens. Just hit the link below to set a new one.
|
4
|
-
|
5
|
-
[Reset my password]<%%= edit_identity_password_reset_url(sid: @signed_id) %>
|
6
|
-
|
7
|
-
If you did not request a password reset you can safely ignore this email, it expires in 20 minutes. Only someone with access to this email account can reset your password.
|
8
|
-
|
9
|
-
Have questions or need help? Just reply to this email and our support team will help you sort it out.
|