PageSourceSearch

https://earsc-portal.eu/includes/js/login.js

js earsc-portal.eu collected 2026-09-29 00:00:09 UTC 4,009 bytes, 130 lines download raw bytes

1/**
2 * @module confluence/login
3 */
4define('confluence/login', [
5    'jquery',
6    'ajs',
7    'document',
8    'confluence/captcha-handler',
9    'wrm/context-path'
10], function(
11    $,
12    AJS,
13    document,
14    captchaHandler,
15    contextPath
16) {
17    'use strict';
18
19    return function() {
20        var $loginButton;
21        var $loginForm;
22        var $usernameErrorMessage;
23        var $passwordErrorMessage;
24        var $username;
25        var $password;
26
27        function showSignup() {
28            var $signupSection = $('.signup-section');
29
30            if ($signupSection.length !== 0) {
31                $('.login-section').hide();
32                $signupSection.show();
33            }
34        }
35
36        function showLogin() {
37            $('.login-section').show();
38            $('.signup-section').hide();
39        }
40
41        if (document.URL.indexOf('login.action') > -1 || document.URL.indexOf('logout.action') > -1) {
42            showLogin();
43        }
44
45        if (document.URL.indexOf('signup.action') > -1) {
46            showSignup();
47        }
48
49        $('#signupMessage').delegate('click', 'a', function(e) {
50            e.preventDefault();
51            showSignup();
52        });
53
54        $('#loginMessage').delegate('click', 'a', function(e) {
55            e.preventDefault();
56            showLogin();
57        });
58
59        var errorTemplate = '<div id="os_{field}_error" class="error" style="display:none"><span class="error">{message}</span></div>';
60
61        $usernameErrorMessage = $(AJS.template(errorTemplate).fill({ field: 'username', message: AJS.I18n.getText('login.username.required') }).toString());
62        $passwordErrorMessage = $(AJS.template(errorTemplate).fill({ field: 'password', message: AJS.I18n.getText('login.password.required') }).toString());
63
64        $username = $('#os_username');
65        $password = $('#os_password');
66
67        var fetchCaptchaAndShow = function() {
68            /* Only set captcha src for login flow in this js file. Return for all other flows.
69              Since signup page comes with captcha (generated from backend), this function was resetting captchaId,
70              leading to mismatch in captchaId during validation , hence we need to skip captchaId regeneration for signup)
71            */
72            if (document.URL.indexOf('login.action') === -1) {
73                return;
74            }
75
76            var captchaId = Math.random();
77            var captchaImg = document.querySelector('#login-captcha-img');
78
79            $('input[name="captchaId"]').val(captchaId);
80
81            if (captchaImg) {
82                captchaHandler.bindingEvent(captchaImg);
83                captchaImg.setAttribute('src', contextPath() + '/jcaptcha?id=' + captchaId + '&action=login');
84            }
85        };
86
87        $(document).ready(function() {
88            fetchCaptchaAndShow();
89        });
90
91        function validate() {
92            var inputIsValid = true;
93
94            if ($username.val().length < 1) {
95                inputIsValid = false;
96                $username.after($usernameErrorMessage.show());
97            } else {
98                $usernameErrorMessage.hide();
99            }
100
101            if ($password.val().length < 1) {
102                inputIsValid = false;
103                $password.after($passwordErrorMessage.show());
104            } else {
105                $passwordErrorMessage.hide();
106            }
107
108            return inputIsValid;
109        }
110
111        $loginButton = $('#loginButton');
112        $loginForm = $loginButton.closest('form');
113        $loginForm.submit(function(e) {
114            var formIsValid;
115            $loginButton.attr('enabled', 'false');
116            formIsValid = validate();
117            if (!formIsValid) {
118                $loginButton.attr('enabled', 'true');
119            }
120            formIsValid || e.preventDefault();
121        });
122    };
123});
124
125/* istanbul ignore next */
126require('confluence/module-exporter').safeRequire('confluence/login', function(Login) {
127    'use strict';
128
129    require('ajs').toInit(Login);
130});

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.