PageSourceSearch

https://www.brightplus.be/scripts/JobDispatcher/Login.js

js brightplus.be collected 2026-09-24 12:49:24 UTC 5,201 bytes, 176 lines download raw bytes

1import { disableButton, enableButton } from './helpers.js';
2import { handleAjaxError } from "../JS/ajaxHelpers.js"
3import { showLoader, hideLoader } from '../JS/loader.js';
4
5var isEmailAddressValid = false;
6var lastCheckedEmailAddress = null;
7var passwordCollapsable = null;
8var passwordCollapsed = true;
9
10$(document).ready(function () {
11    const loginPasswordContainer = document.querySelector('#login-password-container');
12    if (loginPasswordContainer) {
13        passwordCollapsable = new bootstrap.Collapse(loginPasswordContainer, { hide: true, toggle: false });
14        if ($('#login-email-input').val()) {
15            checkAccountExists();
16        }
17    }
18});
19
20$('.login-form').submit((event) => {
21    const submitBtn = $('.login-form :submit');
22    showLoader();
23    disableButton(submitBtn);
24    checkAccountExists(event, () => {
25        enableButton(submitBtn);
26        hideLoader();
27    });
28});
29
30$('#forgot-password-link').click(resetPassword);
31
32$("#login-email-input").on('keyup paste', function (e) {
33    let emailAddress = $(e.target).val();
34    if (passwordCollapsed || lastCheckedEmailAddress === emailAddress) {
35        return;
36    }
37
38    hidePassword();
39    removeValidation($(e.target));
40    lastCheckedEmailAddress = emailAddress;
41    getAccountExists(emailAddress);
42});
43
44function showPassword() {
45    passwordCollapsed = false;
46    passwordCollapsable.show();
47}
48
49function hidePassword() {
50    passwordCollapsed = true;
51    passwordCollapsable.hide();
52}
53
54function checkAccountExists(event, callback) {
55    let emailAddress = $('#login-email-input').val();
56    if (isEmailAddressValid && lastCheckedEmailAddress === emailAddress) {
57        return;
58    }
59
60    if (event) {
61        event.preventDefault();
62    }
63
64    if (lastCheckedEmailAddress === emailAddress) {
65        if (callback) {
66            callback();
67        }
68
69        return;
70    }
71
72    lastCheckedEmailAddress = emailAddress;
73    hidePassword();
74    getAccountExists(emailAddress).then((response) => {
75        processAccountExistsResult(response);
76        if (callback) {
77            callback();
78        }
79    });
80}
81
82function getAccountExists(emailAddress) {
83
84    let isApply = $("#is-apply-input").val();
85    let isSpontaneous = $("#is-spontaneous-input").val();
86    let jobCode = $("#job-code-input").val();
87    let token = $("input[name='__RequestVerificationToken']").val();
88    let redirectUrl = $("#redirect-url-input").val();
89
90    return $.ajax({
91        type: 'post',
92        url: `/${currentCulture}/api/account/exists`,
93        dataType: "json",
94        headers: { "RequestVerificationToken": token },
95        data: JSON.stringify({
96            emailAddress: emailAddress,
97            isApply: isApply === "true" ? true : false,
98            isSpontaneous: isSpontaneous === "true" ? true : false,
99            jobCode: jobCode,
100            redirectUrl: redirectUrl
101        }),
102        contentType: "application/json; charset=utf-8",
103        error: function (request) {
104            enableButton($(".login-form :submit"));
105            handleAjaxError(this, request);
106        }
107    });
108}
109
110function processAccountExistsResult(response) {
111    isEmailAddressValid = response.isEmailAddressValid;
112    $(`div[data-validation-messages-for='EmailAddress']`).text('');
113    const emailAddressInput = $('#login-email-input');
114
115    if (response.redirectUrl) {
116        window.location.href = response.redirectUrl;
117        return;
118    }
119
120    if (response.accountExists) {
121        markAsValid(emailAddressInput);
122        setTimeout(showPassword());
123        return;
124    }
125
126    for (let i = 0; i < response.errors.length; i++) {
127        let error = response.errors[i];
128        $(`div[data-validation-messages-for='${error.field}']`).text(error.errorMessages.map(x => x.message).join("\n"));
129        const input = $(`[data-input-field='${error.field}']`);
130        markAsInvalid(input);
131    }
132}
133
134function resetPassword(e) {
135    e.preventDefault();
136    const emailAddress = $('#login-email-input').val();
137    let token = $("input[name='__RequestVerificationToken']").val();
138    $.ajax({
139        type: "post",
140        url: `/${currentCulture}/api/account/reset-password`,
141        dataType: 'json',
142        headers: { "RequestVerificationToken": token },
143        data: JSON.stringify(emailAddress),
144        contentType: "application/json; charset=utf-8",
145        success: function (response) {
146            if (!response.message) {
147                return;
148            }
149
150            const container = $(".dxp-page-login__alert-container");
151            container.empty();
152            container.prepend(`<div class="dxp-page-login__alert alert alert-info" role="alert">${response.message}</div>`);
153            isEmailAddressValid = false;
154            lastCheckedEmailAddress = null;
155            hidePassword();
156        },
157        error: function (request) {
158            handleAjaxError(this, request);
159        }
160    })
161}
162
163function markAsValid(input) {
164    input.removeClass("is-invalid");
165    input.addClass("is-valid");
166}
167
168function markAsInvalid(input) {
169    input.removeClass("is-valid");
170    input.addClass("is-invalid");
171}
172
173function removeValidation(input) {
174    input.removeClass("is-valid");
175    input.removeClass("is-invalid");
176}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.