Browse Source

Set password condition

pull/580/head
baarkerlounger 3 years ago
parent
commit
4e7c548fdb
  1. 4
      app/controllers/auth/confirmations_controller.rb
  2. 1
      app/controllers/auth/passwords_controller.rb
  3. 2
      app/views/devise/passwords/reset_password.html.erb
  4. 2
      config/locales/devise.en.yml
  5. 1
      spec/factories/user.rb
  6. 2
      spec/features/organisation_spec.rb

4
app/controllers/auth/confirmations_controller.rb

@ -8,9 +8,7 @@ class Auth::ConfirmationsController < Devise::ConfirmationsController
set_flash_message!(:notice, :confirmed)
if resource.sign_in_count.zero?
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
redirect_to controller: "auth/passwords", action: "edit", reset_password_token: token, confirmation: true
else
respond_with_navigational(resource) { redirect_to after_confirmation_path_for(resource_name, resource) }
end

1
app/controllers/auth/passwords_controller.rb

@ -24,6 +24,7 @@ class Auth::PasswordsController < Devise::PasswordsController
def edit
super
@confirmation = params["confirmation"]
render "devise/passwords/reset_password"
end

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

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

2
config/locales/devise.en.yml

@ -58,7 +58,7 @@ en:
messages:
already_confirmed: "Email has already been confirmed. Sign in."
blank: "Email can’t be blank"
confirmation: "Passwords don’t match"
confirmation: "Password confirmation doesn’t match new password"
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"

1
spec/factories/user.rb

@ -15,6 +15,7 @@ FactoryBot.define do
trait :support do
role { "support" }
end
sign_in_count { 5 }
confirmed_at { Time.zone.now }
created_at { Time.zone.now }
updated_at { Time.zone.now }

2
spec/features/organisation_spec.rb

@ -5,7 +5,7 @@ RSpec.describe "User Features" do
include Helpers
let(:organisation) { user.organisation }
let(:org_id) { organisation.id }
let(:set_password_template_id) { User::SET_PASSWORD_TEMPLATE_ID }
let(:set_password_template_id) { User::CONFIRMABLE_TEMPLATE_ID }
let(:notify_client) { instance_double(Notifications::Client) }
let(:reset_password_token) { "MCDH5y6Km-U7CFPgAMVS" }
let(:devise_notify_mailer) { DeviseNotifyMailer.new }

Loading…
Cancel
Save