authentication-zero 2.2.3 → 2.2.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b27407c78924deb810f7fbfce18aee02eece09440bd24f4820a4533cb7117155
4
- data.tar.gz: 26f8c2e4cd81245f09b5b72c7f2bae9293f2ce9e6d459ca93346fb87c10f20ad
3
+ metadata.gz: 8f18ce45e177a0e4b7cdb47f22456d5516909dc516002ad33416474f7582a39b
4
+ data.tar.gz: 18352b1de767047836853252e9a2832c84e6329002887724157a4dddb1d02f47
5
5
  SHA512:
6
- metadata.gz: dce2fef3a2d068f362ea47d2dee94d86627e80503a002d15ebe7beec21d178b0cceef74b6fddfe954388281aab4a4f6797997bdc542ca5f31c713c6e78cfc52d
7
- data.tar.gz: fd70bc3d6585b769d3ba044fbe36a9f49e6a0954ce56b9cc5032f558cd6420992aef2d8a4ddb9d4bd719d5909031e58ebcf192f20b9c1e124af5a5abb4fb1dae
6
+ metadata.gz: 30be7c743f859f755d32a076ff1748c33f0803d53b3368a6e7914c756e7b5a8183864d07866b15d3b07e2e0ad77bfcd174386090ebe941e1eeee1e269ab57412
7
+ data.tar.gz: 0b07f046c9ccfa17c4ad51fac9c4d4e59807c17f3f190acefc0d73168b32bb4b2112bdbcd14df75d402aa65b78f6c42edd68e18c55f0df39c5f1d4f2ffc7f67a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- authentication-zero (2.2.3)
4
+ authentication-zero (2.2.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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 is changed
16
- - Send e-mail when someone has signed-in into your account
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
@@ -1,3 +1,3 @@
1
1
  module AuthenticationZero
2
- VERSION = "2.2.3"
2
+ VERSION = "2.2.6"
3
3
  end
@@ -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
 
@@ -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: "verify_#{params[:email]}")
15
- rescue ActiveSupport::MessageVerifier::InvalidSignature
14
+ @<%= singular_table_name %> = <%= class_name %>.where(email: params[:email]).find_signed!(params[:token], purpose: params[:email])
15
+ rescue ActiveSupport::MessageVerifier::InvalidSignature, ActiveRecord::RecordNotFound
16
16
  render json: { error: "That email verification link is invalid" }, status: :bad_request
17
17
  end
18
18
  end
@@ -1,5 +1,5 @@
1
1
  class EmailVerificationsController < ApplicationController
2
- before_action :set_<%= singular_table_name %>, only: :edit
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: "verify_#{params[:email]}")
17
- rescue ActiveSupport::MessageVerifier::InvalidSignature
16
+ @<%= singular_table_name %> = <%= class_name %>.where(email: params[:email]).find_signed!(params[:token], purpose: params[:email])
17
+ rescue ActiveSupport::MessageVerifier::InvalidSignature, ActiveRecord::RecordNotFound
18
18
  redirect_to edit_email_path, alert: "That email verification link is invalid"
19
19
  end
20
20
  end
@@ -1,6 +1,6 @@
1
1
  <p style="color: green"><%%= notice %></p>
2
2
 
3
- <h1>Sessions</h1>
3
+ <h1>Devices & Sessions</h1>
4
4
 
5
5
  <div id="sessions">
6
6
  <%% @sessions.each do |session| %>
@@ -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: "verify_#{@<%= singular_table_name %>.email}", expires_in: 20.minutes)
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
@@ -2,7 +2,6 @@ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Mi
2
2
  def change
3
3
  create_table :sessions do |t|
4
4
  t.references :<%= singular_table_name %>, null: false, foreign_key: true
5
-
6
5
  t.string :user_agent
7
6
  t.string :ip_address
8
7
 
@@ -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: "verify_#{@<%= singular_table_name %>.email}", expires_in: 20.minutes)
7
- @sid_exp = @<%= singular_table_name %>.signed_id(purpose: "verify_#{@<%= singular_table_name %>.email}", expires_in: 0.minutes)
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: "verify_#{@<%= singular_table_name %>.email}", expires_in: 20.minutes)
7
- @sid_exp = @<%= singular_table_name %>.signed_id(purpose: "verify_#{@<%= singular_table_name %>.email}", expires_in: 0.minutes)
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.3
4
+ version: 2.2.6
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
@@ -1,6 +0,0 @@
1
- # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
-
3
- lazaro_nixon_ios:
4
- <%= singular_table_name %>: lazaro_nixon
5
- user_agent: Device iOS
6
- ip_address: 127.0.0.1