From b204bc362ee899b9c7858cb521a029b800a6be79 Mon Sep 17 00:00:00 2001 From: rurban Date: Mon, 10 Oct 2005 19:43:49 +0000 Subject: [PATCH] add DBAUTH_PREF_INSERT: self-creating users. by John Stevens git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@4898 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/WikiUser/AdoDb.php | 34 ++++++++++++++++++++++++++++------ lib/WikiUser/LDAP.php | 16 ++++++++++------ lib/WikiUser/PearDb.php | 30 +++++++++++++++++++++++++----- 3 files changed, 63 insertions(+), 17 deletions(-) diff --git a/lib/WikiUser/AdoDb.php b/lib/WikiUser/AdoDb.php index a7a3a1055..c71e48185 100644 --- a/lib/WikiUser/AdoDb.php +++ b/lib/WikiUser/AdoDb.php @@ -1,5 +1,5 @@ _prefs->_update)) { $this->getAuthDbh(); $dbh = &$this->_auth_dbi; - $db_result = $dbh->Execute(sprintf($this->_prefs->_update, - $dbh->qstr($packed), - $dbh->qstr($this->_userid))); + // check if the user already exists (not needed with mysql REPLACE) + $rs = $dbh->Execute(sprintf($this->_prefs->_select, $dbh->qstr($this->_userid))); + if ($rs->EOF) { + $rs->Close(); + $prefs_blob = false; + } else { + $prefs_blob = @$rs->fields['prefs']; + $rs->Close(); + } + if ($prefs_blob) { + $db_result = $dbh->Execute(sprintf($this->_prefs->_update, + $dbh->qstr($packed), + $dbh->qstr($this->_userid))); + } else { + // Otherwise, insert a record for them and set it to the defaults. + $dbi = $request->getDbh(); + $this->_prefs->_insert = $this->prepare($dbi->getAuthParam('pref_insert'), + array("pref_blob", "userid")); + $db_result = $dbh->Execute(sprintf($this->_prefs->_insert, + $dbh->qstr($packed), + $dbh->qstr($this->_userid))); + } $db_result->Close(); - //delete pageprefs: + // delete pageprefs: if ($this->_HomePagehandle and $this->_HomePagehandle->get('pref')) $this->_HomePagehandle->set('pref', ''); } else { @@ -253,6 +272,9 @@ extends _DbPassUser } // $Log: not supported by cvs2svn $ +// Revision 1.6 2005/08/06 13:21:09 rurban +// switch to natural order password, userid +// // Revision 1.5 2005/02/14 12:28:26 rurban // fix policy strict. Thanks to Mikhail Vladimirov // @@ -282,4 +304,4 @@ extends _DbPassUser // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: -?> \ No newline at end of file +?> diff --git a/lib/WikiUser/LDAP.php b/lib/WikiUser/LDAP.php index b2c170bb5..742ce41e0 100644 --- a/lib/WikiUser/LDAP.php +++ b/lib/WikiUser/LDAP.php @@ -1,5 +1,5 @@ _ldap, LDAP_AUTH_USER); else $r = true; // anonymous bind allowed - if (!$r) { + if (!$r) { $this->_free(); - trigger_error(sprintf("Unable to bind LDAP server %s", LDAP_AUTH_HOST), + trigger_error(sprintf(_("Unable to bind LDAP server %s using %s %s"), + LDAP_AUTH_HOST, LDAP_AUTH_USER, LDAP_AUTH_PASSWORD), E_USER_WARNING); return false; } @@ -54,14 +55,14 @@ extends _PassUser $this->_authmethod = 'LDAP'; $userid = $this->_userid; if (!$this->isValidName()) { - trigger_error(_("Invalid username."),E_USER_WARNING); + trigger_error(_("Invalid username."), E_USER_WARNING); return $this->_tryNextPass($submitted_password); } if (!$this->_checkPassLength($submitted_password)) { return WIKIAUTH_FORBIDDEN; } if (strstr($userid,'*')) { - trigger_error(fmt("Invalid username '%s' for LDAP Auth",$userid), + trigger_error(fmt("Invalid username '%s' for LDAP Auth", $userid), E_USER_WARNING); return WIKIAUTH_FORBIDDEN; } @@ -135,6 +136,9 @@ extends _PassUser } // $Log: not supported by cvs2svn $ +// Revision 1.4 2004/12/26 17:11:17 rurban +// just copyright +// // Revision 1.3 2004/12/20 16:05:01 rurban // gettext msg unification // @@ -158,4 +162,4 @@ extends _PassUser // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: -?> \ No newline at end of file +?> diff --git a/lib/WikiUser/PearDb.php b/lib/WikiUser/PearDb.php index 19fa73a2a..e6d970353 100644 --- a/lib/WikiUser/PearDb.php +++ b/lib/WikiUser/PearDb.php @@ -1,5 +1,5 @@ _prefs->store(); if (!$id_only and isset($this->_prefs->_update)) { $dbh = &$this->_auth_dbi; - $dbh->simpleQuery(sprintf($this->_prefs->_update, - $dbh->quote($packed), - $dbh->quote($this->_userid))); + // check if the user already exists (not needed with mysql REPLACE) + $db_result = $dbh->query(sprintf($this->_prefs->_select, + $dbh->quote($this->_userid))); + $prefs = $db_result->fetchRow(); + $prefs_blob = @$prefs["prefs"]; + // If there are prefs for the user, update them. + if($prefs_blob != "" ){ + $dbh->simpleQuery(sprintf($this->_prefs->_update, + $dbh->quote($packed), + $dbh->quote($this->_userid))); + } else { + // Otherwise, insert a record for them and set it to the defaults. + // johst@deakin.edu.au + $dbi = $GLOBALS['request']->getDbh(); + $this->_prefs->_insert = $this->prepare($dbi->getAuthParam('pref_insert'), + array("pref_blob", "userid")); + $dbh->query(sprintf($this->_prefs->_insert, + $dbh->quote($packed), + $dbh->quote($this->_userid))); + } //delete pageprefs: if ($this->_HomePagehandle and $this->_HomePagehandle->get('pref')) $this->_HomePagehandle->set('pref', ''); @@ -224,6 +241,9 @@ extends _DbPassUser } // $Log: not supported by cvs2svn $ +// Revision 1.8 2005/08/06 13:21:09 rurban +// switch to natural order password, userid +// // Revision 1.7 2005/02/14 12:28:27 rurban // fix policy strict. Thanks to Mikhail Vladimirov // @@ -263,4 +283,4 @@ extends _DbPassUser // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: -?> \ No newline at end of file +?> -- 2.45.2