Files
openfoodnetwork/app/controllers/user_confirmations_controller.rb
Luis Ramos 0f29806198 Adapt code to devise 3.2 where the reset_password_token stored in the db is a encrypted version of the token sent in the email
In this particular case, the user confirmations controller is redirecting to the reset password page but it doesnt know what is the raw reset_password_token

So we regenerate the reset password token so that it can know what's the raw value for the redirect

The method User#regenerate_reset_password_token is a proxy to the protected method in Devise::Recoverable
2020-07-31 09:05:42 +01:00

59 lines
1.6 KiB
Ruby

class UserConfirmationsController < DeviseController
# Needed for access to current_ability, so we can authorize! actions
include Spree::Core::ControllerHelpers::Auth
# GET /resource/confirmation/new
def new
build_resource({})
end
# POST /resource/confirmation
def create
set_return_url if params.key? :return_url
self.resource = resource_class.send_confirmation_instructions(resource_params)
if is_navigational_format?
if successfully_sent?(resource)
set_flash_message(:success, :confirmation_sent)
else
set_flash_message(:error, :confirmation_not_sent)
end
end
respond_with_navigational(resource){ redirect_to login_path }
end
# GET /resource/confirmation?confirmation_token=abcdef
def show
self.resource = resource_class.confirm_by_token(params[:confirmation_token])
respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource) }
end
protected
def set_return_url
session[:confirmation_return_url] = params[:return_url]
end
def after_confirmation_path_for(resource)
result =
if resource.errors.empty?
'confirmed'
else
'not_confirmed'
end
if resource.reset_password_token.present?
raw_reset_password_token = resource.regenerate_reset_password_token
return spree.edit_spree_user_password_path(
reset_password_token: raw_reset_password_token
)
end
path = (session[:confirmation_return_url] || login_path).to_s
path += path.include?('?') ? '&' : '?'
path + "validation=#{result}"
end
end