aboutsummaryrefslogtreecommitdiff
path: root/static/juandelacosa.js
blob: b4be44ffae9a8809b739d6cbc26212ee4ddafa83 (plain)
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
$(function () {
  var account = $('#account');
  var main = $('#main');
  var noSuchAccount = $('#noSuchAccount');
  var password = $('#password');
  var passwordChanged = $('#passwordChanged');
  var passwordFailed = $('#passwordFailed');
  var resetPassword = $('#resetPassword');

  document.title = window.location.hostname + ' - ' + 'Juan De La Cosa';

  (function whoAmI() {
    $.ajax({
      url: "whoAmI",
      method: "GET",
      success: function (login) {
        noSuchAccount.hide();
        main.show();
        $('#login').val(login);
      },
      error: function (jqXHR, textStatus, errorThrown) {
        if (404 == jqXHR.status) {
          main.hide();
          account.text(jqXHR.responseText);
          noSuchAccount.show();
        }
      },
      complete: setTimeout(whoAmI, 60 * 1000)
    })
  })();

  resetPassword.click(function () {
    $.ajax({
      url: "resetMyPassword",
      method: "POST",
      error: function (jqXHR, textStatus, errorThrown) {
        resetPassword.prop('disabled', true);
        passwordFailed.fadeIn();
        if (0 == jqXHR.readyState) {
          passwordFailed.text('Service unavailable');
        } else {
          passwordFailed.text(errorThrown);
        }
        setTimeout(function () {
          passwordFailed.fadeOut();
          resetPassword.prop('disabled', false);
        }, 5 * 1000);
      },
      success: function (newpwd) {
        resetPassword.hide();
        password.val(newpwd);
        password.show();
        passwordChanged.fadeIn();
        password.select();

        setTimeout(function () {
          passwordChanged.fadeOut();
        }, 5 * 1000);

        setTimeout(function () {
          password.val('');
          password.hide();
          resetPassword.show();
        }, 10 * 1000);
      }
    });
  })
});