authentication-zero 2.15.0 → 2.15.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b086e42bab2e46a441d48eb06fc05594fd19295df27243089d21923fe590e115
4
- data.tar.gz: f67c8a55537acc984e41dca2b1671c75671b8eb0da735981e352689ac0e0c5e6
3
+ metadata.gz: 6fb0a9a6a553fede5d9554fed3c4d616b61e75c5e503fde621785003f0911fd4
4
+ data.tar.gz: 1f0d80023ec24a5b7395fe5e6b60efe3b437111f757205c98a569e66dcdbc0a3
5
5
  SHA512:
6
- metadata.gz: c65376ea0a5fc58acd2af6f4059f4ecfa6c95017c1c66bab97a9e83f3f37b02faee13a7dcde14a5bd2de3c43af5f0f71c28ff7740b026b45b8d4fd2eb6ca467c
7
- data.tar.gz: 74921b1b883f2d211579bca5c1d412f36cb2e7e9fc5a77699608d467ec93ba22235c5f4e8a0c1b10bf95ee240ea12b4e1f73cc66bc710977ab37d4daa85b900d
6
+ metadata.gz: 0e5041cf30bce8ebc6ad319c51b803d6af97055c59e4e7d74d56cb3abdb8d3555fce1b96f03b11cdfd7bb63022b20d50ae55774cbd84a921165f4bc2bb8b4c60
7
+ data.tar.gz: 8a26de6eedb1d793e3c58eb0f9f8d0289e1903e641ba538e30de3f43d6f8325e7386430808a56b857e6a9bb3bee261e731da2a180380d300165077a13d2be2f1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- authentication-zero (2.15.0)
4
+ authentication-zero (2.15.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -19,7 +19,7 @@ The purpose of authentication zero is to generate a pre-built authentication sys
19
19
  - Reset the user password and send reset instructions
20
20
  - Reset the user password only from verified emails
21
21
  - Lock sending reset password email after many attempts (--lockable)
22
- - Rate limiting for your app, 1000 reqs/hour (--ratelimit)
22
+ - Rate limiting for your app, 1000 reqs/minute (--ratelimit)
23
23
  - Send e-mail confirmation when your email has been changed
24
24
  - Send e-mail notification when someone has logged into your account
25
25
  - Manage multiple sessions & devices
@@ -1,3 +1,3 @@
1
1
  module AuthenticationZero
2
- VERSION = "2.15.0"
2
+ VERSION = "2.15.3"
3
3
  end
@@ -5,14 +5,8 @@ class Identity::EmailsController < ApplicationController
5
5
  before_action :set_user
6
6
 
7
7
  def update
8
- <%- unless options.sudoable? -%>
9
- if !@user.authenticate(params[:current_password])
10
- render json: { error: "The password you entered is incorrect" }, status: :bad_request
11
- elsif @user.update(user_params)
12
- <%- else -%>
13
8
  if @user.update(user_params)
14
- <%- end -%>
15
- render json: @user
9
+ render_show
16
10
  else
17
11
  render json: @user.errors, status: :unprocessable_entity
18
12
  end
@@ -26,4 +20,16 @@ class Identity::EmailsController < ApplicationController
26
20
  def user_params
27
21
  params.permit(:email)
28
22
  end
23
+
24
+ def render_show
25
+ if @user.email_previously_changed?
26
+ resend_email_verification; render(json: @user)
27
+ else
28
+ render json: @user
29
+ end
30
+ end
31
+
32
+ def resend_email_verification
33
+ UserMailer.with(user: @user).email_verification.deliver_later
34
+ end
29
35
  end
@@ -2,7 +2,7 @@ class Identity::PasswordResetsController < ApplicationController
2
2
  skip_before_action :authenticate
3
3
 
4
4
  before_action :set_user, only: :update
5
- <%- if options.lockable? %>
5
+ <%- if options.lockable? -%>
6
6
  before_action :require_lock, only: :create
7
7
  <%- end -%>
8
8
 
@@ -5,6 +5,7 @@ class RegistrationsController < ApplicationController
5
5
  @user = User.new(user_params)
6
6
 
7
7
  if @user.save
8
+ send_email_verification
8
9
  render json: @user, status: :created
9
10
  else
10
11
  render json: @user.errors, status: :unprocessable_entity
@@ -15,4 +16,8 @@ class RegistrationsController < ApplicationController
15
16
  def user_params
16
17
  params.permit(:email, :password, :password_confirmation)
17
18
  end
19
+
20
+ def send_email_verification
21
+ UserMailer.with(user: @user).email_verification.deliver_later
22
+ end
18
23
  end
@@ -8,14 +8,8 @@ class Identity::EmailsController < ApplicationController
8
8
  end
9
9
 
10
10
  def update
11
- <%- unless options.sudoable? -%>
12
- if !@user.authenticate(params[:current_password])
13
- redirect_to edit_identity_email_path, alert: "The password you entered is incorrect"
14
- elsif @user.update(user_params)
15
- <%- else -%>
16
11
  if @user.update(user_params)
17
- <%- end -%>
18
- redirect_to root_path, notice: "Your email has been changed"
12
+ redirect_to_root
19
13
  else
20
14
  render :edit, status: :unprocessable_entity
21
15
  end
@@ -29,4 +23,17 @@ class Identity::EmailsController < ApplicationController
29
23
  def user_params
30
24
  params.permit(:email)
31
25
  end
26
+
27
+ def redirect_to_root
28
+ if @user.email_previously_changed?
29
+ resend_email_verification
30
+ redirect_to root_path, notice: "Your email has been changed"
31
+ else
32
+ redirect_to root_path
33
+ end
34
+ end
35
+
36
+ def resend_email_verification
37
+ UserMailer.with(user: @user).email_verification.deliver_later
38
+ end
32
39
  end
@@ -2,7 +2,7 @@ class Identity::PasswordResetsController < ApplicationController
2
2
  skip_before_action :authenticate
3
3
 
4
4
  before_action :set_user, only: %i[ edit update ]
5
- <%- if options.lockable? %>
5
+ <%- if options.lockable? -%>
6
6
  before_action :require_lock, only: :create
7
7
  <%- end -%>
8
8
 
@@ -23,7 +23,7 @@ class Identity::PasswordResetsController < ApplicationController
23
23
 
24
24
  def update
25
25
  if @user.update(user_params)
26
- @token.destroy; redirect_to sign_in_path, notice: "Your password was reset successfully. Please sign in"
26
+ @token.destroy; redirect_to(sign_in_path, notice: "Your password was reset successfully. Please sign in")
27
27
  else
28
28
  render :edit, status: :unprocessable_entity
29
29
  end
@@ -12,6 +12,7 @@ class RegistrationsController < ApplicationController
12
12
  session = @user.sessions.create!
13
13
  cookies.signed.permanent[:session_token] = { value: session.id, httponly: true }
14
14
 
15
+ send_email_verification
15
16
  redirect_to root_path, notice: "Welcome! You have signed up successfully"
16
17
  else
17
18
  render :new, status: :unprocessable_entity
@@ -22,4 +23,8 @@ class RegistrationsController < ApplicationController
22
23
  def user_params
23
24
  params.permit(:email, :password, :password_confirmation)
24
25
  end
26
+
27
+ def send_email_verification
28
+ UserMailer.with(user: @user).email_verification.deliver_later
29
+ end
25
30
  end
@@ -10,13 +10,7 @@ class TwoFactorAuthentication::TotpsController < ApplicationController
10
10
  end
11
11
 
12
12
  def create
13
- <%- unless options.sudoable? -%>
14
- if !@user.authenticate(params[:current_password])
15
- redirect_to two_factor_authentication_totp_path, alert: "The password you entered is incorrect"
16
- elsif @totp.verify(params[:code], drift_behind: 15)
17
- <%- else -%>
18
13
  if @totp.verify(params[:code], drift_behind: 15)
19
- <%- end -%>
20
14
  @user.update! otp_secret: params[:secret]
21
15
  redirect_to root_path, notice: "2FA is enabled on your account"
22
16
  else
@@ -21,13 +21,6 @@
21
21
  </div>
22
22
  <%% end %>
23
23
 
24
- <%- unless options.sudoable? -%>
25
- <div>
26
- <%%= form.label :current_password, style: "display: block" %>
27
- <%%= form.password_field :current_password, required: true, autofocus: true, autocomplete: "current-password" %>
28
- </div>
29
- <%- end -%>
30
-
31
24
  <div>
32
25
  <%%= form.label :email, "New email", style: "display: block" %>
33
26
  <%%= form.email_field :email %>
@@ -17,13 +17,6 @@
17
17
  <%%= form_with(url: two_factor_authentication_totp_path) do |form| %>
18
18
  <%%= form.hidden_field :secret, value: @totp.secret %>
19
19
 
20
- <%- unless options.sudoable? -%>
21
- <div>
22
- <%%= form.label :current_password, style: "display: block" %>
23
- <%%= form.password_field :current_password, required: true, autofocus: true, autocomplete: "current-password" %>
24
- </div>
25
- <%- end -%>
26
-
27
20
  <div>
28
21
  <%%= form.label :code, "After scanning with your camera, the app will generate a six-digit code. Enter it here:", style: "display: block" %>
29
22
  <%%= form.text_field :code, autofocus: true, required: true, autocomplete: :off %>
@@ -30,11 +30,8 @@ class User < ApplicationRecord
30
30
  sessions.where.not(id: Current.session).destroy_all
31
31
  end
32
32
 
33
- after_save_commit if: :email_previously_changed? do
34
- UserMailer.with(user: self).email_verification.deliver_later
35
- end
36
33
  <%- if options.trackable? %>
37
- after_save_commit if: :email_previously_changed? do
34
+ after_update if: :email_previously_changed? do
38
35
  events.create! action: "email_verification_requested"
39
36
  end
40
37
 
@@ -10,14 +10,7 @@ class Identity::EmailsControllerTest < ActionDispatch::IntegrationTest
10
10
  end
11
11
 
12
12
  test "should update email" do
13
- patch identity_email_url, params: { email: "new_email@hey.com", current_password: "Secret1*3*5*" }, headers: default_headers
13
+ patch identity_email_url, params: { email: "new_email@hey.com" }, headers: default_headers
14
14
  assert_response :success
15
15
  end
16
-
17
- test "should not update email with wrong current password" do
18
- patch identity_email_url, params: { email: "new_email@hey.com", current_password: "SecretWrong1*3" }, headers: default_headers
19
-
20
- assert_response :bad_request
21
- assert_equal "The password you entered is incorrect", response.parsed_body["error"]
22
- end
23
16
  end
@@ -11,14 +11,7 @@ class Identity::EmailsControllerTest < ActionDispatch::IntegrationTest
11
11
  end
12
12
 
13
13
  test "should update email" do
14
- patch identity_email_url, params: { email: "new_email@hey.com", current_password: "Secret1*3*5*" }
14
+ patch identity_email_url, params: { email: "new_email@hey.com" }
15
15
  assert_redirected_to root_url
16
16
  end
17
-
18
- test "should not update email with wrong current password" do
19
- patch identity_email_url, params: { email: "new_email@hey.com", current_password: "SecretWrong1*3" }
20
-
21
- assert_redirected_to edit_identity_email_url
22
- assert_equal "The password you entered is incorrect", flash[:alert]
23
- end
24
17
  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.15.0
4
+ version: 2.15.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nixon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-03 00:00:00.000000000 Z
11
+ date: 2022-07-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: