authentication-zero 2.2.4 → 2.2.7
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 +2 -2
- data/lib/authentication_zero/version.rb +1 -1
- data/lib/generators/authentication/authentication_generator.rb +0 -1
- data/lib/generators/authentication/templates/controllers/api/email_verifications_controller.rb.tt +2 -2
- data/lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt +1 -1
- data/lib/generators/authentication/templates/controllers/html/email_verifications_controller.rb.tt +3 -3
- data/lib/generators/authentication/templates/controllers/html/password_resets_controller.rb.tt +1 -1
- data/lib/generators/authentication/templates/mailers/identity_mailer.rb.tt +1 -1
- data/lib/generators/authentication/templates/migrations/create_sessions_migration.rb.tt +0 -1
- data/lib/generators/authentication/templates/models/model.rb.tt +4 -4
- data/lib/generators/authentication/templates/test_unit/controllers/api/email_verifications_controller_test.rb.tt +11 -2
- data/lib/generators/authentication/templates/test_unit/controllers/html/email_verifications_controller_test.rb.tt +11 -2
- metadata +1 -2
- data/lib/generators/authentication/templates/test_unit/sessions.yml.tt +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 065a0e9195053ad906f495477bc12ffb7a299481f7ce1837389fe7123700b083
|
4
|
+
data.tar.gz: df7baaa9cc9ca5100664ab40884a4c6df62c7e92dc4497e050deb1ad2e91dea2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8506400f8d08c8bfdd0ecf43d25524deb75f23da5ea40dcfd8e9f8b983eded76219f4de68c0d8a31acbb58600992f1c1c6bd4f3da8e110c7985d276cfb7fa04
|
7
|
+
data.tar.gz: bfb7f162e36c9e31fef121998dd8b00aefe298b265a2fa781326a6090be2f788824f7d9fe9066909f80fb8a28f2385b807efbbfa68f71dc192e9d09ebefcf47c
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -12,8 +12,8 @@ The purpose of authentication zero is to generate a pre-built authentication sys
|
|
12
12
|
- Reset the user password only from verified emails
|
13
13
|
- Authentication by cookie (html)
|
14
14
|
- Authentication by token (api)
|
15
|
-
- Send e-mail verification when your email
|
16
|
-
- Send
|
15
|
+
- Send e-mail verification when your email has been changed
|
16
|
+
- Send email when someone has logged into your account
|
17
17
|
- Manage multiple sessions & devices
|
18
18
|
- Cancel my account
|
19
19
|
- Log out
|
@@ -38,7 +38,6 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
|
|
38
38
|
def create_fixture_file
|
39
39
|
if options.fixture && options.fixture_replacement.nil?
|
40
40
|
template "#{test_framework}/fixtures.yml", "test/fixtures/#{fixture_file_name}.yml"
|
41
|
-
template "#{test_framework}/sessions.yml", "test/fixtures/sessions.yml"
|
42
41
|
end
|
43
42
|
end
|
44
43
|
|
data/lib/generators/authentication/templates/controllers/api/email_verifications_controller.rb.tt
CHANGED
@@ -11,8 +11,8 @@ class EmailVerificationsController < ApplicationController
|
|
11
11
|
|
12
12
|
private
|
13
13
|
def set_<%= singular_table_name %>
|
14
|
-
@<%= singular_table_name %> = <%= class_name %>.find_signed!(params[:token], purpose:
|
15
|
-
rescue
|
14
|
+
@<%= singular_table_name %> = <%= class_name %>.where(email: params[:email]).find_signed!(params[:token], purpose: params[:email])
|
15
|
+
rescue
|
16
16
|
render json: { error: "That email verification link is invalid" }, status: :bad_request
|
17
17
|
end
|
18
18
|
end
|
data/lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt
CHANGED
@@ -22,7 +22,7 @@ class PasswordResetsController < ApplicationController
|
|
22
22
|
private
|
23
23
|
def set_<%= singular_table_name %>
|
24
24
|
@<%= singular_table_name %> = <%= class_name %>.find_signed!(params[:token], purpose: :password_reset)
|
25
|
-
rescue
|
25
|
+
rescue
|
26
26
|
render json: { error: "That password reset link is invalid" }, status: :bad_request
|
27
27
|
end
|
28
28
|
|
data/lib/generators/authentication/templates/controllers/html/email_verifications_controller.rb.tt
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class EmailVerificationsController < ApplicationController
|
2
|
-
before_action :set_<%= singular_table_name %>, only:
|
2
|
+
before_action :set_<%= singular_table_name %>, only: %i[ edit update ]
|
3
3
|
|
4
4
|
def edit
|
5
5
|
@<%= singular_table_name %>.update! verified: true
|
@@ -13,8 +13,8 @@ class EmailVerificationsController < ApplicationController
|
|
13
13
|
|
14
14
|
private
|
15
15
|
def set_<%= singular_table_name %>
|
16
|
-
@<%= singular_table_name %> = <%= class_name %>.find_signed!(params[:token], purpose:
|
17
|
-
rescue
|
16
|
+
@<%= singular_table_name %> = <%= class_name %>.where(email: params[:email]).find_signed!(params[:token], purpose: params[:email])
|
17
|
+
rescue
|
18
18
|
redirect_to edit_email_path, alert: "That email verification link is invalid"
|
19
19
|
end
|
20
20
|
end
|
data/lib/generators/authentication/templates/controllers/html/password_resets_controller.rb.tt
CHANGED
@@ -29,7 +29,7 @@ class PasswordResetsController < ApplicationController
|
|
29
29
|
private
|
30
30
|
def set_<%= singular_table_name %>
|
31
31
|
@<%= singular_table_name %> = <%= class_name %>.find_signed!(params[:token], purpose: :password_reset)
|
32
|
-
rescue
|
32
|
+
rescue
|
33
33
|
redirect_to new_password_reset_path, alert: "That password reset link is invalid"
|
34
34
|
end
|
35
35
|
|
@@ -8,7 +8,7 @@ class IdentityMailer < ApplicationMailer
|
|
8
8
|
|
9
9
|
def email_verify_confirmation
|
10
10
|
@<%= singular_table_name %> = params[:<%= singular_table_name %>]
|
11
|
-
@signed_id = params[:<%= singular_table_name %>].signed_id(purpose:
|
11
|
+
@signed_id = params[:<%= singular_table_name %>].signed_id(purpose: @<%= singular_table_name %>.email, expires_in: 20.minutes)
|
12
12
|
|
13
13
|
mail to: @<%= singular_table_name %>.email, subject: "Verify your email"
|
14
14
|
end
|
@@ -11,12 +11,12 @@ class <%= class_name %> < ApplicationRecord
|
|
11
11
|
self.email = email.downcase.strip
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
before_validation if: :email_changed? do
|
15
|
+
self.verified = false
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
after_create_commit do
|
19
|
+
IdentityMailer.with(<%= singular_table_name %>: self).email_verify_confirmation.deliver_later
|
20
20
|
end
|
21
21
|
|
22
22
|
after_update_commit if: :email_previously_changed? do
|
@@ -3,8 +3,8 @@ require "test_helper"
|
|
3
3
|
class EmailVerificationsControllerTest < ActionDispatch::IntegrationTest
|
4
4
|
setup do
|
5
5
|
@<%= singular_table_name %>, @token = sign_in_as(<%= table_name %>(:lazaro_nixon))
|
6
|
-
@sid = @<%= singular_table_name %>.signed_id(purpose:
|
7
|
-
@sid_exp = @<%= singular_table_name %>.signed_id(purpose:
|
6
|
+
@sid = @<%= singular_table_name %>.signed_id(purpose: @<%= singular_table_name %>.email, expires_in: 20.minutes)
|
7
|
+
@sid_exp = @<%= singular_table_name %>.signed_id(purpose: @<%= singular_table_name %>.email, expires_in: 0.minutes)
|
8
8
|
|
9
9
|
@<%= singular_table_name %>.update! verified: false
|
10
10
|
end
|
@@ -29,6 +29,15 @@ class EmailVerificationsControllerTest < ActionDispatch::IntegrationTest
|
|
29
29
|
assert_equal "That email verification link is invalid", response.parsed_body["error"]
|
30
30
|
end
|
31
31
|
|
32
|
+
test "should not verify email with previous token" do
|
33
|
+
@<%= singular_table_name %>.update! email: "other_email@hey.com"
|
34
|
+
|
35
|
+
patch email_verification_url, params: { token: @sid, email: @<%= singular_table_name %>.email_previously_was }, headers: { "Authorization" => "Bearer #{@token}" }
|
36
|
+
|
37
|
+
assert_response :bad_request
|
38
|
+
assert_equal "That email verification link is invalid", response.parsed_body["error"]
|
39
|
+
end
|
40
|
+
|
32
41
|
def sign_in_as(<%= singular_table_name %>)
|
33
42
|
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "secret123" })
|
34
43
|
[<%= singular_table_name %>, response.headers["X-Session-Token"]]
|
@@ -3,8 +3,8 @@ require "test_helper"
|
|
3
3
|
class EmailVerificationsControllerTest < ActionDispatch::IntegrationTest
|
4
4
|
setup do
|
5
5
|
@<%= singular_table_name %> = sign_in_as(<%= table_name %>(:lazaro_nixon))
|
6
|
-
@sid = @<%= singular_table_name %>.signed_id(purpose:
|
7
|
-
@sid_exp = @<%= singular_table_name %>.signed_id(purpose:
|
6
|
+
@sid = @<%= singular_table_name %>.signed_id(purpose: @<%= singular_table_name %>.email, expires_in: 20.minutes)
|
7
|
+
@sid_exp = @<%= singular_table_name %>.signed_id(purpose: @<%= singular_table_name %>.email, expires_in: 0.minutes)
|
8
8
|
|
9
9
|
@<%= singular_table_name %>.update! verified: false
|
10
10
|
end
|
@@ -29,6 +29,15 @@ class EmailVerificationsControllerTest < ActionDispatch::IntegrationTest
|
|
29
29
|
assert_equal "That email verification link is invalid", flash[:alert]
|
30
30
|
end
|
31
31
|
|
32
|
+
test "should not verify email with previous token" do
|
33
|
+
@<%= singular_table_name %>.update! email: "other_email@hey.com"
|
34
|
+
|
35
|
+
get edit_email_verification_url(token: @sid, email: @<%= singular_table_name %>.email_previously_was)
|
36
|
+
|
37
|
+
assert_redirected_to edit_email_path
|
38
|
+
assert_equal "That email verification link is invalid", flash[:alert]
|
39
|
+
end
|
40
|
+
|
32
41
|
def sign_in_as(<%= singular_table_name %>)
|
33
42
|
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "secret123" }); <%= singular_table_name %>
|
34
43
|
end
|
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: 2.2.
|
4
|
+
version: 2.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nixon
|
@@ -76,7 +76,6 @@ files:
|
|
76
76
|
- lib/generators/authentication/templates/test_unit/controllers/html/registrations_controller_test.rb.tt
|
77
77
|
- lib/generators/authentication/templates/test_unit/controllers/html/sessions_controller_test.rb.tt
|
78
78
|
- lib/generators/authentication/templates/test_unit/fixtures.yml.tt
|
79
|
-
- lib/generators/authentication/templates/test_unit/sessions.yml.tt
|
80
79
|
- lib/generators/authentication/templates/test_unit/system/emails_test.rb.tt
|
81
80
|
- lib/generators/authentication/templates/test_unit/system/password_resets_test.rb.tt
|
82
81
|
- lib/generators/authentication/templates/test_unit/system/passwords_test.rb.tt
|