News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Register a user from a small PHP file hidden somewhere.

Started by madturnip, March 09, 2012, 08:24:10 PM

Previous topic - Next topic

madturnip

Here:
        // Sanitize some data
        $username = !empty($_POST['user']) ?
            $smcFunc['htmlspecialchars']($_POST['user'], ENT_QUOTES) : '';



and here:
<input type="text" name="username" />

They didn't match - so it didn't work.   Simple overlook....   Again thanks.

ascaland


madturnip

Ok it works...  and does what is suppose to.

However, how do I register a user with whatever group access without having to be logged into the forum with 'KEEP ME LOGGED IN' checked.

I know I can change:  'interface' => 'admin',  to 'interface' => 'guest',   --- but that will not allow me to select the proper group.  No matter what they will be a plain jane registered account.

If I am logged into the forum and run this same script with 'interface' => 'admin', it works just fine.   However that defeats the purpose of the script in the first place.


Any work-around for this?

ascaland

Shoot that is quite a pain in the arse...
I rewrote the function to take care of this. It will update the primary group of the added member (assuming that's what you intended).
function loadLogic() {
   
    global $smcFunc, $sourcedir, $groups, $modSettings;

    $request = $smcFunc['db_query']('',
        'SELECT id_group, group_name
        FROM {db_prefix}membergroups');
    while ($row = $smcFunc['db_fetch_assoc']($request))
        $groups[$row['id_group']] = $row['group_name'];

    $smcFunc['db_free_result']($request);
   
    // Only do this part if the submit button was pressed
    if (isset($_POST['submit'])) {
        // Make sure we include the registration function
        require_once($sourcedir . '/Subs-Members.php');
       
        // Sanitize some data
        $username = !empty($_POST['user']) ?
            $smcFunc['htmlspecialchars']($_POST['user'], ENT_QUOTES) : '';
        $email = !empty($_POST['email']) ?
            $smcFunc['htmlspecialchars']($_POST['email'], ENT_QUOTES) : '';
        $password = !empty($_POST['passwrd']) ?
            $smcFunc['htmlspecialchars']($_POST['passwrd'], ENT_QUOTES) : '';
        $group_id = !empty($_POST['group']) && is_numeric($_POST['group']) ?
                $_POST['group'] : 0;
       
    $regOptions = array(
    'interface' => 'guest',
    'username' => $username,
    'email' => $email,
    'password' => $password,
    'password_check' => $password,
    'openid' => '',
    'auth_method' => '',
    'check_reserved_name' => true,
    'check_password_strength' => false,
    'check_email_ban' => false,
    'send_welcome_email' => !empty($modSettings['send_welcomeEmail']),
    'require' => 'nothing',
    'extra_register_vars' => array(),
    'theme_vars' => array(),
    );
   
        $id_member = registerMember($regOptions);
        $smcFunc['db_query']('',
            'UPDATE {db_prefix}members SET id_group = {int:group_id} WHERE id_member =
            {int:id_member}',
            array(
               'group_id' => $group_id, 'id_member' => $id_member,
            )
        );
    }
}

madturnip


Advertisement: