Success

User tests: Successful: Unsuccessful:

avatar wilsonge
wilsonge
16 Mar 2013

I'm following (with a slight tweak of the foreach statement) example 2 of the JFactory::getUser() docs page here (http://docs.joomla.org/JFactory/getUser)

$users[0]='admin';    //Some user that exists
$users[1]='joeblogs';  // Some user that doesn't exist
foreach($users as $name) {
        $user =& JFactory::getUser( $name );
    if ($user->id == 0) {
            echo 'There is no user '.$name.' registered on this site.';
    } else {
        echo 'User name: ' . $user->username;
        echo 'Real name: ' . $user->name;
        echo 'User ID : ' . $user->id; 
    }
}

Now the docs state when searching for a user that "information about a specific user, with username 'joebloggs', is displayed, regardless of the status of the current user."

So when you run this when logged out you find you get "There is no user admin registered on this site.There is no user joeblogs registered on this site." whereas you actually should see admin does exist as a user. And if you are logged in then you find a JLog (or whatever its called now) is thrown for the joebloggs user of "JUser: :_load: User joeblogs does not exist" and a php warning is also thrown that the line "if ($user->id == 0) {" is "Trying to get property of non-object". And the admin properties display as expected.

This JLog is thrown on line 245 of libraries/joomla/user/user.php : " JLog::add(JText::sprintf('JLIB_USER_ERROR_ID_NOT_EXISTS', $identifier), JLog::WARNING, 'jerror');" in joomla 3.0 (this may have changed since I guess).

Now this is definitely NOT the behavior documented and this needs to be resolved. Personally I prefer the documented behavior (although i guess that's open to you guys).

I chucked in a couple of commits on the platform pull request I made for this a couple of months ago here (it's just got closed as its being referred back to the CMS as the platform is closing) - although there was debate about whether my code was the best way to restore the behaviour

Initial Request: joomla/joomla-platform#1810

Joomla Tracker Code:

http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=29986

avatar wilsonge wilsonge - open - 16 Mar 2013
avatar alwarren
alwarren - comment - 17 Mar 2013

This appears to be a type comparison issue. Check around line 223 of /ibraries/joomla/factory.php:

if ($current->id != $id)

$current->id will always be an integer. When we pass a string to $id, we're comparing an integer to a string. In PHP, the == operator (or !=) will convert a string to a number before doing the comparison. A non-numeric string gets converted to zero which in this case is equivalent. So, we will always pass back the session user instead of fetching a user by username.

avatar alwarren
alwarren - comment - 17 Mar 2013

For security reasons, I probably wouldn't do any error output if 'someuser' isn't found.

avatar wilsonge
wilsonge - comment - 17 Mar 2013

I wouldn't output the error :) But partially I would like the docs to work as they say they do and mainly - I had a list of potential usernames and I wanted to see which tied up with usernames on my site and which didn't. That was my overall aim for this code.

avatar wilsonge
wilsonge - comment - 31 Mar 2013

Moved the commits over onto the CMS side

avatar ShMaunder
ShMaunder - comment - 7 Aug 2013

Good catch, I never noticed this inconsistent behaviour. I decided to try a few things myself and found a few minor issues with the patch. One of these is that the ID is only checked in the JFactory::getUser() method from the session. I would propose something along the lines of: commit f586732 (embedded below - I don't know how to correctly link) with commit 4db79a5 you proposed.

$instance = self::getSession()->get('user');

if (is_null($id))
{
 if (!($instance instanceof JUser))
 {
  $instance = JUser::getInstance();
 }
}
elseif (!$instance->id)
{
 $instance = JUser::getInstance($id);
}
 elseif (is_numeric($id) ? ($instance->id != $id) : ($instance->username != $id))
{
 $instance = JUser::getInstance($id);
}

return $instance;

Something I also witnessed is the inconsistency of a "blank" JUser object which related to whether JUser::load() with an invalid ID is used - though I believe that doesn't belong in this pull.

avatar brianteeman
brianteeman - comment - 23 Jul 2014

@wilsonge what is the status of this please?

avatar wilsonge
wilsonge - comment - 23 Jul 2014

hell. this was my first ever pr to joomla :P there's all kinds of b/c issues with this but it's also completely different to what the docs say.......

I really have no clue what to do with it. @mbabker / @dbhurley / @Bakual / any other PLT dudes dunno if you guys have any comments?

avatar dbhurley
dbhurley - comment - 23 Jul 2014

My first thought is probably to close the PR until it's ready for merging.
:)

Congrats on finding your first! You've done a lot of great things since.
On Jul 23, 2014 8:17 AM, "George Wilson" notifications@github.com wrote:

hell. this was my first ever pr to joomla :P there's all kinds of b/c
issues with this but it's also completely different to what the docs
say.......

I really have no clue what to do with it. @mbabker
https://github.com/mbabker / @dbhurley https://github.com/dbhurley
dunno if you guys have any comments?


Reply to this email directly or view it on GitHub
#811 (comment).

avatar wilsonge
wilsonge - comment - 23 Jul 2014

It is ready for merging. So the PR now follows what the docs says. And what I'd say is more intuitively correct. But technically that comes with a b/c incompatibility..... (which is currently why the test fails - the test is really easy to fix if people are happy with it but point stands)

avatar Bakual
Bakual - comment - 23 Jul 2014

Travis yells at your first PR :smile:
The B/C would be that you now return an empty JUser instead of the wrong "false". There is another case a bit later in code where an empty JUser is returned. So any extension using this probably already can deal with an empty JUser object and thus nothing should break in theory.
Is there another B/C?

avatar wilsonge
wilsonge - comment - 23 Jul 2014

Not that I'm aware of - expect you pass in an ID and it will actually return the user object now you requested now :P

avatar wilsonge
wilsonge - comment - 23 Jul 2014

btw travis wasn't being used when my first pr was made :P

avatar Bakual
Bakual - comment - 23 Jul 2014

btw travis wasn't being used when my first pr was made :package:

I'm aware of that :smile:

avatar roland-d
roland-d - comment - 20 Aug 2014

@test: After applying the PR I get the information about the user correctly.
You may blame the J!Tracker Application at http://issues.joomla.org/ for transmitting this comment.

avatar brianteeman brianteeman - change - 21 Aug 2014
Status New Pending
Build .
avatar b2z
b2z - comment - 17 Sep 2014

@test all good! I get the information about the users correctly.

This comment was created with the J!Tracker Application at http://issues.joomla.org/.

avatar zero-24 zero-24 - change - 17 Sep 2014
Category Libraries
avatar zero-24 zero-24 - change - 17 Sep 2014
Status Pending Ready to Commit
Build . master/staging
avatar zero-24
zero-24 - comment - 17 Sep 2014

thanks @b2z moving to RTC

This comment was created with the J!Tracker Application at http://issues.joomla.org/.

avatar wilsonge
wilsonge - comment - 17 Sep 2014

First ever PR to Joomla RTC. I can now stop :P :P

avatar Bakual
Bakual - comment - 17 Sep 2014

I can now stop

Don't you dare!

avatar zero-24 zero-24 - change - 17 Sep 2014
Status Ready to Commit Pending
avatar wilsonge wilsonge - change - 17 Sep 2014
Title
JFactory::getUser()
[#29986] JFactory::getUser()
avatar wilsonge wilsonge - change - 17 Sep 2014
Title
JFactory::getUser()
[#29986] JFactory::getUser()
avatar b2z
b2z - comment - 17 Sep 2014

More I am thinking about it more my mind is blown :anguished:

avatar wilsonge
wilsonge - comment - 17 Sep 2014

No because it's a or statement. the entire thing is true if one side or the other is true. It's only with an and statement that that's the case

avatar b2z
b2z - comment - 17 Sep 2014

Ok shame on me... So if ID is a string then the entire thing is true and we do not compare ids at all?

avatar beat
beat - comment - 17 Sep 2014

Why was my PR https://github.com/beat/joomla-cms/compare/wilsonge:userjfact...patch-6?quick_pull=1 ignored ? anything wrong with it ?

The is_string test above is not right, as it ignores numeric strings that should be handled as ids for B/C.

This is security-relevant stuff, so we should not take it lightly.

avatar wilsonge
wilsonge - comment - 17 Sep 2014

Beat I didn't ignore you PR at all. If you look I commented on it after you pasted the link above.

avatar beat
beat - comment - 17 Sep 2014

@wilsonge thanks for the reply. Missed it as it got hidden by github together with my line-comment after the line got changed.

avatar brianteeman
brianteeman - comment - 16 Oct 2014

Is this RTC ? Travis failed?

This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/811.

avatar wilsonge
wilsonge - comment - 17 Oct 2014

Travis fixed

avatar jissues-bot jissues-bot - change - 17 Oct 2014
Title
[#29986] JFactory::getUser()
JFactory::getUser()
avatar brianteeman brianteeman - change - 17 Oct 2014
Title
[#29986] JFactory::getUser()
JFactory::getUser()
avatar brianteeman
brianteeman - comment - 17 Oct 2014

OK setting to RTC then

This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/811.

avatar brianteeman brianteeman - change - 17 Oct 2014
Status Pending Ready to Commit
avatar wilsonge wilsonge - change - 17 Oct 2014
Title
JFactory::getUser()
[#29986] JFactory::getUser()
avatar nicksavov nicksavov - change - 17 Oct 2014
Labels Added: ?
avatar nicksavov nicksavov - change - 17 Oct 2014
Title
JFactory::getUser()
[#29986] JFactory::getUser()
avatar jissues-bot jissues-bot - change - 17 Oct 2014
Labels Added: ?
avatar infograf768
infograf768 - comment - 19 Oct 2014

Can you make it a PR towards staging please?

avatar Bakual
Bakual - comment - 22 Oct 2014

Merged into staging. Thanks!

And with that closed the oldest still open PR :smile:

avatar Bakual Bakual - close - 22 Oct 2014
avatar Bakual Bakual - close - 22 Oct 2014
avatar Bakual Bakual - change - 22 Oct 2014
Status Ready to Commit Closed
Closed_Date 0000-00-00 00:00:00 2014-10-22 18:41:45
avatar wilsonge wilsonge - head_ref_deleted - 22 Oct 2014
avatar wilsonge
wilsonge - comment - 22 Oct 2014

I quit! My work here is done :P

avatar Bakual
Bakual - comment - 22 Oct 2014

I would be very surprised if you did!

avatar Bakual Bakual - change - 24 Oct 2014
Milestone
avatar mbabker mbabker - change - 22 Nov 2014
Milestone
avatar mbabker mbabker - change - 22 Nov 2014
Milestone Added:
avatar mbabker mbabker - change - 22 Nov 2014
Milestone Added:
avatar mbabker mbabker - change - 22 Nov 2014
Milestone
avatar gauravjain028
gauravjain028 - comment - 31 Dec 2014

Shouldn't there be any check before checking $instance->id in elseif (is_string($id) || $instance->id !== $id) ?

#3104

Add a Comment

Login with GitHub to post a comment