authentication-zero 2.2.7 → 2.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (18) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/lib/authentication_zero/version.rb +1 -1
  4. data/lib/generators/authentication/authentication_generator.rb +1 -1
  5. data/lib/generators/authentication/templates/controllers/api/email_verifications_controller.rb.tt +5 -5
  6. data/lib/generators/authentication/templates/controllers/api/emails_controller.rb.tt +8 -3
  7. data/lib/generators/authentication/templates/controllers/api/passwords_controller.rb.tt +8 -3
  8. data/lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt +1 -1
  9. data/lib/generators/authentication/templates/controllers/html/email_verifications_controller.rb.tt +1 -1
  10. data/lib/generators/authentication/templates/controllers/html/emails_controller.rb.tt +8 -3
  11. data/lib/generators/authentication/templates/controllers/html/passwords_controller.rb.tt +8 -3
  12. data/lib/generators/authentication/templates/controllers/html/sessions_controller.rb.tt +1 -1
  13. data/lib/generators/authentication/templates/test_unit/controllers/api/email_verifications_controller_test.rb.tt +4 -5
  14. data/lib/generators/authentication/templates/test_unit/controllers/api/emails_controller_test.rb.tt +1 -2
  15. data/lib/generators/authentication/templates/test_unit/controllers/api/passwords_controller_test.rb.tt +1 -2
  16. data/lib/generators/authentication/templates/test_unit/controllers/api/registrations_controller_test.rb.tt +1 -2
  17. data/lib/generators/authentication/templates/test_unit/controllers/api/sessions_controller_test.rb.tt +1 -2
  18. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 065a0e9195053ad906f495477bc12ffb7a299481f7ce1837389fe7123700b083
4
- data.tar.gz: df7baaa9cc9ca5100664ab40884a4c6df62c7e92dc4497e050deb1ad2e91dea2
3
+ metadata.gz: b36f33fad8ac0fd532efd29f0db68dc51bcac45a8fff39d53f914d7d3f4381e6
4
+ data.tar.gz: f44735476b0095bd9f4c5dd9db09c16b9e8bc7edf636d32372da2a974bfe249b
5
5
  SHA512:
6
- metadata.gz: b8506400f8d08c8bfdd0ecf43d25524deb75f23da5ea40dcfd8e9f8b983eded76219f4de68c0d8a31acbb58600992f1c1c6bd4f3da8e110c7985d276cfb7fa04
7
- data.tar.gz: bfb7f162e36c9e31fef121998dd8b00aefe298b265a2fa781326a6090be2f788824f7d9fe9066909f80fb8a28f2385b807efbbfa68f71dc192e9d09ebefcf47c
6
+ metadata.gz: 1fb6d2a12d39475fa1ced3b188230426ad18fc67bef7c6f560e1744bc73b17e45b676bf8b68c79129474004fbe9e47150c4fd82b36cdd78555772df03f398d8b
7
+ data.tar.gz: 0d1b0553b77a69ee1a67546c9d2e749abf47481cc2cf7355eda039777ade3ad14d95531ea640b694d698ccac7f7603fdf1d70faf2e1efac2ab59c79b90613e09
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- authentication-zero (2.2.7)
4
+ authentication-zero (2.2.8)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,3 +1,3 @@
1
1
  module AuthenticationZero
2
- VERSION = "2.2.7"
2
+ VERSION = "2.2.8"
3
3
  end
@@ -96,7 +96,7 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
96
96
  route "resource :registration, only: :destroy"
97
97
  route "resource :password_reset, only: [:new, :edit, :create, :update]"
98
98
  route "resource :password, only: [:edit, :update]"
99
- route "resource :email_verification, only: [:new, :edit, :create, :update]"
99
+ route "resource :email_verification, only: [:edit, :create]"
100
100
  route "resource :email, only: [:edit, :update]"
101
101
  route "resources :sessions, only: [:index, :show, :destroy]"
102
102
  route "post 'sign_up', to: 'registrations#create'"
@@ -1,12 +1,12 @@
1
1
  class EmailVerificationsController < ApplicationController
2
- before_action :set_<%= singular_table_name %>, only: :update
2
+ before_action :set_<%= singular_table_name %>, only: :edit
3
3
 
4
- def create
5
- IdentityMailer.with(<%= singular_table_name %>: Current.<%= singular_table_name %>).email_verify_confirmation.deliver_later
4
+ def edit
5
+ @<%= singular_table_name %>.update! verified: true
6
6
  end
7
7
 
8
- def update
9
- @<%= singular_table_name %>.update! verified: true
8
+ def create
9
+ IdentityMailer.with(<%= singular_table_name %>: Current.<%= singular_table_name %>).email_verify_confirmation.deliver_later
10
10
  end
11
11
 
12
12
  private
@@ -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 !@<%= singular_table_name %>.authenticate(params[:current_password])
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
@@ -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 !@<%= singular_table_name %>.authenticate(params[:current_password])
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 %>.try(:authenticate, params[:password])
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
 
@@ -1,5 +1,5 @@
1
1
  class EmailVerificationsController < ApplicationController
2
- before_action :set_<%= singular_table_name %>, only: %i[ edit update ]
2
+ before_action :set_<%= singular_table_name %>, only: :edit
3
3
 
4
4
  def edit
5
5
  @<%= singular_table_name %>.update! verified: true
@@ -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 !@<%= singular_table_name %>.authenticate(params[:current_password])
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
@@ -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 !@<%= singular_table_name %>.authenticate(params[:current_password])
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 %>.try(:authenticate, params[:password])
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
 
@@ -18,12 +18,12 @@ class EmailVerificationsControllerTest < ActionDispatch::IntegrationTest
18
18
  end
19
19
 
20
20
  test "should verify email" do
21
- patch email_verification_url, params: { token: @sid, email: @<%= singular_table_name %>.email }, headers: { "Authorization" => "Bearer #{@token}" }
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
- patch email_verification_url, params: { token: @sid_exp, email: @<%= singular_table_name %>.email }, headers: { "Authorization" => "Bearer #{@token}" }
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
- patch email_verification_url, params: { token: @sid, email: @<%= singular_table_name %>.email_previously_was }, headers: { "Authorization" => "Bearer #{@token}" }
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
@@ -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.7
4
+ version: 2.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nixon