FIX: Account activation under ember-5 build (#24722)

We were previously relying on Ember's 'vendor' bundle to make the jquery global available on the activate_account route. That no longer happens under our Ember 5 build.

This commit updates our activate-account script to remove the need for jquery, so that it works under both Ember 3 and Ember 5 builds.
This commit is contained in:
David Taylor 2023-12-05 17:49:40 +00:00 committed by GitHub
parent 6aeddad333
commit a5fc8f3253
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 13 deletions

View File

@ -1,18 +1,27 @@
/* eslint-disable ember/no-global-jquery */
(function () { (function () {
const $activateButton = $("#activate-account-button"); const activateButton = document.querySelector("#activate-account-button");
$activateButton.on("click", function () { activateButton.addEventListener("click", async function () {
$activateButton.prop("disabled", true); activateButton.setAttribute("disabled", true);
const hpPath = document.getElementById("data-activate-account").dataset const hpPath = document.getElementById("data-activate-account").dataset
.path; .path;
$.ajax(hpPath)
.then(function (hp) { try {
$("#password_confirmation").val(hp.value); const response = await fetch(hpPath, {
$("#challenge").val(hp.challenge.split("").reverse().join("")); headers: {
$("#activate-account-form").submit(); Accept: "application/json",
}) },
.fail(function () {
$activateButton.prop("disabled", false);
}); });
const hp = await response.json();
document.querySelector("#password_confirmation").value = hp.value;
document.querySelector("#challenge").value = hp.challenge
.split("")
.reverse()
.join("");
document.querySelector("#activate-account-form").submit();
} catch (e) {
activateButton.removeAttribute("disabled");
throw e;
}
}); });
})(); })();

View File

@ -12,7 +12,6 @@
</div> </div>
<%- content_for(:no_ember_head) do %> <%- content_for(:no_ember_head) do %>
<%= preload_script "vendor" %>
<%= render_google_universal_analytics_code %> <%= render_google_universal_analytics_code %>
<%= tag.meta id: 'data-activate-account', data: { path: path('/session/hp') } %> <%= tag.meta id: 'data-activate-account', data: { path: path('/session/hp') } %>
<%- end %> <%- end %>