From 253d4b48ec708eb42033862dc15c8576f44a48ed Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 1 Oct 2014 15:32:05 +0200 Subject: more PHPDocs, unused var, small bit code reformatting --- lib/plugins/authplain/auth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/plugins/authplain/auth.php') diff --git a/lib/plugins/authplain/auth.php b/lib/plugins/authplain/auth.php index b3ca988b9..1ea75b100 100644 --- a/lib/plugins/authplain/auth.php +++ b/lib/plugins/authplain/auth.php @@ -77,7 +77,7 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { * @author Andreas Gohr * @param string $user * @param bool $requireGroups (optional) ignored by this plugin, grps info always supplied - * @return array|bool + * @return array|false */ public function getUserData($user, $requireGroups=true) { if($this->users === null) $this->_loadUserData(); -- cgit v1.2.3 From 79e79377626799a77c11aa7849cb9c64305590c8 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 7 Jan 2015 10:47:45 +0100 Subject: Remove error supression for file_exists() In an older version of PHP a file_exists() call would issue a warning when the file did not exist. This was fixed in later PHP releases. Since we require PHP 5.3 now, there's no need to supress any error here anymore. This might even give a minor performance boost. --- lib/plugins/authplain/auth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/plugins/authplain/auth.php') diff --git a/lib/plugins/authplain/auth.php b/lib/plugins/authplain/auth.php index fd2d0b249..b31c02fc8 100644 --- a/lib/plugins/authplain/auth.php +++ b/lib/plugins/authplain/auth.php @@ -325,7 +325,7 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { $this->users = array(); - if(!@file_exists($config_cascade['plainauth.users']['default'])) return; + if(!file_exists($config_cascade['plainauth.users']['default'])) return; $lines = file($config_cascade['plainauth.users']['default']); foreach($lines as $line) { -- cgit v1.2.3 From db9faf025cf129d15a086a803e8056e977975d76 Mon Sep 17 00:00:00 2001 From: Patrick Brown Date: Wed, 6 May 2015 01:30:59 -0400 Subject: Report more meaningful errors when an auth backend fails. closes #1093 --- lib/plugins/authplain/auth.php | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'lib/plugins/authplain/auth.php') diff --git a/lib/plugins/authplain/auth.php b/lib/plugins/authplain/auth.php index b31c02fc8..bd46c61a7 100644 --- a/lib/plugins/authplain/auth.php +++ b/lib/plugins/authplain/auth.php @@ -134,7 +134,10 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { global $config_cascade; // user mustn't already exist - if($this->getUserData($user) !== false) return false; + if($this->getUserData($user) !== false) { + msg($this->getLang('userexists'), -1); + return false; + } $pass = auth_cryptPassword($pwd); @@ -144,16 +147,13 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { // prepare user line $userline = $this->_createUserLine($user, $pass, $name, $mail, $grps); - if(io_saveFile($config_cascade['plainauth.users']['default'], $userline, true)) { - $this->users[$user] = compact('pass', 'name', 'mail', 'grps'); - return $pwd; + if(!io_saveFile($config_cascade['plainauth.users']['default'], $userline, true)) { + msg($this->getLang('writefail'), -1); + return null; } - msg( - 'The '.$config_cascade['plainauth.users']['default']. - ' file is not writable. Please inform the Wiki-Admin', -1 - ); - return null; + $this->users[$user] = compact('pass', 'name', 'mail', 'grps'); + return $pwd; } /** @@ -169,7 +169,10 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { global $config_cascade; // sanity checks, user must already exist and there must be something to change - if(($userinfo = $this->getUserData($user)) === false) return false; + if(($userinfo = $this->getUserData($user)) === false) { + msg($this->getLang('usernotexists'), -1); + return false; + } if(!is_array($changes) || !count($changes)) return true; // update userinfo with new data, remembering to encrypt any password @@ -186,13 +189,14 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { $userline = $this->_createUserLine($newuser, $userinfo['pass'], $userinfo['name'], $userinfo['mail'], $userinfo['grps']); if(!$this->deleteUsers(array($user))) { - msg('Unable to modify user data. Please inform the Wiki-Admin', -1); + msg($this->getLang('writefail'), -1); return false; } if(!io_saveFile($config_cascade['plainauth.users']['default'], $userline, true)) { msg('There was an error modifying your user data. You should register again.', -1); // FIXME, user has been deleted but not recreated, should force a logout and redirect to login page + // Should replace the delete/save hybrid modify with an atomic io_replaceInFile $ACT = 'register'; return false; } @@ -223,7 +227,10 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { if(empty($deleted)) return 0; $pattern = '/^('.join('|', $deleted).'):/'; - io_deleteFromFile($config_cascade['plainauth.users']['default'], $pattern, true); + if (!io_deleteFromFile($config_cascade['plainauth.users']['default'], $pattern, true)) { + msg($this->getLang('writefail'), -1); + return 0; + } // reload the user list and count the difference $count = count($this->users); @@ -407,4 +414,4 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { $this->_pattern[$item] = '/'.str_replace('/', '\/', $pattern).'/i'; // allow regex characters } } -} \ No newline at end of file +} -- cgit v1.2.3 From 699e3c4900f2d6cc860a3587a05798cd23b7944d Mon Sep 17 00:00:00 2001 From: Patrick Brown Date: Thu, 7 May 2015 14:27:00 -0400 Subject: Use io_replaceInFile for updating auth --- lib/plugins/authplain/auth.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'lib/plugins/authplain/auth.php') diff --git a/lib/plugins/authplain/auth.php b/lib/plugins/authplain/auth.php index b31c02fc8..35cf7a802 100644 --- a/lib/plugins/authplain/auth.php +++ b/lib/plugins/authplain/auth.php @@ -185,14 +185,9 @@ class auth_plugin_authplain extends DokuWiki_Auth_Plugin { $userline = $this->_createUserLine($newuser, $userinfo['pass'], $userinfo['name'], $userinfo['mail'], $userinfo['grps']); - if(!$this->deleteUsers(array($user))) { - msg('Unable to modify user data. Please inform the Wiki-Admin', -1); - return false; - } - - if(!io_saveFile($config_cascade['plainauth.users']['default'], $userline, true)) { - msg('There was an error modifying your user data. You should register again.', -1); - // FIXME, user has been deleted but not recreated, should force a logout and redirect to login page + if(!io_replaceInFile($config_cascade['plainauth.users']['default'], '/^'.$user.':/', $userline, true)) { + msg('There was an error modifying your user data. You may need to register again.', -1); + // FIXME, io functions should be fail-safe so existing data isn't lost $ACT = 'register'; return false; } -- cgit v1.2.3