Commit 1f3ee1cd96f5eda0814792b13392fdb95a2356eb

Authored by Benjamin Renard
1 parent f437123a

Improve login page (for #6495)

desktop.php
... ... @@ -9,10 +9,19 @@
9 9 require_once('php/config.php');
10 10  
11 11 // error_reporting(E_ALL);
  12 + if (!isset($_POST['username'])) {
  13 + header('Location: index.html');
  14 + exit(1);
  15 + }
  16 +
12 17 if (!isset($_POST['username'])) die('<a href="index.html">LOGIN SVP</a>');
13 18  
14 19 $usrMgr = new UserMgr();
15 20 $sessionID = $usrMgr->init();
  21 + if ($sessionID === FALSE) {
  22 + header('Location: index.html?error=1');
  23 + exit(1);
  24 + }
16 25 ?>
17 26  
18 27 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
... ...
index.html
... ... @@ -13,6 +13,7 @@
13 13 <body>
14 14 <div id="centrage">
15 15  
  16 +
16 17 <div id="trou">
17 18  
18 19 <div id="couvercle"></div>
... ... @@ -20,11 +21,56 @@
20 21 <div id="TousLesBoutons">
21 22 <div id="Btn_FirstVisit" onclick="location.href='help.html';"></div>
22 23 <div id="Btn_Rules" onclick="location.href='help/policy.html';"></div>
23   -<form method="POST" action="desktop.php">
  24 +<form id="Form_Login" method="POST" action="desktop.php" onsubmit="return checkForm(this);">
  25 + <div id="loader" class="loader"></div>
24 26 <input type="text" name="username" placeholder="LOGIN" id="Btn_EnterLogin" class="PlaceHolder" />
25 27 <input type="password" name="password" placeholder="PASSWORD" id="Btn_EnterPassword" class="PlaceHolder"/>
26   - <div><input id="Btn_Login" type="submit" value=""/></div>
27   -</form>
  28 + <div><input id="Btn_Login" name="login" type="submit" value=""/></div>
  29 +</form>
  30 +<script type="text/javascript">
  31 + function setLoginLoader(value) {
  32 + var form = document.getElementById('Form_Login');
  33 + form.elements['username'].readOnly = value;
  34 + form.elements['password'].readOnly = value;
  35 + form.elements['login'].disabled = value;
  36 + document.getElementById("loader").style.display = value ? 'block' : 'none';
  37 + }
  38 +
  39 +
  40 + function checkForm(form)
  41 + {
  42 + if (form.elements['username'].value == "" || form.elements['password'].value == "") {
  43 + alert('Please type your username and password');
  44 + return false;
  45 + }
  46 + setLoginLoader(true);
  47 + return true;
  48 + }
  49 +
  50 + window.onpageshow = function(event) {
  51 + var qs = (function(a) {
  52 + if (a == "") return {};
  53 + var b = {};
  54 + for (var i = 0; i < a.length; ++i)
  55 + {
  56 + var p=a[i].split('=', 2);
  57 + if (p.length == 1)
  58 + b[p[0]] = "";
  59 + else
  60 + b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
  61 + }
  62 + return b;
  63 + })(window.location.search.substr(1).split('&'));
  64 +
  65 + if (qs["error"] && qs["error"] == "1") {
  66 + alert('Cannot connect to AMDA');
  67 + return false;
  68 + }
  69 +
  70 + setLoginLoader(false);
  71 +
  72 + };
  73 +</script>
28 74 <a href="mailto:amda@irap.omp.eu?subject=AMDA registration" id="Btn_Register"></a>
29 75 <a href="mailto:amda@irap.omp.eu?subject=AMDA contact" id="Btn_Contact"></a>
30 76 <div id="Btn_About" onclick="location.href='help/info.html';"></div><div id="textAbout">AMDA Info</div>
... ...
js/resources/css/login.css
... ... @@ -22,3 +22,23 @@ input, textarea { font-family:verdana,tahoma,arial,verdana,sans-serif; font-size
22 22 #field2 { left:540px; top:333px; width:200px; }
23 23 .qo-submit { background:transparent url(../images/login/login.gif) no-repeat 0 0; height:22px; left:705px; top:373px; width:43px; }
24 24 .qo-submit-over { background:transparent url(../images/login/login.gif) no-repeat 0 -38px; height:22px; left:705px; top:373px; width:43px; }
  25 +
  26 +.loader {
  27 + position: absolute;
  28 + left: 50%;
  29 + top: 50%;
  30 + z-index: 999;
  31 + margin: -75px 0 0 -75px;
  32 + border: 16px solid #f3f3f3;
  33 + border-radius: 50%;
  34 + border-top: 16px solid #3498db;
  35 + width: 50px;
  36 + height: 50px;
  37 + animation: spin 2s linear infinite;
  38 + display: none;
  39 +}
  40 +
  41 +@keyframes spin {
  42 + 0% { transform: rotate(0deg); }
  43 + 100% { transform: rotate(360deg); }
  44 +}
... ...
php/classes/UserMgr.php
... ... @@ -535,8 +535,9 @@ class UserMgr
535 535  
536 536 public function init()
537 537 {
538   - if ($this->ddLogin() != 0)
539   - die('<h2>You are trying to log in as '.$this->user.'<br/> Please check that you entered a valid password</h2>');
  538 + if ($this->ddLogin() != 0) {
  539 + return FALSE;
  540 + }
540 541  
541 542 $this->userdir = USERPATH."/".$this->user."/";
542 543  
... ...