registerMember()

Started by asmith, April 29, 2014, 12:54:18 AM

Previous topic - Next topic

asmith

Hello,

Not sure if this is a bug, but it worth a shot. (SMF 2.0.7)
I've been playing around with registerMember() function located in Subs-Members.php.

This function accepts 2 parameters:

function registerMember(&$regOptions, $return_errors = false)

I setup a custom code in my site which uses this function to register. So I pass the the $regOptions with $return_errors to true and happily get back the result of the registration which can contain errors. That's generally what I'd expect from using a function in "Subs" sources.

But there are still some parts in this function which will generate a fatal error despite the fact that $return_errors is set to true:


// Put any errors in here.
$reg_errors = array();

// Registration from the admin center, let them sweat a little more.
if ($regOptions['interface'] == 'admin')
{
is_not_guest();
isAllowedTo('moderate_forum');
}
// If you're an admin, you're special ;).
elseif ($regOptions['interface'] == 'guest')
{
// You cannot register twice...
if (empty($user_info['is_guest']))
redirectexit();

// Make sure they didn't just register with this session.
if (!empty($_SESSION['just_registered']) && empty($modSettings['disableRegisterCheck']))
fatal_lang_error('register_only_once', false);
}


Is there a reason we have fatal errors there? or it's a bug that has slipped through?

I noticed that bug, when creating a user and tried creating another one right after. so fatal_lang_error('register_only_once', false); kicked in and ended my code. I was expecting it would return the 'register_only_once' text error not making it fatal.

Hope this helps

emanuele

Considering in the various Subs-*.php there are:
* 3 is_not_guest
* 9 isAllowedTo
* 16 redirectexit
* 79 fatal_(lang_){0,1}error
I wouldn't consider it a "bug that slipped through". :P

Last time I had to deal with it for an integration, I "defined" my own "interface":
https://github.com/emanuele45/joomla_bridge/blob/master/smf2.php#L110
that way the two checks are skipped and you can proceed with the registration without being kicked out.


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

asmith

Thanks for the reply :)

Indeed defining my own interface will solve the problem. But still! I think a function argument must have its effect in all places.
You may want to call registerMember() in "guest" mode in Ajax or in a normal way and with an argument like $return_errors you could have better control over it.

I guess it is just a suggestion though, not a bug :)

emanuele

Oh, but I agree!
Subs should do the subs and not kill the execution, if you look at the file I posted, in order to delete a member's account you'd have to cheat *badly* and say the member is admin ($user_info['is_admin'] = true;), otherwise you can't delete it because of some error checking (I don't remember the details at the moment). Of course this is barely acceptable for short scripts, but in more complicated ones that would be a terrible pain to deal with.


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Advertisement: