Skip to content

Commit

Permalink
Use 422 status code for form submission error responses
Browse files Browse the repository at this point in the history
This is required by Turbo [1].
This will be the default in Rails 7 [2].

[1] hotwired/turbo#39
[2] rails/rails@2afc905
  • Loading branch information
airblade committed May 26, 2021
1 parent cb4516d commit f83c20b
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

## HEAD

* Use 422 status code for form submission error responses.
* Make default cookie name depend on Rails environment.


Expand Down
2 changes: 1 addition & 1 deletion app/controllers/quo_vadis/password_resets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def update
login @password.account.model, true
redirect_to qv.path_after_authentication, notice: QuoVadis.translate('flash.password_reset.reset')
else
render :edit
render :edit, status: :unprocessable_entity
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/quo_vadis/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def update
qv.replace_session
redirect_to qv.path_after_password_change, notice: QuoVadis.translate('flash.password.update')
else
render :edit
render :edit, status: :unprocessable_entity
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/quo_vadis/recovery_codes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def authenticate
else
qv.log account, Log::RECOVERY_CODE_FAILURE
flash.now[:alert] = QuoVadis.translate('flash.recovery_code.unverified')
render :challenge
render :challenge, status: :unprocessable_entity
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/quo_vadis/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ def create
unless account
qv.log nil, Log::LOGIN_UNKNOWN, identifier: QuoVadis.identifier_value_in_params(params)
flash.now[:alert] = QuoVadis.translate 'flash.login.failed'
render :new
render :new, status: :unprocessable_entity
return
end

unless account.password.authenticate params[:password]
qv.log account, Log::LOGIN_FAILURE
flash.now[:alert] = QuoVadis.translate 'flash.login.failed'
render :new
render :new, status: :unprocessable_entity
return
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/quo_vadis/totps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def authenticate
qv.log authenticated_model.qv_account, Log::TOTP_FAILURE
end
flash.now[:alert] = QuoVadis.translate('flash.totp.unverified')
render :challenge
render :challenge, status: :unprocessable_entity
end
end

Expand Down

0 comments on commit f83c20b

Please sign in to comment.