[Solution]FrontEndUsers 1.17 one wrong add user aproach!

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
User avatar
kembl
Forum Members
Forum Members
Posts: 16
Joined: Wed Feb 22, 2012 9:13 pm

[Solution]FrontEndUsers 1.17 one wrong add user aproach!

Post by kembl »

Hello all!

Board: 1.10.3 "Hyacinthe"
Module: FrontEndUsers 1.17

Just found this bug and wish to create this post to avoid you from troubles >:D

When we needs to register some new user from code, we usually work by this steps:

1) Check if username not used already by some one else

2) If not, register user.

3) Check if user present in system now

When I was try to release this steps I was found this approach impossible, look :)

1) CHECK

Code: Select all

$feu = $this->GetModuleInstance('FrontEndUsers');
$uinfo = $feu->GetUserInfoByName( $username );

if( !is_array($uinfo) || $uinfo[0] != FALSE )
{
// All right at this time new user not found! And we do not step here.
}
2) REGISTER

I like to use SelfRegistration at this step, which I give proper formated $params array.

Code: Select all


$this->GetModuleInstance('SelfRegistration')->DoAction('reguser', 0, $params);

3) Check one more, to find that user already present in system

Code: Select all

$uinfo = $feu->GetUserInfoByName( $username );

if( !is_array($uinfo) || (is_array($uinfo) && $uinfo[0] == FALSE) )
{
// Ha-ha we always step here! while actually user was added to db already, but we do 
// not know it and step to this place, where we think that user 
// was no added at all!
}
We drops in to STEP3 because at first step, when we check user, FrontEndUsersManipulator was put in to local cache array $_useridbyname that it do not know this user, and now:

Code: Select all

$_useridbyname  == array (  'SomeUserName' => 'invalid',)
and when we step into GetUserInfoByName() at STEP3 it see the invalid user in cache and do not try to check it in database. While at that moment user actualy was added to database!!! :o

So, the question is: How to do the right check of username before add the user? ???

You may get all users in default group by

Code: Select all

$feu->GetFullUsersInGroup($feu->GetPreference('default_group'))
and then, search in this array your user. This is only workaround, because that approach too expensive and needs to search in all exists user groups.
In good style, you need to add cache refresh method to FrontEndUsers.
Post Reply

Return to “Modules/Add-Ons”