authentication-zero 2.2.5 → 2.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/authentication_zero/version.rb +1 -1
- data/lib/generators/authentication/authentication_generator.rb +1 -2
- data/lib/generators/authentication/templates/controllers/api/email_verifications_controller.rb.tt +7 -11
- data/lib/generators/authentication/templates/controllers/api/emails_controller.rb.tt +8 -3
- data/lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt +1 -1
- data/lib/generators/authentication/templates/controllers/api/passwords_controller.rb.tt +8 -3
- data/lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt +1 -1
- data/lib/generators/authentication/templates/controllers/html/email_verifications_controller.rb.tt +4 -8
- data/lib/generators/authentication/templates/controllers/html/emails_controller.rb.tt +8 -3
- data/lib/generators/authentication/templates/controllers/html/password_resets_controller.rb.tt +1 -1
- data/lib/generators/authentication/templates/controllers/html/passwords_controller.rb.tt +8 -3
- data/lib/generators/authentication/templates/controllers/html/sessions_controller.rb.tt +1 -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 +4 -5
- data/lib/generators/authentication/templates/test_unit/controllers/api/emails_controller_test.rb.tt +1 -2
- data/lib/generators/authentication/templates/test_unit/controllers/api/passwords_controller_test.rb.tt +1 -2
- data/lib/generators/authentication/templates/test_unit/controllers/api/registrations_controller_test.rb.tt +1 -2
- data/lib/generators/authentication/templates/test_unit/controllers/api/sessions_controller_test.rb.tt +1 -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: b36f33fad8ac0fd532efd29f0db68dc51bcac45a8fff39d53f914d7d3f4381e6
|
4
|
+
data.tar.gz: f44735476b0095bd9f4c5dd9db09c16b9e8bc7edf636d32372da2a974bfe249b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fb6d2a12d39475fa1ced3b188230426ad18fc67bef7c6f560e1744bc73b17e45b676bf8b68c79129474004fbe9e47150c4fd82b36cdd78555772df03f398d8b
|
7
|
+
data.tar.gz: 0d1b0553b77a69ee1a67546c9d2e749abf47481cc2cf7355eda039777ade3ad14d95531ea640b694d698ccac7f7603fdf1d70faf2e1efac2ab59c79b90613e09
|
data/Gemfile.lock
CHANGED
@@ -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
|
|
@@ -97,7 +96,7 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
|
|
97
96
|
route "resource :registration, only: :destroy"
|
98
97
|
route "resource :password_reset, only: [:new, :edit, :create, :update]"
|
99
98
|
route "resource :password, only: [:edit, :update]"
|
100
|
-
route "resource :email_verification, only: [:
|
99
|
+
route "resource :email_verification, only: [:edit, :create]"
|
101
100
|
route "resource :email, only: [:edit, :update]"
|
102
101
|
route "resources :sessions, only: [:index, :show, :destroy]"
|
103
102
|
route "post 'sign_up', to: 'registrations#create'"
|
data/lib/generators/authentication/templates/controllers/api/email_verifications_controller.rb.tt
CHANGED
@@ -1,22 +1,18 @@
|
|
1
1
|
class EmailVerificationsController < ApplicationController
|
2
|
-
before_action :set_<%= singular_table_name %>, only: :
|
2
|
+
before_action :set_<%= singular_table_name %>, only: :edit
|
3
3
|
|
4
|
-
def
|
5
|
-
|
4
|
+
def edit
|
5
|
+
@<%= singular_table_name %>.update! verified: true
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
9
|
-
|
10
|
-
@<%= singular_table_name %>.update! verified: true
|
11
|
-
else
|
12
|
-
render json: { error: "That email verification link is invalid" }, status: :bad_request
|
13
|
-
end
|
8
|
+
def create
|
9
|
+
IdentityMailer.with(<%= singular_table_name %>: Current.<%= singular_table_name %>).email_verify_confirmation.deliver_later
|
14
10
|
end
|
15
11
|
|
16
12
|
private
|
17
13
|
def set_<%= singular_table_name %>
|
18
|
-
@<%= singular_table_name %> = <%= class_name %>.find_signed!(params[:token], purpose: params[:email])
|
19
|
-
rescue
|
14
|
+
@<%= singular_table_name %> = <%= class_name %>.where(email: params[:email]).find_signed!(params[:token], purpose: params[:email])
|
15
|
+
rescue
|
20
16
|
render json: { error: "That email verification link is invalid" }, status: :bad_request
|
21
17
|
end
|
22
18
|
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
class EmailsController < ApplicationController
|
2
2
|
before_action :set_<%= singular_table_name %>
|
3
|
+
before_action :validate_current_password
|
3
4
|
|
4
5
|
def update
|
5
|
-
if
|
6
|
-
render json: { error: "The current password you entered is incorrect" }, status: :bad_request
|
7
|
-
elsif @<%= singular_table_name %>.update(<%= "#{singular_table_name}_params" %>)
|
6
|
+
if @<%= singular_table_name %>.update(<%= "#{singular_table_name}_params" %>)
|
8
7
|
render json: @<%= singular_table_name %>
|
9
8
|
else
|
10
9
|
render json: @<%= singular_table_name %>.errors, status: :unprocessable_entity
|
@@ -19,4 +18,10 @@ class EmailsController < ApplicationController
|
|
19
18
|
def <%= "#{singular_table_name}_params" %>
|
20
19
|
params.permit(:email)
|
21
20
|
end
|
21
|
+
|
22
|
+
def validate_current_password
|
23
|
+
unless @<%= singular_table_name %>.authenticate(params[:current_password])
|
24
|
+
render json: { error: "The current password you entered is incorrect" }, status: :bad_request
|
25
|
+
end
|
26
|
+
end
|
22
27
|
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
|
|
@@ -1,10 +1,9 @@
|
|
1
1
|
class PasswordsController < ApplicationController
|
2
2
|
before_action :set_<%= singular_table_name %>
|
3
|
+
before_action :validate_current_password
|
3
4
|
|
4
5
|
def update
|
5
|
-
if
|
6
|
-
render json: { error: "The current password you entered is incorrect" }, status: :bad_request
|
7
|
-
elsif @<%= singular_table_name %>.update(<%= "#{singular_table_name}_params" %>)
|
6
|
+
if @<%= singular_table_name %>.update(<%= "#{singular_table_name}_params" %>)
|
8
7
|
render json: @<%= singular_table_name %>
|
9
8
|
else
|
10
9
|
render json: @<%= singular_table_name %>.errors, status: :unprocessable_entity
|
@@ -19,4 +18,10 @@ class PasswordsController < ApplicationController
|
|
19
18
|
def <%= "#{singular_table_name}_params" %>
|
20
19
|
params.permit(:password, :password_confirmation)
|
21
20
|
end
|
21
|
+
|
22
|
+
def validate_current_password
|
23
|
+
unless @<%= singular_table_name %>.authenticate(params[:current_password])
|
24
|
+
render json: { error: "The current password you entered is incorrect" }, status: :bad_request
|
25
|
+
end
|
26
|
+
end
|
22
27
|
end
|
@@ -14,7 +14,7 @@ class SessionsController < ApplicationController
|
|
14
14
|
def create
|
15
15
|
@<%= singular_table_name %> = <%= class_name %>.find_by_email(params[:email])
|
16
16
|
|
17
|
-
if @<%= singular_table_name %>.
|
17
|
+
if @<%= singular_table_name %> && @<%= singular_table_name %>.authenticate(params[:password])
|
18
18
|
session = @<%= singular_table_name %>.sessions.create!(session_params)
|
19
19
|
response.set_header("X-Session-Token", session.signed_id)
|
20
20
|
|
data/lib/generators/authentication/templates/controllers/html/email_verifications_controller.rb.tt
CHANGED
@@ -2,12 +2,8 @@ class EmailVerificationsController < ApplicationController
|
|
2
2
|
before_action :set_<%= singular_table_name %>, only: :edit
|
3
3
|
|
4
4
|
def edit
|
5
|
-
|
6
|
-
|
7
|
-
redirect_to root_path, notice: "Thank you for verifying your email address"
|
8
|
-
else
|
9
|
-
redirect_to edit_email_path, alert: "That email verification link is invalid"
|
10
|
-
end
|
5
|
+
@<%= singular_table_name %>.update! verified: true
|
6
|
+
redirect_to root_path, notice: "Thank you for verifying your email address"
|
11
7
|
end
|
12
8
|
|
13
9
|
def create
|
@@ -17,8 +13,8 @@ class EmailVerificationsController < ApplicationController
|
|
17
13
|
|
18
14
|
private
|
19
15
|
def set_<%= singular_table_name %>
|
20
|
-
@<%= singular_table_name %> = <%= class_name %>.find_signed!(params[:token], purpose: params[:email])
|
21
|
-
rescue
|
16
|
+
@<%= singular_table_name %> = <%= class_name %>.where(email: params[:email]).find_signed!(params[:token], purpose: params[:email])
|
17
|
+
rescue
|
22
18
|
redirect_to edit_email_path, alert: "That email verification link is invalid"
|
23
19
|
end
|
24
20
|
end
|
@@ -1,13 +1,12 @@
|
|
1
1
|
class EmailsController < ApplicationController
|
2
2
|
before_action :set_<%= singular_table_name %>
|
3
|
+
before_action :validate_current_password, only: :update
|
3
4
|
|
4
5
|
def edit
|
5
6
|
end
|
6
7
|
|
7
8
|
def update
|
8
|
-
if
|
9
|
-
redirect_to edit_email_path, alert: "The current password you entered is incorrect"
|
10
|
-
elsif @<%= singular_table_name %>.update(<%= "#{singular_table_name}_params" %>)
|
9
|
+
if @<%= singular_table_name %>.update(<%= "#{singular_table_name}_params" %>)
|
11
10
|
redirect_to root_path, notice: "Your email has been changed"
|
12
11
|
else
|
13
12
|
render :edit, status: :unprocessable_entity
|
@@ -22,4 +21,10 @@ class EmailsController < ApplicationController
|
|
22
21
|
def <%= "#{singular_table_name}_params" %>
|
23
22
|
params.require(:<%= singular_table_name %>).permit(:email)
|
24
23
|
end
|
24
|
+
|
25
|
+
def validate_current_password
|
26
|
+
unless @<%= singular_table_name %>.authenticate(params[:current_password])
|
27
|
+
redirect_to edit_email_path, alert: "The current password you entered is incorrect"
|
28
|
+
end
|
29
|
+
end
|
25
30
|
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
|
|
@@ -1,13 +1,12 @@
|
|
1
1
|
class PasswordsController < ApplicationController
|
2
2
|
before_action :set_<%= singular_table_name %>
|
3
|
+
before_action :validate_current_password, only: :update
|
3
4
|
|
4
5
|
def edit
|
5
6
|
end
|
6
7
|
|
7
8
|
def update
|
8
|
-
if
|
9
|
-
redirect_to edit_password_path, alert: "The current password you entered is incorrect"
|
10
|
-
elsif @<%= singular_table_name %>.update(<%= "#{singular_table_name}_params" %>)
|
9
|
+
if @<%= singular_table_name %>.update(<%= "#{singular_table_name}_params" %>)
|
11
10
|
redirect_to root_path, notice: "Your password has been changed"
|
12
11
|
else
|
13
12
|
render :edit, status: :unprocessable_entity
|
@@ -22,4 +21,10 @@ class PasswordsController < ApplicationController
|
|
22
21
|
def <%= "#{singular_table_name}_params" %>
|
23
22
|
params.require(:<%= singular_table_name %>).permit(:password, :password_confirmation)
|
24
23
|
end
|
24
|
+
|
25
|
+
def validate_current_password
|
26
|
+
unless @<%= singular_table_name %>.authenticate(params[:current_password])
|
27
|
+
redirect_to edit_password_path, alert: "The current password you entered is incorrect"
|
28
|
+
end
|
29
|
+
end
|
25
30
|
end
|
@@ -14,7 +14,7 @@ class SessionsController < ApplicationController
|
|
14
14
|
def create
|
15
15
|
@<%= singular_table_name %> = <%= class_name %>.find_by_email(params[:email])
|
16
16
|
|
17
|
-
if @<%= singular_table_name %>.
|
17
|
+
if @<%= singular_table_name %> && @<%= singular_table_name %>.authenticate(params[:password])
|
18
18
|
session = @<%= singular_table_name %>.sessions.create!(session_params)
|
19
19
|
cookies.signed.permanent[:session_token] = { value: session.id, httponly: true }
|
20
20
|
|
@@ -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
|
@@ -18,12 +18,12 @@ class EmailVerificationsControllerTest < ActionDispatch::IntegrationTest
|
|
18
18
|
end
|
19
19
|
|
20
20
|
test "should verify email" do
|
21
|
-
|
21
|
+
get edit_email_verification_url, params: { token: @sid, email: @<%= singular_table_name %>.email }, headers: { "Authorization" => "Bearer #{@token}" }
|
22
22
|
assert_response :no_content
|
23
23
|
end
|
24
24
|
|
25
25
|
test "should not verify email with expired token" do
|
26
|
-
|
26
|
+
get edit_email_verification_url, params: { token: @sid_exp, email: @<%= singular_table_name %>.email }, headers: { "Authorization" => "Bearer #{@token}" }
|
27
27
|
|
28
28
|
assert_response :bad_request
|
29
29
|
assert_equal "That email verification link is invalid", response.parsed_body["error"]
|
@@ -32,14 +32,13 @@ class EmailVerificationsControllerTest < ActionDispatch::IntegrationTest
|
|
32
32
|
test "should not verify email with previous token" do
|
33
33
|
@<%= singular_table_name %>.update! email: "other_email@hey.com"
|
34
34
|
|
35
|
-
|
35
|
+
get edit_email_verification_url, params: { token: @sid, email: @<%= singular_table_name %>.email_previously_was }, headers: { "Authorization" => "Bearer #{@token}" }
|
36
36
|
|
37
37
|
assert_response :bad_request
|
38
38
|
assert_equal "That email verification link is invalid", response.parsed_body["error"]
|
39
39
|
end
|
40
40
|
|
41
41
|
def sign_in_as(<%= singular_table_name %>)
|
42
|
-
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "secret123" })
|
43
|
-
[<%= singular_table_name %>, response.headers["X-Session-Token"]]
|
42
|
+
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "secret123" }); [<%= singular_table_name %>, response.headers["X-Session-Token"]]
|
44
43
|
end
|
45
44
|
end
|
data/lib/generators/authentication/templates/test_unit/controllers/api/emails_controller_test.rb.tt
CHANGED
@@ -18,7 +18,6 @@ class EmailsControllerTest < ActionDispatch::IntegrationTest
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def sign_in_as(<%= singular_table_name %>)
|
21
|
-
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "secret123" })
|
22
|
-
[<%= singular_table_name %>, response.headers["X-Session-Token"]]
|
21
|
+
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "secret123" }); [<%= singular_table_name %>, response.headers["X-Session-Token"]]
|
23
22
|
end
|
24
23
|
end
|
@@ -18,7 +18,6 @@ class PasswordsControllerTest < ActionDispatch::IntegrationTest
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def sign_in_as(<%= singular_table_name %>)
|
21
|
-
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "secret123" })
|
22
|
-
[<%= singular_table_name %>, response.headers["X-Session-Token"]]
|
21
|
+
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "secret123" }); [<%= singular_table_name %>, response.headers["X-Session-Token"]]
|
23
22
|
end
|
24
23
|
end
|
@@ -20,7 +20,6 @@ class RegistrationsControllerTest < ActionDispatch::IntegrationTest
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def sign_in_as(<%= singular_table_name %>)
|
23
|
-
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "secret123" })
|
24
|
-
[<%= singular_table_name %>, response.headers["X-Session-Token"]]
|
23
|
+
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "secret123" }); [<%= singular_table_name %>, response.headers["X-Session-Token"]]
|
25
24
|
end
|
26
25
|
end
|
@@ -33,7 +33,6 @@ class SessionsControllerTest < ActionDispatch::IntegrationTest
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def sign_in_as(<%= singular_table_name %>)
|
36
|
-
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "secret123" })
|
37
|
-
[<%= singular_table_name %>, response.headers["X-Session-Token"]]
|
36
|
+
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "secret123" }); [<%= singular_table_name %>, response.headers["X-Session-Token"]]
|
38
37
|
end
|
39
38
|
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.8
|
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
|