-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
login.js
73 lines (59 loc) · 1.73 KB
/
login.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict';
define('forum/login', ['jquery-form'], function () {
var Login = {};
Login.init = function () {
var errorEl = $('#login-error-notify');
var submitEl = $('#login');
var formEl = $('#login-form');
submitEl.on('click', function (e) {
e.preventDefault();
if (!$('#username').val() || !$('#password').val()) {
errorEl.find('p').translateText('[[error:invalid-username-or-password]]');
errorEl.show();
} else {
errorEl.hide();
if (submitEl.hasClass('disabled')) {
return;
}
submitEl.addClass('disabled');
formEl.ajaxSubmit({
headers: {
'x-csrf-token': config.csrf_token,
},
success: function (data) {
var pathname = utils.urlToLocation(data.next).pathname;
var params = utils.params({ url: data.next });
params.loggedin = true;
var qs = decodeURIComponent($.param(params));
window.location.href = pathname + '?' + qs;
},
error: function (data) {
if (data.status === 403 && data.responseText === 'Forbidden') {
window.location.href = config.relative_path + '/login?error=csrf-invalid';
} else {
errorEl.find('p').translateText(data.responseText);
errorEl.show();
submitEl.removeClass('disabled');
// Select the entire password if that field has focus
if ($('#password:focus').length) {
$('#password').select();
}
}
},
});
}
});
$('#login-error-notify button').on('click', function (e) {
e.preventDefault();
errorEl.hide();
return false;
});
if ($('#content #username').val()) {
$('#content #password').val('').focus();
} else {
$('#content #username').focus();
}
$('#content #noscript').val('false');
};
return Login;
});