-
Notifications
You must be signed in to change notification settings - Fork 23
/
authentication.js
56 lines (50 loc) · 1.71 KB
/
authentication.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
onDomReady(function() {
// Log in.
const login_form = document.getElementById('login-form')
if (login_form !== null) {
login_form.addEventListener('submit', function(event) {
event.preventDefault();
const login_failed_notice = document.getElementById('login-failed-notice');
login_failed_notice.classList.add('hidden');
$.ajax({
type: 'POST',
url: login_form.getAttribute('action'),
data: $(this).serializeArray(),
success: function(data, text_status, xhr) {
// Redirect to location specified via header.
var redirect_url = _get_location(xhr);
if (redirect_url !== null) {
location.href = redirect_url;
return;
}
// Redirect to referrer if available.
var referrer = document.createElement('a');
referrer.href = document.referrer;
// Exclude selected referrer paths.
if (/^\/(authentication|consent)\//.test(referrer.pathname)) {
referrer.pathname = '/';
}
location.href = (referrer.hostname == location.hostname) ? referrer.pathname : '/';
},
error: function() {
login_failed_notice.classList.remove('hidden');
},
dataType: 'text'
});
});
}
// Log out.
forEach(
document.querySelectorAll('a[data-action="logout"]'),
function(anchor) {
anchor.addEventListener('click', function(event) {
if (confirm('Wirklich abmelden?')) {
const href = anchor.getAttribute('href');
send_post_request(href, function() {
location.href = '/authentication/login';
});
};
event.preventDefault();
});
});
});