From 506331f45ca85950b79167a2f9078a4db8c40a09 Mon Sep 17 00:00:00 2001
From: Thijs Kinkhorst <thijs@kinkhorst.com>
Date: Mon, 30 Mar 2015 16:03:00 +0000
Subject: [PATCH] Disable login button with JS after first click.

Impatient users will press the button twice which leads (esp in Chrome it seems) to NOSTATE errors.
---
 dictionaries/login.definition.json       | 3 +++
 modules/core/templates/loginuserpass.php | 6 +++---
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/dictionaries/login.definition.json b/dictionaries/login.definition.json
index 6399256a6..49ebed33e 100644
--- a/dictionaries/login.definition.json
+++ b/dictionaries/login.definition.json
@@ -11,6 +11,9 @@
 	"login_button": {
 		"en": "Login"
 	},
+	"processing": {
+		"en": "Processing..."
+	},
 	"username": {
 		"en": "Username"
 	},
diff --git a/modules/core/templates/loginuserpass.php b/modules/core/templates/loginuserpass.php
index a0ccb0061..7b39963c2 100644
--- a/modules/core/templates/loginuserpass.php
+++ b/modules/core/templates/loginuserpass.php
@@ -67,7 +67,7 @@ if ($this->data['rememberUsernameEnabled'] || $this->data['rememberMeEnabled'])
 } else {
 	$text = $this->t('{login:login_button}');
 	echo str_repeat("\t", 4);
-	echo "<input type=\"submit\" tabindex=\"4\" id=\"regularsubmit\" value=\"{$text}\" />";
+	echo "<input onclick=\"this.value='" . $this->t('{login:processing}') . "';this.disabled=true;this.form.submit();return true;\" type=\"submit\" tabindex=\"4\" id=\"regularsubmit\" value=\"{$text}\" />";
 }
 ?>
 			</td>
@@ -81,7 +81,7 @@ if ($this->data['rememberUsernameEnabled'] || $this->data['rememberMeEnabled'])
 	$rowspan = (array_key_exists('organizations', $this->data) ? 2 : 1);
 ?>
 			<td style="padding: .4em;" rowspan="<?php echo $rowspan; ?>">
-				<input type="submit" tabindex="5" id="regularsubmit" value="<?php echo $this->t('{login:login_button}'); ?>" />
+				<input onclick="this.value='<?php echo $this->t('{login:processing}'); ?>';this.disabled=true;this.form.submit();return true;" type="submit" tabindex="5" id="regularsubmit" value="<?php echo $this->t('{login:login_button}'); ?>" />
 			</td>
 <?php
 }
@@ -121,7 +121,7 @@ foreach ($this->data['organizations'] as $orgId => $orgDesc) {
 }
 ?>
 	<tr><td></td><td>
-	<input type="submit" tabindex="5" id="mobilesubmit" value="<?php echo $this->t('{login:login_button}'); ?>" />
+	<input onclick="this.value='<?php echo $this->t('{login:processing}'); ?>';this.disabled=true;this.form.submit();return true;" type="submit" tabindex="5" id="mobilesubmit" value="<?php echo $this->t('{login:login_button}'); ?>" />
 	</td></tr>
 	</table>
 <?php
-- 
GitLab