Author:   Lars Michelsen <[email protected]>
Date:     Sun Nov 27 18:00:04 2011 +0100
Committer:   Lars Michelsen <[email protected]>
Commit-Date: Sun Nov 27 18:00:04 2011 +0100

Added error messages to login dialog on login failure

---

 TODO                                               |    3 -
 .../frontend/nagvis-js/classes/NagVisLoginView.php |    2 +
 .../server/core/classes/CoreLogonDialogHandler.php |   51 ++++++++++++--------
 share/server/core/functions/index.php              |    1 +
 share/userfiles/templates/default.login.css        |   11 ++++-
 share/userfiles/templates/default.login.html       |    3 +
 6 files changed, 46 insertions(+), 25 deletions(-)

diff --git a/TODO b/TODO
index 4e72259..a872c48 100644
--- a/TODO
+++ b/TODO
@@ -11,9 +11,6 @@ Relative Koordinaten:
 - Sidebar Folder auf/zu klappbar
 - In Sidebar/Dropdown die aktuelle Map highlighten
 
-- Erster AJAX request geht schief (You are not authenticated)
-- omdadmin Passwort ist offensichtlich nicht omd
-
 -------------------------------------------------------------------------------
 
 - NagVis Multisite Snapin optional als Baum
diff --git a/share/frontend/nagvis-js/classes/NagVisLoginView.php 
b/share/frontend/nagvis-js/classes/NagVisLoginView.php
index 427bccf..48c56c9 100644
--- a/share/frontend/nagvis-js/classes/NagVisLoginView.php
+++ b/share/frontend/nagvis-js/classes/NagVisLoginView.php
@@ -45,6 +45,7 @@ class NagVisLoginView {
      * @author         Lars Michelsen <[email protected]>
      */
     public function parse() {
+        global $LOGIN_MSG;
         // Initialize template system
         $TMPL = New FrontendTemplateSystem($this->CORE);
         $TMPLSYS = $TMPL->getTmplSys();
@@ -72,6 +73,7 @@ class NagVisLoginView {
             'langLogin' => l('Login'),
             'langTitleCookiesDisabled' => l('Cookies disabled'),
             'langTextCookiesDisabled' => l('NagVis is unable to set a cookie 
in your browser. Please enable cookies for at least the NagVis host.'),
+            'loginMsg' => isset($LOGIN_MSG)  && $LOGIN_MSG !== null ? 
$LOGIN_MSG->msg : '',
         );
 
         // Build page based on the template file and the data array
diff --git a/share/server/core/classes/CoreLogonDialogHandler.php 
b/share/server/core/classes/CoreLogonDialogHandler.php
index a127899..dc56c4d 100644
--- a/share/server/core/classes/CoreLogonDialogHandler.php
+++ b/share/server/core/classes/CoreLogonDialogHandler.php
@@ -27,25 +27,32 @@ class CoreLogonDialogHandler {
     public function check($printErr = true) {
         global $AUTH;
 
-        $data = $this->handleResponseAuth();
-        if($data !== false) {
-            // Set credentials to authenticate
-            $AUTH->setTrustUsername(false);
-            $AUTH->setLogoutPossible(true);
-            $AUTH->passCredentials($data);
+        $err = null;
+        try {
+            $data = $this->handleResponseAuth();
+            if($data !== null) {
+                // Set credentials to authenticate
+                $AUTH->setTrustUsername(false);
+                $AUTH->setLogoutPossible(true);
+                $AUTH->passCredentials($data);
 
-            // Try to authenticate the user
-            $result = $AUTH->isAuthenticated();
-            if($result === true) {
-                // Success: Store in session
-                $AUTH->storeInSession();
-                return true;
+                // Try to authenticate the user
+                $result = $AUTH->isAuthenticated();
+                if($result === true) {
+                    // Success: Store in session
+                    $AUTH->storeInSession();
+                    return true;
+                } else {
+                    throw new FieldInputError(null, l('Authentication 
failed.'));
+                }
             }
+        } catch(FieldInputError $e) {
+            $err = $e;
         }
 
         // Failed!
         if(!CONST_AJAX) {
-            return array('LogonDialog', 'view');
+            return array('LogonDialog', 'view', $err);
         } else {
             throw new NagVisException(l('You are not authenticated'), null, 
l('Access denied'));
         }
@@ -57,14 +64,16 @@ class CoreLogonDialogHandler {
 
         $FHANDLER = new CoreRequestHandler($_POST);
 
-        if(!$FHANDLER->match('username', MATCH_USER_NAME))
-            return false;
-        if(!$FHANDLER->issetAndNotEmpty('password'))
-            return false;
-        if($FHANDLER->isLongerThan('username', AUTH_MAX_USERNAME_LENGTH))
-            return false;
-        if($FHANDLER->isLongerThan('password', AUTH_MAX_PASSWORD_LENGTH))
-            return false;
+        if(!$FHANDLER->issetAndNotEmpty('username') && 
!$FHANDLER->issetAndNotEmpty('password'))
+            return null;
+
+        if(!$FHANDLER->match('username', MATCH_USER_NAME)
+           || $FHANDLER->isLongerThan('username', AUTH_MAX_USERNAME_LENGTH))
+            throw new FieldInputError('username', l('Invalid username.'));
+
+        if(!$FHANDLER->issetAndNotEmpty('password')
+           || $FHANDLER->isLongerThan('password', AUTH_MAX_PASSWORD_LENGTH))
+            throw new FieldInputError('password', l('Invalid password.'));
 
         return Array('user'     => $FHANDLER->get('username'),
                      'password' => $FHANDLER->get('password'));
diff --git a/share/server/core/functions/index.php 
b/share/server/core/functions/index.php
index 862cf0f..8bf290e 100644
--- a/share/server/core/functions/index.php
+++ b/share/server/core/functions/index.php
@@ -58,6 +58,7 @@ if(!($AUTH->sessionAuthPresent() && 
$AUTH->isAuthenticatedSession())) {
     if(is_array($ret)) {
         $UHANDLER->set('mod', $ret[0]);
         $UHANDLER->set('act', $ret[1]);
+        $LOGIN_MSG = $ret[2];
     }
 }
 
diff --git a/share/userfiles/templates/default.login.css 
b/share/userfiles/templates/default.login.css
index d8a341b..3e4bf76 100644
--- a/share/userfiles/templates/default.login.css
+++ b/share/userfiles/templates/default.login.css
@@ -22,6 +22,15 @@ form {
 
 form .forgetmenot { font-weight: normal; float: left; margin-bottom: 0; }
 
+#login form .msg {
+    font-size: 14px;
+    text-align: center;
+    margin-bottom: 10px;
+}
+#login form .msg strong {
+    color: #ff0000;
+}
+
 #login form .submit input {
     font-family: "Lucida Grande", Verdana, Arial, "Bitstream Vera Sans", 
sans-serif;
     padding: 3px 10px;
@@ -94,4 +103,4 @@ h1 a {
 
 .clear {
     clear: both;
-}
\ No newline at end of file
+}
diff --git a/share/userfiles/templates/default.login.html 
b/share/userfiles/templates/default.login.html
index 51efbcc..20c2ca2 100644
--- a/share/userfiles/templates/default.login.html
+++ b/share/userfiles/templates/default.login.html
@@ -35,6 +35,9 @@
 <h1><a href="#" title="{$pageTitle}" 
style="background-image:url({$htmlImages}internal/logo.png)">{$pageTitle}</a></h1>
 
 <form name="loginform" id="loginform" action="{$formTarget}" method="post">
+    {if $loginMsg != ''}<p class="msg">
+    <strong>Error:</strong> {$loginMsg}
+    </p>{/if}
     <p>
         <label>{$langName}<br />
         <input type="text" name="username" id="user_login" class="input" 
value="" size="{$maxUsernameLength}" tabindex="10" /></label>


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to