From: Michael M Slusarz Date: Thu, 2 Sep 2010 17:15:46 +0000 (-0600) Subject: Request #9211: Improved login error reporting in IMP X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=2a3c7ea011d364b024424b124584a06238ea4310;p=horde.git Request #9211: Improved login error reporting in IMP --- diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index 3496cce95..e6a7984c4 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -2,6 +2,7 @@ v5.0-git -------- +[mms] Improved login error reporting/logging in IMP (Request #9211). [mms] Add hook to skip MDN prompt based on content of message headers. [mms] Allow expand/collapse of folders in MIMP. [mms] Use single, unified mailbox cache. diff --git a/imp/lib/Auth.php b/imp/lib/Auth.php index 5ae6befd4..1eb2bbcb0 100644 --- a/imp/lib/Auth.php +++ b/imp/lib/Auth.php @@ -64,7 +64,8 @@ class IMP_Auth } if (!$imp_imap->createImapObject($credentials['userId'], $credentials['password'], $credentials['server'])) { - self::_logMessage('failed'); + self::_logMessage(false); + Horde::logMessage('Could not create IMAP object', 'ERR'); throw new Horde_Auth_Exception('', Horde_Auth::REASON_FAILED); } } @@ -72,12 +73,33 @@ class IMP_Auth try { $imp_imap->login(); } catch (Horde_Imap_Client_Exception $e) { - self::_logMessage('Login failed', 'INFO'); - if ($e->getCode() == Horde_Imap_Client_Exception::SERVER_CONNECT) { - throw new Horde_Auth_Exception(_("Could not connect to the remote server.")); + self::_logMessage(false); + + switch ($e->getCode()) { + case Horde_Imap_Client_Exception::LOGIN_AUTHENTICATIONFAILED: + case Horde_Imap_Client_Exception::LOGIN_AUTHORIZATIONFAILED: + $code = Horde_Auth::REASON_BADLOGIN; + break; + + case Horde_Imap_Client_Exception::LOGIN_EXPIRED: + $code = Horde_Auth::REASON_EXPIRED; + break; + + case Horde_Imap_Client_Exception::LOGIN_UNAVAILABLE: + $code = Horde_Auth::REASON_MESSAGE; + $e = _("Remove server is down. Please try again later."); + break; + + case Horde_Imap_Client_Exception::LOGIN_NOAUTHMETHOD: + case Horde_Imap_Client_Exception::LOGIN_PRIVACYREQUIRED: + case Horde_Imap_Client_Exception::LOGIN_TLSFAILURE: + case Horde_Imap_Client_Exception::SERVER_CONNECT: + default: + $code = Horde_Auth::REASON_FAILED; + break; } - throw new Horde_Auth_Exception($e->getMessage()); + throw new Horde_Auth_Exception($e, $code); } return false; @@ -118,35 +140,23 @@ class IMP_Auth /** * Log login related message. * - * @param Exception $status Message should contain either 'login', - * 'logout', 'failed', or an error message. - * @param mixed $level The logging level. See Horde::logMessage(). + * @param boolean $success True on success, false on failure. */ - static protected function _logMessage($status, $level) + static protected function _logMessage($status) { - switch ($status) { - case 'login': - $status_msg = 'Login success'; - break; - - case 'logout': - $status_msg = 'Logout'; - break; - - case 'failed': - $status_msg = 'FAILED LOGIN'; - break; - - default: - $status_msg = $status; - break; + if ($status) { + $msg = 'Login success'; + $level = 'NOTICE'; + } else { + $msg = 'FAILED LOGIN'; + $level = 'INFO'; } $auth_id = $GLOBALS['registry']->getAuth(); $imap_ob = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb(); $msg = sprintf( - $status_msg . '%s [%s]%s to {%s:%s%s}', + $msg . ' %s [%s]%s to {%s:%s%s}', !strlen($auth_id) ? '' : ' for ' . $auth_id, $_SERVER['REMOTE_ADDR'], empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? '' : ' (forwarded for [' . $_SERVER['HTTP_X_FORWARDED_FOR'] . '])', @@ -502,7 +512,7 @@ class IMP_Auth /* Check for drafts due to session timeouts. */ $imp_compose = $GLOBALS['injector']->getInstance('IMP_Compose')->getOb()->recoverSessionExpireDraft(); - self::_logMessage('login', 'NOTICE'); + self::_logMessage(true); } /**