PageSourceSearch

https://www.aradon.ro/wp-content/plugins/endless-core/js/trAccounts.js?ver=1790773834

js aradon.ro collected 2026-10-01 10:40:33 UTC 14,799 bytes, 377 lines download raw bytes

1const TrAccounts = {
2    manualDate: Date.now(),
3    reloadAfterLogInOut: false,
4    init: function (userIconParentSelector) {
5        TrAccounts.manualDateParam = TrAccounts.isGetHasTrAccounts('current-date') ? '?current-date=' + TrAccounts.isGetHasTrAccounts('current-date') : '';
6        TrAccounts.userIcon.build(userIconParentSelector);
7        TrAccounts.modal.build(TrAccounts.forms.loginModalConfig());
8        TrAccounts.user.check();
9    },
10    user: {
11        cookieId: 'trAccountsUserToken',
12        userDataEndpoint: '/wp-json/endless/v1/tr-accounts',
13        check: function () {
14            return TrAccounts.getCookie(TrAccounts.user.cookieId);
15        },
16        set: function (data) {
17            if (typeof data !== 'object' || data === null || !data.hasOwnProperty('token')) {
18                console.error('Invalid data format for setting user token:', data);
19                return;
20            }
21
22            document.cookie = TrAccounts.user.cookieId + '=' + data.token + '; path=/; max-age=259200; SameSite=Lax';
23        },
24        login: function (data) {
25            jQuery.ajax({
26                type: 'POST',
27                url: TrAccounts.user.userDataEndpoint + '/login',
28                data: data,
29                success: TrAccounts.user.afterLogin,
30            });
31        },
32        afterLogin: function (response) {
33            if (!response.hasOwnProperty('success') || !response.success) {
34                const modal = TrAccounts.modal.get();
35                console.log(response.hasOwnProperty('errorMessage'), modal);
36                if (response.hasOwnProperty('errorMessage') && modal) {
37                    const errorMessageElement = modal.querySelector('.error-message');
38                    if (errorMessageElement) {
39                        errorMessageElement.textContent = response.errorMessage;
40                    }
41                }
42                return;
43            }
44
45            TrAccounts.user.set(response);
46            if (TrAccounts.reloadAfterLogInOut) {
47                document.location.reload();
48            }
49        },
50        logout: function () {
51            document.cookie = TrAccounts.user.cookieId + '=; path=/; max-age=0; SameSite=Lax';
52            if (TrAccounts.reloadAfterLogInOut) {
53                document.location.reload();
54                return;
55            }
56
57            TrAccounts.userIcon.setLoggedOut();
58        },
59        register: function () {
60            jQuery.ajax({
61                type: 'POST',
62                url: TrAccounts.user.userDataEndpoint + '/register',
63                data: {},
64                success: TrAccounts.user.afterLogin
65            });
66        }
67    },
68    userIcon: {
69        wrapperId: 'TrAccountsUserIcon',
70        build: function (parentSelector) {
71            if (typeof parentSelector !== 'string') {
72                return;
73            }
74            const config = [
75                {
76                    tag: 'button',
77                    onClick: TrAccounts.modal.show,
78                    classList: 'tr-accounts-user-button',
79                }
80            ];
81            return HtmlBuilder.buildByConfig(TrAccounts.userIcon.wrapperId, config, parentSelector);
82        },
83        get: function () {
84            return document.querySelector('#' + TrAccounts.userIcon.wrapperId);
85        },
86        setLoggedIn: function () {
87            let icon = TrAccounts.userIcon.get() ?? TrAccounts.userIcon.build();
88            if (!icon) {
89                return;
90            }
91            icon.classList.add('logged-in');
92        },
93        setLoggedOut: function () {
94            let icon = TrAccounts.userIcon.get() ?? TrAccounts.userIcon.build();
95            if (!icon) {
96                return;
97            }
98            icon.classList.remove('logged-in');
99        }
100    },
101    modal: {
102        wrapperId: 'TrAccountsModal',
103        loginTitle: 'Bejelentkezés',
104        formId: 'TrAccountsLoginForm',
105        build: function (config) {
106            const wrappedConfig = [
107                {
108                    tag: 'div',
109                    classList: 'modal-background',
110                    onClick: TrAccounts.modal.hide
111                },
112                {
113                    tag: 'div',
114                    classList: 'modal-content',
115                    children: config
116                }
117            ]
118            return HtmlBuilder.buildByConfig(TrAccounts.modal.wrapperId, wrappedConfig);
119        },
120        get: function () {
121            return document.querySelector('#' + TrAccounts.modal.wrapperId);
122        },
123        show: function () {
124            let modal = TrAccounts.modal.build(TrAccounts.forms.loginModalConfig());
125            modal.classList.add('show');
126        },
127        hide: function () {
128            let modal = TrAccounts.modal.get();
129            if (modal) {
130                modal.classList.remove('show');
131            }
132        }
133    },
134    forms: {
135        loginModalConfig: function () {
136            return [
137                {
138                    tag: 'form',
139                    id: TrAccounts.modal.formId,
140                    classList: 'tr-accounts-login-form',
141                    target: TrAccounts.user.userDataEndpoint + '/login',
142                    children: [
143                        {
144                            tag: 'h1',
145                            text: TrAccounts.modal.loginTitle
146                        },
147                        {
148                            tag: 'div',
149                            classList: 'form-group',
150                            children: [
151                                {
152                                    tag: 'label',
153                                    for: 'TrAccountsLoginEmailOrUsername',
154                                    text: 'E-mail cím vagy felhasználónév'
155                                },
156                                {
157                                    tag: 'input',
158                                    type: 'text',
159                                    id: 'TrAccountsLoginEmailOrUsername',
160                                    name: 'emailOrUsername',
161                                    autocomplete: 'current-username',
162                                    required: true
163                                },
164                                {
165                                    tag: 'p',
166                                    classList: 'error',
167                                    text: 'Kérjük, adja meg a felhasználónevét vagy az e-mail címét.'
168                                }
169                            ]
170                        },
171                        {
172                            tag: 'div',
173                            classList: 'form-group',
174                            children: [
175                                {
176                                    tag: 'label',
177                                    for: 'TrAccountsLoginPassword',
178                                    text: 'Jelszó'
179                                },
180                                {
181                                    tag: 'input',
182                                    type: 'password',
183                                    id: 'TrAccountsLoginPassword',
184                                    name: 'password',
185                                    autocomplete: 'current-password',
186                                    required: true
187                                },
188                                {
189                                    tag: 'p',
190                                    classList: 'error',
191                                    text: 'Kérjük, adja meg a jelszavát.'
192                                }
193                            ]
194                        },
195                        {
196                            tag: 'p',
197                            classList: 'error-message',
198                            text: ''
199                        },
200                        {
201                            tag: 'div',
202                            classList: 'btn-group',
203                            children: [
204                                {
205                                    tag: 'button',
206                                    classList: 'close-button',
207                                    onClick: TrAccounts.modal.hide,
208                                    text: 'Mégse'
209                                },
210                                {
211                                    tag: 'button',
212                                    classList: 'submit-button',
213                                    onClick: TrAccounts.forms.submit.bind(null, TrAccounts.user.login),
214                                    text: 'Bejelentkezés'
215                                }
216                            ]
217                        }
218                    ]
219                }
220            ];
221        },
222        submit: function (callback = (data) => {
223            console.log(data)
224        }) {
225            const modal = TrAccounts.modal.get();
226            if (!modal) {
227                console.log('Submit failed, form not found');
228                return;
229            }
230
231            const form = modal.querySelector('#' + TrAccounts.modal.formId);
232            if (!form) {
233                console.log('Submit failed, form not found');
234                return;
235            }
236
237            let inputs = form.querySelectorAll('input');
238            if (TrAccounts.forms.checkForInvalidInputs(inputs)) {
239                return;
240            }
241
242            let data = TrAccounts.forms.getNeededInputValues(inputs);
243            callback(data);
244        },
245        getNeededInputValues: function (inputElements) {
246            const neededInputs = {};
247            for (const inputIndex in inputElements) {
248                if (isFinite(inputIndex)) {
249                    if (inputElements[inputIndex].type !== 'radio' && inputElements[inputIndex].type !== 'checkbox') {
250                        neededInputs[inputElements[inputIndex].name] = inputElements[inputIndex].value;
251                    } else if (inputElements[inputIndex].checked) {
252                        neededInputs[inputElements[inputIndex].name] = inputElements[inputIndex].value;
253                    }
254                }
255            }
256
257            return neededInputs;
258        },
259        checkForInvalidInputs: function (inputs) {
260            let firstInvalidInput = undefined;
261            const emailRegex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
262            for (const inputIndex in inputs) {
263                if (!isFinite(inputIndex)) {
264                    continue;
265                }
266
267                // Remove previous validation errors
268                inputs[inputIndex].classList.remove('is-invalid');
269                let formGroup = inputs[inputIndex].closest('.form-group');
270                if (formGroup) {
271                    formGroup.classList.remove('is-invalid');
272                }
273
274                if (
275                    (
276                        !inputs[inputIndex].required &&
277                        !inputs[inputIndex].classList.contains('required')
278                    ) &&
279                    (
280                        !inputs[inputIndex].closest('.form-group') ||
281                        !inputs[inputIndex].closest('.form-group').classList.contains('required')
282                    )
283                ) {
284                    continue;
285                }
286
287                let isInvalid = false;
288
289                // Checkbox check
290                if (
291                    inputs[inputIndex].getAttribute('type') === 'checkbox' &&
292                    !inputs[inputIndex].checked
293                ) {
294                    console.log('Checkbox is not checked:', inputs[inputIndex]);
295                    isInvalid = true;
296                }
297
298                // RadioButton check
299                if (
300                    inputs[inputIndex].getAttribute('type') === 'radio' &&
301                    !ssoAccounts.forms.checkIfRadioButtonGroupIsValid(inputs[inputIndex])
302                ) {
303                    console.log('Radio button group is not checked:', inputs[inputIndex]);
304                    isInvalid = true;
305                }
306
307                // TextField and Password check
308                if (
309                    (
310                        inputs[inputIndex].getAttribute('type') === 'text' ||
311                        inputs[inputIndex].getAttribute('type') === 'password'
312                    ) &&
313                    inputs[inputIndex].value.trim() === ''
314                ) {
315                    console.log('Text or Password field is empty:', inputs[inputIndex]);
316                    isInvalid = true;
317                }
318
319                // Email check
320                if (
321                    inputs[inputIndex].getAttribute('type') === 'email' &&
322                    (
323                        !emailRegex.test(inputs[inputIndex].value) ||
324                        inputs[inputIndex].value.trim() === ''
325                    )
326                ) {
327                    console.log('Email format is invalid:', inputs[inputIndex]);
328                    isInvalid = true;
329                }
330
331                if (isInvalid) {
332                    inputs[inputIndex].classList.add('is-invalid');
333                    let formGroup = inputs[inputIndex].closest('.form-group');
334                    if (formGroup) {
335                        formGroup.classList.add('is-invalid');
336                    }
337                    if (!firstInvalidInput) {
338                        firstInvalidInput = inputs[inputIndex];
339                    }
340                }
341            }
342
343            if (firstInvalidInput) {
344                firstInvalidInput.scrollIntoView({behavior: 'smooth', block: 'center'});
345                return true;
346            }
347
348            return false;
349        }
350    },
351    isGetHasTrAccounts: function (passedString) {
352        let parameters = window.location.search.substr(1);
353        parameters = parameters != null && parameters !== '' ? transformGetParametersToObject(parameters) : {};
354        for (const key in parameters) {
355            if (passedString === key) {
356                return parameters[key];
357            }
358        }
359
360        return false;
361    },
362    getCookie: function (name) {
363        let cookieValue = null;
364        if (document.cookie && document.cookie !== '') {
365            const cookies = document.cookie.split(';');
366            for (let i = 0; i < cookies.length; i++) {
367                const cookie = cookies[i].trim();
368                // Check if this cookie string begins with the name we want
369                if (cookie.substring(0, name.length + 1) === (name + '=')) {
370                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
371                    break;
372                }
373            }
374        }
375        return cookieValue;
376    }
377};

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.