[joomla] Code tip: Clearing errors from display
Gary Mort
garyamort at gmail.com
Thu Jul 1 09:38:35 EDT 2010
I am putting together a SSO set of plugins for IIS using Windows user
accounts.
As such, I am trusting that any user who connects is a valid user and
allowing them to logon.
I have a system plugin which fires first, it checks to make sure we
have a REMOTE_USER set, parses out the username from the domain[using
either slash since Windows except either and lowercase the username].
Then it checks to see if that user is already logged on, if so no
reason to keep going. If not, and the override is set, it will check
to see if the user exists, if the user doesn't exist it creates the
user, and then logs them on[and of course there is an IIS logon module
which returns success for REMOTE_USER's that exist in the user
database].
All good. The only issue I ran into was that the user lookup function
keeps throwing a warning that no user was found[basically, anytime you
use the
Joomla API to look for a user, it generates a user error message
when no user is found. This makes sense when a user is logging on,
it is USELESS when you are looking for a user for other reasons]
Despite auto logging the user on, there still is displayed an error
message that no
user was found.
To work around this, I used the following code:
----
// save the current warning handler
$warnHandlers = JERROR::getErrorHandling( E_WARNING );
// ignore warnings because we expect some users to not exist
JERROR::setErrorHandling(E_WARNING, 'ignore');
// lookup user by name`
$finduser =& JFactory::getUser($username);
// reset the warning handler(s)
foreach($warnHandlers as $mode) {
JERROR::setErrorHandling(E_WARNING, $mode);
}
// if this user does not exist, create it
if (!($finduser)) {
// first we need to clear the error
$userError = JError::getError( true );
jimport('joomla.user.user');
$newuser =& JUser::getInstance(0);
--------
This resets the warning handler to ignore, runs the lookup code, then
resets it to whatever mode(s) where set before. Finally, if the user
did not exist, I know there is an error at the top of the error queue
about that, so I call getError with true set to pop the error and
remove it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/joomla/attachments/20100701/cd8aa16f/attachment.html>
More information about the Joomla
mailing list