From 550d95fadef2213044ac36104a549d0c6151f8cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come.chilliet@fusiondirectory.org> Date: Tue, 23 Jun 2020 15:00:16 +0200 Subject: [PATCH] :ambulance: fix(login) Use new Error classes in login methods issue #6071 --- .../errors/class_FusionDirectoryWarning.inc | 30 +++++++++++++++++++ include/login/class_LoginMethod.inc | 13 ++++---- 2 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 include/errors/class_FusionDirectoryWarning.inc diff --git a/include/errors/class_FusionDirectoryWarning.inc b/include/errors/class_FusionDirectoryWarning.inc new file mode 100644 index 000000000..6422baf70 --- /dev/null +++ b/include/errors/class_FusionDirectoryWarning.inc @@ -0,0 +1,30 @@ +<?php +/* + This code is part of FusionDirectory (http://www.fusiondirectory.org/) + + Copyright (C) 2019-2020 FusionDirectory + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +/*! \class FusionDirectoryWarning +*/ +class FusionDirectoryWarning extends FusionDirectoryError +{ + public function computeMsgDialogParameters (): array + { + return [_('Warning'), $this->htmlMessage, WARNING_DIALOG, static::formatTrace($this)]; + } +} diff --git a/include/login/class_LoginMethod.inc b/include/login/class_LoginMethod.inc index 1753e49f1..183f609d6 100644 --- a/include/login/class_LoginMethod.inc +++ b/include/login/class_LoginMethod.inc @@ -36,7 +36,7 @@ class LoginMethod } /*! \brief Runs schemaCheck if activated in configuration */ - static function runSchemaCheck () + static function runSchemaCheck (): bool { global $config; if ($config->get_cfg_value('schemaCheck') != 'TRUE') { @@ -51,9 +51,10 @@ class LoginMethod foreach ($str as $tr) { if (!$tr['STATUS']) { if ($tr['IS_MUST_HAVE']) { - return htmlescape(_('LDAP schema check reported errors:')).'<br/><br/><i>'.htmlescape($tr['MSG']).'</i>'; + throw new FusionDirectoryError(htmlescape(_('LDAP schema check reported errors:')).'<br/><br/><i>'.htmlescape($tr['MSG']).'</i>'); } else { - msg_dialog::display(_('LDAP schema error'), htmlescape($tr['MSG']), WARNING_DIALOG); + $warning = new FusionDirectoryWarning(nl2br(htmlescape(sprintf(_("LDAP schema error:\n%s"), $tr['MSG'])))); + $warning->display(); } } } @@ -81,7 +82,7 @@ class LoginMethod /*! \brief Check username for invalid characters and check password is not empty * Also trims username */ - static function validateUserInput () + static function validateUserInput (): bool { global $message, $smarty; static::$username = trim(static::$username); @@ -97,7 +98,7 @@ class LoginMethod } /*! \brief Performs an LDAP bind with $username and $password */ - static function ldapLoginUser () + static function ldapLoginUser (): bool { global $ui, $config, $message, $smarty; /* Login as user, initialize user ACL's */ @@ -116,7 +117,7 @@ class LoginMethod } /*! \brief Called after successful login, return FALSE if account is expired */ - static function loginAndCheckExpired () + static function loginAndCheckExpired (): bool { global $ui, $config, $plist, $message, $smarty; -- GitLab