[Solution]FrontEndUsers 1.17 one wrong add user aproach!
Posted: Mon Oct 22, 2012 3:49 pm
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
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
2) REGISTER
I like to use SelfRegistration at this step, which I give proper formated $params array.
3) Check one more, to find that user already present in system
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:
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!!!
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
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.
Board: 1.10.3 "Hyacinthe"
Module: FrontEndUsers 1.17
Just found this bug and wish to create this post to avoid you from troubles

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.
}
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);
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!
}
Code: Select all
$_useridbyname == array ( 'SomeUserName' => 'invalid',)

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'))
In good style, you need to add cache refresh method to FrontEndUsers.