Skip to content

Commit 167da79

Browse files
committed
Improve error handling in the Scalient::Rails::ProgressiveConfirmationsController#confirm action
1 parent d6b0146 commit 167da79

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

app/controllers/scalient/rails/progressive_confirmations_controller.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,23 @@ def confirm
106106
# it here to add an `:already_confirmed` error to be detected by downstream code.
107107
resource.send(:pending_any_confirmation) {}
108108

109-
# The record could already have errors from failed retrieval.
109+
# The record could have accumulated errors at this point.
110110
if resource.errors.empty?
111111
resource.update(
112112
resource_params.permit(:password, :password_confirmation).slice(:password, :password_confirmation),
113113
)
114114
end
115115

116+
# The record could have accumulated errors at this point.
117+
if resource.errors.empty?
118+
self.resource = resource_class.confirm_by_token(confirmation_token)
119+
end
120+
116121
yield resource if block_given?
117122

118-
# The record could have accumulated errors from saving.
123+
# The record could have accumulated errors from retrieval, setting the password, or confirming the token; or it
124+
# could already be confirmed.
119125
if resource.errors.empty?
120-
self.resource = resource_class.confirm_by_token(confirmation_token)
121126
set_flash_message!(:notice, :confirmed)
122127
sign_in(resource_name, resource)
123128

0 commit comments

Comments
 (0)