412 Commits

Author SHA1 Message Date
Adan Amarillas
9a149ff139 Return 401 for sessions#destroy action with no user signed in (#4878)
It's an unauthenticated request, so return 401 Unauthorized like most
other similar requests.

Signed-off-by: Carlos Antonio da Silva <carlosantoniodasilva@gmail.com>
2025-12-31 13:56:01 -03:00
Taketo Takashima
8054ad55c3 Use :unprocessable_content in generated Devise config for Rack 3.1+, avoid Rack warnings (#5797)
In Rack v3.1.0, the symbol for HTTP status code 422 was changed from `:unprocessable_entity` to `:unprocessable_content`.

As a result, when using rack 3.2 with the following configuration in `config/initializers/devise.rb`, a warning is shown on login failure:

```ruby
# config/initializers/devise.rb
Devise.setup do |config|
  ...
  config.responder.error_status = :unprocessable_entity
```

Warning message:

```sh
/path-to-app/vendor/bundle/ruby/3.4.0/gems/devise-4.9.4/lib/devise/failure_app.rb:80: warning: Status code :unprocessable_entity is deprecated and will be removed in a future version of Rack. Please use :unprocessable_content instead.
```

This warning can be resolved by updating the config as follows:
```diff
# config/initializers/devise.rb
Devise.setup do |config|
  ...
+  config.responder.error_status = :unprocessable_content
-  config.responder.error_status = :unprocessable_entity
```

This fixes the root cause of the warning for new apps by adjusting the generated config during `$ rails generate devise:install` depending on the rack version, so new apps using newer Rack versions generate `error_status = :unprocessable_content` instead of `:unprocessable_entity`.

Existing apps are handled by [latest versions of Rails, which will now transparently convert the code under the hood to avoid the Rack warning](https://github.com/rails/rails/pull/53383), and Devise will use that translation layer when available in the failure app to prevent the warning there as well (since that isn't covered by Rails automatic conversion).

Signed-off-by: Carlos Antonio da Silva <carlosantoniodasilva@gmail.com>
2025-12-31 10:45:09 -03:00
Carlos Antonio da Silva
d13ef89afb Replace [data-turbo-cache=false] with [data-turbo-temporary]
The default `_error_messages.html.erb` partial uses a deprecated Turbo
attribute `data-turbo-cache=false`, which was deprecated on Feb 15 2023
in [this pull request](https://github.com/hotwired/turbo/pull/871).

Use more up-to-date attribute name called
[data-turbo-temporary](https://github.com/hotwired/turbo/pull/871) to
avoid deprecation issues and reduce developer confusion as
`data-turbo-temporary` is the only attributed mentioned in
[Turbo Drive's documentation](https://turbo.hotwired.dev/handbook/building#preparing-the-page-to-be-cached)

Closes #5664
Closes #5662

Signed-off-by: Carlos Antonio da Silva <carlosantoniodasilva@gmail.com>
2025-12-31 09:26:09 -03:00
Carlos Antonio da Silva
b0867c998c Remove deprecated stuff (#5803)
All of these have been deprecated for years, if we're releasing a new
major version, let's take the opportunity to do some cleanup.

* Remove deprecated `:bypass` option from `sign_in` helper,
  use `bypass_sign_in` instead.
* Remove deprecated `devise_error_messages!` helper,
  use `render "devise/shared/error_messages", resource: resource` instead.
* Remove deprecated `scope` second argument from `sign_in(resource, :admin)`
  controller test helper, use `sign_in(resource, scope: :admin)` instead.
* Remove deprecated `Devise::TestHelpers`,
  use `Devise::Test::ControllerHelpers` instead.

Closes #5739
2025-10-31 13:52:34 -03:00
Carlos Antonio da Silva
4d18d81311 Respect locale set by controller in the failure app (#5567)
A common usage of I18n with different locales is to create some around
callback in the application controller that sets the locale for the
entire action, via params/url/user/etc., which ensure the locale is
respected for the duration of that action, and resets at the end.

Devise was not respecting the locale when the authenticate failed and
triggered the failure app, because that happens in a warden middleware
right up in the change, by that time the controller around callback had
already reset the locale back to its default, and the failure app would
just translate flash messages using the default locale.

Now we are passing the current locale down to the failure app via warden
options, and wrapping it with an around callback, which makes the
failure app respect the set I18n locale by the controller at the time
the authentication failure is triggered, working as expected. (much more
like a normal controller would.)

I chose to introduce a callback in the failure app so we could wrap the
whole `respond` action processing rather than adding individual `locale`
options to the `I18n.t` calls, because that should ensure other possible
`I18n.t` calls from overridden failure apps would respect the set locale
as well, and makes it more like one would implement in a controller. I
don't recommend people using callbacks in their own failure apps though,
as this is not going to be documented as a "feature" of failures apps,
it's considered "internal" and could be refactored at any point.

It is possible to override the locale with the new `i18n_locale` method,
which simply defaults to the passed locale from the controller.

Closes #5247
Closes #5246

Related to: #3052, #4823, and possible others already closed.
Related to warden: (may be closed there afterwards)
https://github.com/wardencommunity/warden/issues/180
https://github.com/wardencommunity/warden/issues/170
2023-10-13 11:20:29 -03:00
Carlos Antonio da Silva
e688b2f256 Merge branch '4-stable' 2023-10-11 19:12:53 -03:00
Carlos Antonio da Silva
c146b25f31 Better clarify need to override internal_methods
Co-authored-by: Eebs Kobeissi <ebrahim.kobeissi@gmail.com>
2023-10-10 19:51:06 -03:00
Carlos Antonio da Silva
f2a42abbf4 Ensure _prefixes is not available as an action method on controllers
There was a change introduced in Rails 7.1 that causes all public
actions of non-abstract controllers to become action methods, even if
they happen to match the name of an internal method defined by abstract
`ActionController::Base` and such, which is the case with `_prefixes`.

This change was intentional, it allows for example to have an action
called `status`, which is an internal method, and that is properly
managed as an action method now. However, it broke Devise due to
overriding `_prefixes`, which is a public method of Action Controller.

To fix, we are simply ensuring we keep `_prefixes` as an internal method
rather than action method, which matches previous behavior for this
particular method/implementation in Devise.

Ref: https://github.com/rails/rails/pull/48699
2023-10-10 11:29:29 -03:00
Rafael Mendonça França
a7d64ae313 Merge pull request #5583 from etiennebarrie/deprecator
Use a dedicated ActiveSupport::Deprecation
2023-10-10 11:29:29 -03:00
Iain Beeston
1a3d1ae350 Replaced <br/> with paragraph tags
In regular HTML `<br>` is a void element, so it

Many of the shared templates used by devise use `<br/>`
to separate lines, which is invalid html because `<br>`
doesn't need a closing tag or a closing slash. See the
WhatWG spec here:
https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-br-element

Also, the WhatWG spec uses `<p>` tags to separate
`<label>` and `<input>` tags rather than `<br>`, see
here:
https://html.spec.whatwg.org/multipage/input.html

To clean this up I've replaced `<br/>` with paragraph
tags throughout all of the templates.

This reverts b86c1c241b
2023-06-09 22:36:51 +00:00
Rafael Mendonça França
1195c6f0d6 Merge pull request #5515 from okyanusoz/patch-1
Fix a grammatical error
2023-06-09 18:16:38 -04:00
Étienne Barrié
882dd70a9f Use a dedicated ActiveSupport::Deprecation
Rails 7.1 will deprecate using the singleton ActiveSupport::Deprecation
instance. This defines one for the gem and uses it.
2023-04-07 00:15:10 +02:00
Matt Redmond
60c5774ff4 Delegate sign_in_after_reset_password to resource class
Allows resource class scopes to overrides the global configuration for sign in after reset password behaviour.
2023-03-01 22:18:16 -03:00
Junichi Ito
49ed129c40 Replce p tag with div since p tags cannot contain other block elements 2023-02-14 08:34:26 +09:00
Carlos Antonio da Silva
88625d488f Use button_to to generate a POST form, disable turbo with OmniAuth
This changes the OmniAuth "sign in" links to use buttons, which can be
wrapped in an actual HTML form with a method POST, making them work
better with and without Turbo in the app. It doesn't require rails/ujs
anymore in case of a non-Turbo app, as it previously did with links +
method=POST.

Turbo is disabled for those OmniAuth buttons, as they simply don't work
trying to follow the redirect to the OmniAuth provider via fetch,
causing CORS issues/errors.
2023-02-01 11:29:17 -03:00
Carlos Antonio da Silva
f08e0ad24a Integrate with Hotwire/Turbo by configuring error and response statuses
Treat `:turbo_stream` request format as a navigational format, much like
HTML, so Devise/responders can work properly.

Allow configuring the `error_status` and `redirect_status` using the
latest responders features, via a new custom Devise responder, so we can
customize the both responses to match Hotwire/Turbo behavior, for
example with `422 Unprocessable Entity` and `303 See Other`,
respectively. The defaults aren't changing in Devise itself (yet), so it
still responds on errors cases with `200 OK`, and redirects on non-GET
requests with `302 Found`, but new apps are generated with the new
statuses and existing apps can opt-in. Please note that these defaults
might change in a future release of Devise.

PRs/Issues references:

https://github.com/heartcombo/devise/pull/5545
https://github.com/heartcombo/devise/pull/5529
https://github.com/heartcombo/devise/pull/5516
https://github.com/heartcombo/devise/pull/5499
https://github.com/heartcombo/devise/pull/5487
https://github.com/heartcombo/devise/pull/5467
https://github.com/heartcombo/devise/pull/5440
https://github.com/heartcombo/devise/pull/5410
https://github.com/heartcombo/devise/pull/5340

https://github.com/heartcombo/devise/issues/5542
https://github.com/heartcombo/devise/issues/5530
https://github.com/heartcombo/devise/issues/5519
https://github.com/heartcombo/devise/issues/5513
https://github.com/heartcombo/devise/issues/5478
https://github.com/heartcombo/devise/issues/5468
https://github.com/heartcombo/devise/issues/5463
https://github.com/heartcombo/devise/issues/5458
https://github.com/heartcombo/devise/issues/5448
https://github.com/heartcombo/devise/issues/5446
https://github.com/heartcombo/devise/issues/5439
2023-01-31 11:02:01 -03:00
okyanusoz
41003bf5de Update new.html.erb 2022-08-30 17:06:16 +03:00
Jordan Owens
837baaf2e1 Update omniauthable tests for OmniAuth 2.0 (#5331) 2021-01-19 15:19:55 -03:00
mune
eed641d2be Add spaces around method arguments when setting default values
Closes #5288
2020-08-31 18:15:45 -03:00
Carlos Antonio da Silva
4f60544396 Improve deprecation message with example of how to remove it
The deprecation of `devise_error_messages!` wasn't super clear on what
was happening and how to get rid of the message, not it has a more
detailed explanation with an example of what to look for and what to
replace it with.

Closes #5257.
2020-06-17 08:52:43 -03:00
Connor Shea
a3fcb3b682 Fix two deprecated usages of keyword arguments.
This prevents us from using behavior that was deprecated in Ruby 2.7.
2019-12-26 17:44:53 -07:00
Renan Gurgel
d022fb8cc4 Update code with single-quotes 2019-10-03 14:27:59 -03:00
Renan Gurgel
0f134f7030 Call set_flash_message helper instead of flash accessor 2019-10-03 00:15:15 -03:00
Lucas Ferreira
964ae53e5b Update password confirmation autocomplete 2019-04-02 18:39:19 -03:00
kenji kobayashi
e3a00b27d1 Add an option to not automatically sign in a user after changing a password (#4569) 2018-12-28 11:29:58 -02:00
Pavel Pestau
8266e85576 Removing extra characters (#4991) 2018-12-21 10:18:05 -02:00
Pavel Pestau
4372dd402b Removed extra characters (#4988) 2018-12-20 11:51:19 -02:00
Marcos Ferreira
14785afe8d Add a deprecation warn for DeviseHelper.devise_error_messages!
To customize the error style one should modifying the
`devise/shared/error_messages` partial.
2018-12-18 21:15:13 -02:00
Marcos Ferreira
66a96ab9d6 Fix unclosed li tag in error_messages partial 2018-12-18 21:15:11 -02:00
Graham Brereton
76b87dc0e8 Refactor the devise_error_messages! helper to render a partial (#4616)
This should make it more intuitive and easier for developers using the
project to implement their own layout for errors.
2018-12-18 21:01:16 -02:00
Kanmaniselvan Murugesan
bafc23eae5 Issue 4895: Add after_database_authentication callback after sign_in immediately after password update (#4916) 2018-11-22 19:13:55 -02:00
Isaac Orme
acc45c5a44 issue 4356 adds is_navigational_format? check to after_sign_up_path_for (#4833) 2018-08-02 11:02:50 -03:00
Jayanth Manklu
9d90a559ce Fix in rdoc of DeviseController#_prefixes
Removing an additional "is"
2018-05-03 15:36:43 +05:30
Gustavo Bazan
6260c29a86 Improve passwords autocomplete
Use `autocomplete="new-password"` or `autocomplete="current-password"` to better signal to browsers and password managers how to handle the password fields.

This feature is especially useful for “change your password” and “new user” forms
2018-04-19 12:58:58 -04:00
Anton Davydov
95689757c0 Delete unnecessary condition for helper method (#4359) 2017-12-22 15:38:45 -02:00
Mike Rogers
16b3d6d67c Adding autocomplete="email" to email fields (#4643)
As discussed in https://github.com/plataformatec/devise/issues/4635
2017-12-21 17:13:50 -02:00
Sai Chander
db011c0192 set_flash_method! instead of set_flash_method in omniauth callbacks controller (#4680) 2017-12-21 15:53:14 -02:00
Pat Allan
f39c6fd927 Add the frozen_string_literal pragma comment to all Ruby files. (#4725) 2017-12-21 15:36:29 -02:00
Pat Allan
1009096172 Fix syntax for MRI 2.5.0-preview1. 2017-10-13 10:38:43 +11:00
Jonathon Padfield
ce08d7abb8 Replaced render :text 404 with :plain in omniauth
Rails 5.1 has deprecated render :text, and HEAD requests on the
omniauth callbacks passthru method is causing errors because the render
:text is non-existant, and there's no template to fall back to.

Replacing :text with :plain, adds a content-type type of text/plain and
also returns the previous message.

render :plain was supported back in rails 4.1.0
http://api.rubyonrails.org/v4.1.0/classes/ActionView/Helpers/RenderingHelper.html#method-i-render
2017-05-03 13:31:52 +10:00
Carlos Antonio da Silva
ce071502ee Display unconfirmed email when using reconfirmable and email changed notification
Otherwise we'd be mistakenly displaying the original email in the
message (which is the same we're sending the message to).

Also tweak the messaging a bit in this case, to show that the email "is
being changed" (the change hasn't taken effect yet).

Related to #4455.
2017-03-15 11:47:47 -03:00
Carlos Antonio da Silva
2135ae5e5e Change email_change => email_changed notification
This better indicates what the setting is for, and when it's supposed to
be triggered.

We might eventually deprecate the existing password_change on in favor
of password_changed.
2017-03-10 08:56:34 -03:00
Carlos Antonio da Silva
70eb18d766 Notify original user email when the email changes
This adds a new setting `send_email_change_notification` which will
send an email to the original user email when their email is updated to
a new one.

It doesn't take into account the reconfirmable setting yet, it will be
added next, so that if confirmable is included and reconfirmable is
being used, the email will be triggered when the email change is
requested, not when confirmed (e.g when we store the email in
`unconfirmed_email`, not when it's later copied to `email` when that is
confirmed).
2017-03-06 17:04:26 -03:00
ethiraj
7a44233fb9 set minimum password length after user registration update 2016-10-27 08:33:35 +05:30
Kris Handley
0c991af985 Fix Rails 5 env deprecation warning
Full warning ```DEPRECATION WARNING: env is deprecated and will be removed from Rails 5.1```
2016-06-18 14:20:08 +01:00
Steve Richert
83d5d3142d Self-love isn't entirely appropriate in this setting 2016-05-26 09:25:44 -04:00
Ulisses Almeida
2044fffa25 Deprecate the bypass option of sign_in (#4078)
The sign_in method permits the bypass option
that ignore the others options used. This behavior
has lead some users to a misconfusion what the
method really does.

This change deprecate the bypass option in favor
of a method that only does the sign in with bypass.

Closes #3981
2016-05-15 11:46:48 -03:00
Matt Yanchek
85bcbdf18b Set minimum password length for edit and new views (#4068)
* Set minimum password length for edit and new views

* Update edit.html.erb

* Update registerable_test.rb
2016-05-05 17:16:41 -03:00
Jeroen Visser
b214333760 Remove trailing whitespace from confirmation view
Though not a real issue, it was highlighted as an error by my commit
hooks, so I took the opportunity to fix it.
2016-03-07 10:07:34 +01:00
oss92
18528650c3 Added DeviseController#set_flash_message! 2016-02-11 02:49:53 +02:00