From 4f61950dadc43d4504617fa667d8f9efacc0d1a3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no>
Date: Thu, 27 Mar 2008 06:06:36 +0000
Subject: [PATCH] Adding automatically focus on login form + minor template and
 auth module template tidying.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@431 44740490-163a-0410-bde0-09ae8108e29a
---
 dictionaries/login.php            | 14 ++++-
 lib/SimpleSAML/XHTML/Template.php | 29 ++--------
 templates/default/login.php       | 91 ++++++++++++++++---------------
 www/auth/login-ldapmulti.php      |  2 +-
 www/auth/login.php                | 24 +++-----
 5 files changed, 75 insertions(+), 85 deletions(-)

diff --git a/dictionaries/login.php b/dictionaries/login.php
index 8696635c1..36e1d082a 100644
--- a/dictionaries/login.php
+++ b/dictionaries/login.php
@@ -4,8 +4,8 @@ $lang = array(
 
 
 	'error_header' => array(
-		'en' => 'What you entered was not accepted!',
-		'no' => 'Feil under innlogging',
+		'en' => 'Error',
+		'no' => 'Error',
 	),
 	'user_pass_header' => array(
 		'en' => 'Enter your username and password',
@@ -38,5 +38,15 @@ $lang = array(
 		'no' => 'Synd! - Uten riktig brukernavn og passord kan du ikke autentisere deg. Det kan være noen som kan hjelpe deg. Forsøk å kontakt help-desk hos din hjemmeorganisasjon.',
 	),
 
+	'error_nopassword' => array(
+		'en' => 'You sent something to the login page, but for some reason the password was not sent. Try again please.',
+		'no' => 'Du kontaktet loginsiden, men passordet ble ikke sendt med. Forsøk igjen.',
+	),	
+
+	'error_wrongpassword' => array(
+		'en' => 'Wrong username or password.',
+		'no' => 'Feil brukernavn eller passord.',
+	),	
+
 	
 );
\ No newline at end of file
diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php
index fe70ff62a..2a0596f63 100644
--- a/lib/SimpleSAML/XHTML/Template.php
+++ b/lib/SimpleSAML/XHTML/Template.php
@@ -53,7 +53,10 @@ class SimpleSAML_XHTML_Template {
 		
 		// Language is not set, and we get the default language from the configuration.
 		} else {
-			return $this->getDefaultLanguage('language.default');
+		
+			#$nego = http_negotiate_language($this->configuration->getValue('language.available'));
+		
+			return $this->getDefaultLanguage();
 		}
 		
 		return $this->language;
@@ -104,25 +107,8 @@ class SimpleSAML_XHTML_Template {
 		include($filename);
 	}
 
-	private function includeAtLanguageBase($file) {
-	
+	private function includeAtLanguageBase($file) {	
 		throw new Exception('Deprecated method call includeAtLanguageBase()');
-	/*
-		$data = $this->data;
-		$filebase = $this->configuration->getPathValue('templatedir') . $this->getLanguage() . '/' ;
-		
-		if (!file_exists($filebase . $file)) {
-			$filebase = $this->configuration->getPathValue('templatedir') . 
-				$this->configuration->getValue('language.default') . '/';
-				
-			
-			if (!file_exists($filebase . $file) ) {
-				SimpleSAML_Logger::error($_SERVER['PHP_SELF'].' - Template: Could not find template file [' . $this->template . '] at [' . $filename . ']');
-				return;
-			}
-		}
-		include($filebase . $file);
-		*/
 	}
 	
 	
@@ -142,9 +128,6 @@ class SimpleSAML_XHTML_Template {
 			return $this->t_not_translated($tag, $fallbacktag);
 		}
 
-#		echo 'LANGTEXT: ';
-#		print_r($this->langtext);
-
 		$selected_language = $this->getLanguage();
 		$default_language  = $this->getDefaultLanguage();
 		
@@ -217,8 +200,6 @@ class SimpleSAML_XHTML_Template {
 	 */
 	public function show() {
 	
-		
-
 		$filename  = $this->configuration->getPathValue('templatedir') . 
 			$this->configuration->getValue('theme.use') . '/' . $this->template;
 		
diff --git a/templates/default/login.php b/templates/default/login.php
index b67313bc3..6dc9a8c38 100644
--- a/templates/default/login.php
+++ b/templates/default/login.php
@@ -2,51 +2,56 @@
 	if (!array_key_exists('icon', $this->data)) $this->data['icon'] = 'lock.png';
 	$this->includeAtTemplateBase('includes/header.php'); 
 ?>
+	<script type="text/javascript">
+		function focusit() {
+			document.getElementById('username').focus();
+		}
+		window.onload = focusit;
+	</script>
+<div id="content">
 
-	<div id="content">
-	
-		<?php if (isset($this->data['error'])) { ?>
-			<div style="border-left: 1px solid #e8e8e8; border-bottom: 1px solid #e8e8e8; background: #f5f5f5"
-			<img src="/<?php echo $this->data['baseurlpath']; ?>resources/icons/bomb.png" style="float: left; margin: 15px " />
-			<h2><?php echo $this->t('error_header'); ?></h2>
-			
-			<p><?php echo htmlspecialchars($this->data['error']); ?> </p>
-			</div>
-		<?php } ?>
-	
-		<h2 style="break: both"><?php echo $this->t('user_pass_header'); ?></h2>
-		
-		<p><?php echo $this->t('user_pass_text'); ?></p>
-		
-		<form action="?" method="post" name="f">
+	<?php if (isset($this->data['error'])) { ?>
+		<div style="border-left: 1px solid #e8e8e8; border-bottom: 1px solid #e8e8e8; background: #f5f5f5">
+		<img src="/<?php echo $this->data['baseurlpath']; ?>resources/icons/bomb.png" style="float: left; margin: 15px " />
+		<h2><?php echo $this->t('error_header'); ?></h2>
+		
+		<p><?php echo $this->t($this->data['error']); ?> </p>
+		</div>
+	<?php } ?>
 
-		<table>
-			<tr>
-				<td rowspan="2"><img src="/<?php echo $this->data['baseurlpath']; ?>resources/icons/pencil.png" /></td>
-				<td style="padding: .3em;"><?php echo $this->t('username'); ?></td>
-				<td><input type="text" tabindex="1" name="username" 
-					<?php if (isset($this->data['username'])) {
-						echo 'value="' . htmlspecialchars($this->data['username']) . '"';
-					} ?> /></td>
-				<td style="padding: .4em;" rowspan="2">
-					<input type="submit" tabindex="3" value="<?php echo $this->t('login_button'); ?>" />
-					<input type="hidden" name="RelayState" value="<?php echo htmlspecialchars($this->data['relaystate']); ?>" />
-				</td>
-			</tr>
-			<tr>
-				<td style="padding: .3em;"><?php echo $this->t('password'); ?></td>
-				<td><input type="password" tabindex="2" name="password" /></td>
-			</tr>
-		</table>
-		
-		
-		</form>
-		
-		
-		<h2><?php echo $this->t('help_header'); ?></h2>
-		
-		
-		<p><?php echo $this->t('help_text'); ?></p>
+	<h2 style="break: both"><?php echo $this->t('user_pass_header'); ?></h2>
+	
+	<p><?php echo $this->t('user_pass_text'); ?></p>
+	
+	<form action="?" method="post" name="f">
+
+	<table>
+		<tr>
+			<td rowspan="2"><img src="/<?php echo $this->data['baseurlpath']; ?>resources/icons/pencil.png" /></td>
+			<td style="padding: .3em;"><?php echo $this->t('username'); ?></td>
+			<td><input type="text" id="username" tabindex="1" name="username" 
+				<?php if (isset($this->data['username'])) {
+					echo 'value="' . htmlspecialchars($this->data['username']) . '"';
+				} ?> /></td>
+			<td style="padding: .4em;" rowspan="2">
+				<input type="submit" tabindex="3" value="<?php echo $this->t('login_button'); ?>" />
+				<input type="hidden" name="RelayState" value="<?php echo htmlspecialchars($this->data['relaystate']); ?>" />
+			</td>
+		</tr>
+		<tr>
+			<td style="padding: .3em;"><?php echo $this->t('password'); ?></td>
+			<td><input type="password" tabindex="2" name="password" /></td>
+		</tr>
+	</table>
+	
+	
+	</form>
+	
+	
+	<h2><?php echo $this->t('help_header'); ?></h2>
+	
+	
+	<p><?php echo $this->t('help_text'); ?></p>
 	
 
 <?php $this->includeAtTemplateBase('includes/footer.php'); ?>
\ No newline at end of file
diff --git a/www/auth/login-ldapmulti.php b/www/auth/login-ldapmulti.php
index db0661715..e7ad280ea 100644
--- a/www/auth/login-ldapmulti.php
+++ b/www/auth/login-ldapmulti.php
@@ -59,7 +59,7 @@ if (isset($_POST['username'])) {
 			exit;
 			}
 			*/
-			if (!ldap_bind($ds, $dn, $pwd)) {
+			if (!@ldap_bind($ds, $dn, $pwd)) {
 				$error = 'Bind failed, wrong username or password.' .
 					' Tried with DN=[' . $dn . '] DNPattern=[' .
 					$ldapconfig['dnpattern'] . '] Error=[' .
diff --git a/www/auth/login.php b/www/auth/login.php
index c3e31188a..900235a77 100644
--- a/www/auth/login.php
+++ b/www/auth/login.php
@@ -46,7 +46,7 @@ if (isset($_POST['username'])) {
 	
 		/* First, make sure that the password field is included. */
 		if (!array_key_exists('password', $_POST)) {
-			$error = 'You sent something to the login page, but for some reason the password was not sent. Try again please.';
+			$error = 'error_nopassword'; 
 			continue;
 		}
 	
@@ -67,22 +67,21 @@ if (isset($_POST['username'])) {
 		$ldap = new SimpleSAML_Auth_LDAP($ldapconfig->getValue('auth.ldap.hostname'),
                                          $ldapconfig->getValue('auth.ldap.enable_tls'));
 	
-		/* Insert the LDAP username into the pattern configured in the
-		 * 'auth.ldap.dnpattern' option.
+		
+		
+		
+		/** 
+		 * Insert the LDAP username into the pattern configured in the 'auth.ldap.dnpattern' option.
 		 */
-		$dn = str_replace('%username%', $ldapusername,
-						  $ldapconfig->getValue('auth.ldap.dnpattern'));
+		$dn = str_replace('%username%', $ldapusername, $ldapconfig->getValue('auth.ldap.dnpattern'));
 	
-		/* Connect to the LDAP server. */
-		#$ds = ldap_connect($ldapconfig->getValue('auth.ldap.hostname'));
-		
 		
 		/*
 		 * Do LDAP bind using DN found from the the dnpattern
 		 */
 		if (!$ldap->bind($dn, $password)) {
 			SimpleSAML_Logger::info('AUTH - ldap: '. $username . ' failed to authenticate. DN=' . $dn);
-			throw new Exception('Wrong username or password');
+			throw new Exception('error_wrongpassword');
 		}
 
 		/*
@@ -109,16 +108,11 @@ if (isset($_POST['username'])) {
 		else 
 			SimpleSAML_Logger::stats('AUTH-login OK');
 			
-			
-		
-		
+
 		$returnto = $_REQUEST['RelayState'];
 		SimpleSAML_Utilities::redirect($returnto);	
 		
 		
-		
-		
-		
 	} catch (Exception $e) {
 		SimpleSAML_Logger::error('AUTH - ldap: User: '.(isset($requestedUser) ? $requestedUser : 'na'). ':'. $e->getMessage());
 		SimpleSAML_Logger::stats('AUTH-login Failed');
-- 
GitLab