Browse Source

Redirect confirmation to set password

pull/580/head
baarkerlounger 3 years ago
parent
commit
f2cd0dae96
  1. 24
      app/controllers/auth/confirmations_controller.rb
  2. 2
      app/views/devise/passwords/reset_password.html.erb
  3. 8
      config/locales/devise.en.yml
  4. 2
      config/routes.rb

24
app/controllers/auth/confirmations_controller.rb

@ -0,0 +1,24 @@
class Auth::ConfirmationsController < Devise::ConfirmationsController
# GET /resource/confirmation?confirmation_token=abcdef
def show
self.resource = resource_class.confirm_by_token(params[:confirmation_token])
yield resource if block_given?
if resource.errors.empty?
set_flash_message!(:notice, :confirmed)
token = resource.send(:set_reset_password_token)
base = public_send("edit_#{resource_class.name.underscore}_password_url")
url = "#{base}?reset_password_token=#{token}"
redirect_to url
else
respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
end
end
protected
def after_confirmation_path_for(resource_name, resource)
edit_user_password_path(email: resource.email)
end
end

2
app/views/devise/passwords/reset_password.html.erb

@ -1,4 +1,4 @@
<% content_for :title, "Reset your password" %>
<% content_for :title, resource.sign_in_count.zero? ? "Set your password" : "Reset your password" %>
<% content_for :before_content do %>
<%= govuk_back_link(

8
config/locales/devise.en.yml

@ -56,10 +56,10 @@ en:
unlocked: "Your account has been successfully unlocked. Sign in to continue."
errors:
messages:
already_confirmed: "has already been confirmed. Sign in."
blank: "can’t be blank"
confirmation: "doesn’t match new password"
confirmation_period_expired: "needs to be confirmed within %{period}. Request a new account."
already_confirmed: "Email has already been confirmed. Sign in."
blank: "Email can’t be blank"
confirmation: "Passwords don’t match"
confirmation_period_expired: "Email needs to be confirmed within %{period}. Request a new account."
expired: "Token has expired. Request a new token."
not_found: "was not found"
not_locked: "has not been locked"

2
config/routes.rb

@ -26,7 +26,7 @@ Rails.application.routes.draw do
devise_for :users, {
path: :account,
controllers: {
confirmations: "devise/confirmations",
confirmations: "auth/confirmations",
passwords: "auth/passwords",
sessions: "auth/sessions",
two_factor_authentication: "auth/two_factor_authentication",

Loading…
Cancel
Save