Ejemplo n.º 1
0
/**
* Shows the user registration form
*
* @param    int     $msg        message number to show
* @param    string  $referrer   page to send user to after registration
* @return   string  HTML for user registration page
*/
function newuserform($msg = '')
{
    global $_CONF, $LANG01, $LANG04;
    $retval = '';
    if ($_CONF['disable_new_user_registration']) {
        COM_setMsg($LANG04[122], 'error');
        echo COM_refresh($_CONF['site_url']);
    }
    if ($_CONF['custom_registration'] and function_exists('CUSTOM_userForm')) {
        return CUSTOM_userForm($msg);
    }
    if (!empty($msg)) {
        $retval .= COM_showMessageText($msg, $LANG04[21], false, 'info');
    }
    $user_templates = new Template($_CONF['path_layout'] . 'users');
    $user_templates->set_file('regform', 'registrationform.thtml');
    $user_templates->set_var('start_block', COM_startBlock($LANG04[22]));
    $user_templates->set_var('lang_instructions', $LANG04[23]);
    $user_templates->set_var('lang_username', $LANG04[2]);
    $user_templates->set_var('lang_fullname', $LANG04[3]);
    $user_templates->set_var('lang_email', $LANG04[5]);
    $user_templates->set_var('lang_email_conf', $LANG04[124]);
    if ($_CONF['registration_type'] == 1) {
        // verification link
        $user_templates->set_var('lang_passwd', $LANG01[57]);
        $user_templates->set_var('lang_passwd_conf', $LANG04[176]);
        $user_templates->set_var('lang_warning', $LANG04[167]);
    } else {
        $user_templates->set_var('lang_warning', $LANG04[24]);
    }
    $user_templates->set_var('lang_register', $LANG04[27]);
    PLG_templateSetVars('registration', $user_templates);
    $user_templates->set_var('end_block', COM_endBlock());
    $username = '';
    if (!empty($_POST['username'])) {
        $username = trim($_POST['username']);
    }
    $user_templates->set_var('username', @htmlentities($username, ENT_COMPAT, COM_getEncodingt()));
    $fullname = '';
    if (!empty($_POST['fullname'])) {
        $fullname = $_POST['fullname'];
    }
    $fullname = USER_sanitizeName($fullname);
    $user_templates->set_var('fullname', @htmlentities($fullname, ENT_COMPAT, COM_getEncodingt()));
    switch ($_CONF['user_reg_fullname']) {
        case 2:
            $user_templates->set_var('require_fullname', 'true');
        case 1:
            $user_templates->set_var('show_fullname', 'true');
    }
    $email = '';
    if (!empty($_POST['email'])) {
        $email = COM_applyFilter($_POST['email']);
    }
    $user_templates->set_var('email', $email);
    $email_conf = '';
    if (!empty($_POST['email_conf'])) {
        $email_conf = COM_applyFilter($_POST['email_conf']);
    }
    $user_templates->set_var('email_conf', $email_conf);
    $user_templates->parse('output', 'regform');
    $retval .= $user_templates->finish($user_templates->get_var('output'));
    return $retval;
}
Ejemplo n.º 2
0
/**
 * Creates a user
 * Creates a user with the give username and email address
 *
 * @param    string $username   username to create user for
 * @param    string $email      email address to assign to user
 * @param    string $email_conf confirmation email address check
 * @return   string      HTML for the form again if error occurs, otherwise nothing.
 */
function createuser($username, $email, $email_conf)
{
    global $_CONF, $_TABLES, $LANG01, $LANG04;
    $retval = '';
    $username = trim($username);
    $email = trim($email);
    $email_conf = trim($email_conf);
    if (!isset($_CONF['disallow_domains'])) {
        $_CONF['disallow_domains'] = '';
    }
    if (COM_isEmail($email) && !empty($username) && $email === $email_conf && !USER_emailMatches($email, $_CONF['disallow_domains']) && strlen($username) <= 16) {
        $ucount = DB_count($_TABLES['users'], 'username', DB_escapeString($username));
        $ecount = DB_count($_TABLES['users'], 'email', DB_escapeString($email));
        if ($ucount == 0 && $ecount == 0) {
            // For Geeklog, it would be okay to create this user now. But check
            // with a custom userform first, if one exists.
            if ($_CONF['custom_registration'] && function_exists('CUSTOM_userCheck')) {
                $ret = CUSTOM_userCheck($username, $email);
                if (!empty($ret)) {
                    // no, it's not okay with the custom userform
                    $retval = COM_createHTMLDocument(CUSTOM_userForm($ret['string']));
                    return $retval;
                }
            }
            // Let plugins have a chance to decide what to do before creating the user, return errors.
            $msg = PLG_itemPreSave('registration', $username);
            if (!empty($msg)) {
                if ($_CONF['custom_registration'] && function_exists('CUSTOM_userForm')) {
                    $retval .= CUSTOM_userForm($msg);
                } else {
                    $retval .= newuserform($msg);
                }
                $retval = COM_createHTMLDocument($retval, array('pagetitle' => $LANG04[22]));
                return $retval;
            }
            $uid = USER_createAccount($username, $email);
            if ($_CONF['usersubmission'] == 1) {
                if (DB_getItem($_TABLES['users'], 'status', "uid = {$uid}") == USER_ACCOUNT_AWAITING_APPROVAL) {
                    COM_redirect($_CONF['site_url'] . '/index.php?msg=48');
                } else {
                    $retval = emailpassword($username, 1);
                }
            } else {
                $retval = emailpassword($username, 1);
            }
            return $retval;
        } else {
            if ($_CONF['custom_registration'] && function_exists('CUSTOM_userForm')) {
                $retval .= CUSTOM_userForm($LANG04[19]);
            } else {
                $retval .= newuserform($LANG04[19]);
            }
            $retval = COM_createHTMLDocument($retval, array('pagetitle' => $LANG04[22]));
        }
    } elseif ($email !== $email_conf) {
        $msg = $LANG04[125];
        if ($_CONF['custom_registration'] && function_exists('CUSTOM_userForm')) {
            $retval .= CUSTOM_userForm($msg);
        } else {
            $retval .= newuserform($msg);
        }
        $retval = COM_createHTMLDocument($retval, array('pagetitle' => $LANG04[22]));
    } else {
        // invalid username or email address
        if (empty($username) || strlen($username) > 16) {
            $msg = $LANG01[32];
            // invalid username
        } else {
            $msg = $LANG04[18];
            // invalid email address
        }
        if ($_CONF['custom_registration'] && function_exists('CUSTOM_userForm')) {
            $retval .= CUSTOM_userForm($msg);
        } else {
            $retval .= newuserform($msg);
        }
        $retval = COM_createHTMLDocument($retval, array('pagetitle' => $LANG04[22]));
    }
    return $retval;
}