Hi,
I am using the ssi_register() function to show a registration form on the site home page outside the smf 1.1.16.
When I tested the SMF 2 large upgrade, everything went fine except for the ss_register() function which is no longer working...it seems to be working but the member never gets registered...I've found two versions of the function but none is working.
I saw it was possible to register a new member using the SMF 2 API but I have no idea how to show a registration form with a CAPTCHA on it.
Any help would be greatly appreciated.
Thanks !
Vroum.
Version 1 (works on SMF 1.1.16)
// Show a form for guests to register.
function ssi_register($output_method = 'echo')
{
global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context;
loadLanguage('Login');
// Generate a visual verification code to make sure the user is no bot.
$context['visual_verification'] = empty($modSettings['disable_visual_verification']) || $modSettings['disable_visual_verification'] != 1;
if ($context['visual_verification'])
{
$context['use_graphic_library'] = in_array('gd', get_loaded_extensions());
$context['verificiation_image_href'] = $scripturl . '?action=verificationcode;rand=' . md5(rand());
// Only generate a new code if one hasn't been set yet
if (!isset($_SESSION['visual_verification_code']))
{
// Skip I, J, L, O and Q.
$character_range = array_merge(range('A', 'H'), array('K', 'M', 'N', 'P'), range('R', 'Z'));
// Generate a new code.
$_SESSION['visual_verification_code'] = '';
for ($i = 0; $i < 5; $i++)
$_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)];
}
}
// If we have GD, try the nice code.
elseif (empty($_REQUEST['format']))
{
require_once($sourcedir . '/Subs-Graphics.php');
if (in_array('gd', get_loaded_extensions()) && !showCodeImage($_SESSION['visual_verification_code'])) {
header('HTTP/1.1 400 Bad Request');
die();
}
// Otherwise just show a pre-defined letter.
elseif (isset($_REQUEST['letter']))
{
$_REQUEST['letter'] = (int) $_REQUEST['letter'];
if ($_REQUEST['letter'] > 0 && $_REQUEST['letter'] <= strlen($_SESSION['visual_verification_code']) && !showLetterImage(strtolower($_SESSION['visual_verification_code']{$_REQUEST['letter'] - 1}))) {
header('HTTP/1.1 400 Bad Request');
die();
}
}
// You must be up to no good.
else {
header('HTTP/1.1 400 Bad Request');
die();
}
}
elseif ($_REQUEST['format'] === '.wav')
{
require_once($sourcedir . '/Subs-Sound.php');
if (!createWaveFile($_SESSION['visual_verification_code'])) {
header('HTTP/1.1 400 Bad Request');
die();
}
}
if($output_method = 'echo' && $context['user']['is_guest']) {
echo '
<div>
<form action="'. $scripturl. '?action=register2" method="post" style="margin: 0px 1px 1px 0; text-align:left;" name="creator" id="creator">
<table class="ssi_table">
<tr>
<td>', $txt['username'], ':</td>
<td><input type="text" name="user" size="10" maxlength="30" /></td>
</tr>
<tr>
<td>', $txt['choose_pass'], ':</td>
<td><input type="password" name="passwrd1" size="10" /></td>
</tr>
<tr>
<td>', $txt['verify_pass'], ': </td>
<td><input type="password" name="passwrd2" size="10" /></td>
</tr>
<tr>
<td>', $txt['email'], ':</td>
<td><input name="email" type="text" size="10" /><input name="regagree" type="hidden" value="checked" /></td>
</tr>';
if ($context['visual_verification'])
{
echo '
<tr>
<td>
', $txt['visual_verification_description'], ':
</td>
<td><input type="text" name="visual_verification_code" size="10" /></td>
</tr>
<tr>';
if ($context['use_graphic_library'])
echo '
<td colspan="2"><img src="', $context['verificiation_image_href'], '" alt="', $txt['visual_verification_description'], '" id="verificiation_image" /></td>';
else
echo '
<td colspan="2"><img src="', $context['verificiation_image_href'], ';letter=1" alt="', $txt['visual_verification_description'], '" id="verificiation_image_1" />
<img src="', $context['verificiation_image_href'], ';letter=2" alt="', $txt['visual_verification_description'], '" id="verificiation_image_2" />
<img src="', $context['verificiation_image_href'], ';letter=3" alt="', $txt['visual_verification_description'], '" id="verificiation_image_3" />
<img src="', $context['verificiation_image_href'], ';letter=4" alt="', $txt['visual_verification_description'], '" id="verificiation_image_4" />
<img src="', $context['verificiation_image_href'], ';letter=5" alt="', $txt['visual_verification_description'], '" id="verificiation_image_5" /></td>';
echo '
</tr>
<tr>
<td class="smalltext" colspan="2">
<a href="', $context['verificiation_image_href'], ';sound" onclick="return reqWin(this.href, 400, 120);">', $txt['visual_verification_sound'], '</a>
</td>
</tr>';
}
echo'
<tr>
<td colspan="2" align="center"><input type="submit" value="', $txt['register'], '" /></td>
</tr>
</table>
</form>
</div>';
}
else
return false;
}
// Do we allow guests in here?
if (empty($ssi_guest_access) && empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && basename($_SERVER['PHP_SELF']) != 'SSI.php')
{
require_once($sourcedir . '/Subs-Auth.php');
KickGuest();
obExit(null, true);
}
// Load the stuff like the menu bar, etc.
if (isset($ssi_layers))
{
$context['template_layers'] = $ssi_layers;
template_header();
}
else
setupThemeContext();
// Make sure they didn't muss around with the settings... but only if it's not cli.
if (isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['is_cli']) && session_id() == '')
trigger_error($txt['ssi_session_broken'], E_USER_NOTICE);
// Without visiting the forum this session variable might not be set on submit.
if (!isset($_SESSION['USER_AGENT']) && (!isset($_GET['ssi_function']) || $_GET['ssi_function'] !== 'pollVote'))
$_SESSION['USER_AGENT'] = $_SERVER['HTTP_USER_AGENT'];
// Call a function passed by GET.
if (isset($_GET['ssi_function']) && function_exists('ssi_' . $_GET['ssi_function']) && (!empty($modSettings['allow_guestAccess']) || !$user_info['is_guest']))
{
call_user_func('ssi_' . $_GET['ssi_function']);
exit;
}
if (isset($_GET['ssi_function']))
exit;
// You shouldn't just access SSI.php directly by URL!!
elseif (basename($_SERVER['PHP_SELF']) == 'SSI.php')
die(sprintf($txt['ssi_not_direct'], $user_info['is_admin'] ? '\'' . addslashes(__FILE__) . '\'' : '\'SSI.php\''));
error_reporting($ssi_error_reporting);
@set_magic_quotes_runtime($ssi_magic_quotes_runtime);
return true;
Version 2 (supposed to work with SMF 2)
user is never registered !!!!!!!!!!!
function ssi_register($output_method = 'echo')
{
global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context;
loadLanguage('Login');
// Generate a visual verification code to make sure the user is no bot.
$context['visual_verification'] = empty($modSettings['disable_visual_verification']) || $modSettings['disable_visual_verification'] != 1;
if ($context['visual_verification'])
{
$context['use_graphic_library'] = in_array('gd', get_loaded_extensions());
$context['verificiation_image_href'] = $scripturl . '?action=verificationcode;rand=' . md5(rand());
// Only generate a new code if one hasn't been set yet
if (!isset($_SESSION['visual_verification_code']))
{
// Skip I, J, L, O and Q.
$character_range = array_merge(range('A', 'H'), array('K', 'M', 'N', 'P'), range('R', 'Z'));
// Generate a new code.
$_SESSION['visual_verification_code'] = '';
for ($i = 0; $i < 5; $i++)
$_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)];
}
}
// If we have GD, try the nice code.
elseif (empty($_REQUEST['format']))
{
require_once($sourcedir . '/Subs-Graphics.php');
if (in_array('gd', get_loaded_extensions()) && !showCodeImage($_SESSION['visual_verification_code'])) {
header('HTTP/1.1 400 Bad Request');
die();
}
// Otherwise just show a pre-defined letter.
elseif (isset($_REQUEST['letter']))
{
$_REQUEST['letter'] = (int) $_REQUEST['letter'];
if ($_REQUEST['letter'] > 0 && $_REQUEST['letter'] <= strlen($_SESSION['visual_verification_code']) && !showLetterImage(strtolower($_SESSION['visual_verification_code']{$_REQUEST['letter'] - 1}))) {
header('HTTP/1.1 400 Bad Request');
die();
}
}
// You must be up to no good.
else {
header('HTTP/1.1 400 Bad Request');
die();
}
}
elseif ($_REQUEST['format'] === '.wav')
{
require_once($sourcedir . '/Subs-Sound.php');
if (!createWaveFile($_SESSION['visual_verification_code'])) {
header('HTTP/1.1 400 Bad Request');
die();
}
}
if($output_method = 'echo' && $context['user']['is_guest']) {
echo '
<div>
<form action="'. $scripturl. '?action=register2" method="post" style="margin: 0px 1px 1px 0; text-align:left;" name="creator" id="creator">
<table class="ssi_table">
<tr>
<td>', $txt['username'], ':</td>
<td><input type="text" name="user" size="10" maxlength="30" /></td>
</tr>
<tr>
<td>', $txt['choose_pass'], ':</td>
<td><input type="password" name="passwrd1" size="10" /></td>
</tr>
<tr>
<td>', $txt['verify_pass'], ': </td>
<td><input type="password" name="passwrd2" size="10" /></td>
</tr>
<tr>
<td>', $txt['email'], ':</td>
<td><input name="email" type="text" size="10" /><input name="regagree" type="hidden" value="checked" /></td>
</tr>';
if ($context['visual_verification'])
{
echo '
<tr>
<td>
', $txt['visual_verification_description'], ':
</td>
<td><input type="text" name="visual_verification_code" size="10" /></td>
</tr>
<tr>';
if ($context['use_graphic_library'])
echo '
<td colspan="2"><img src="', $context['verificiation_image_href'], '" alt="', $txt['visual_verification_description'], '" id="verificiation_image" /></td>';
else
echo '
<td colspan="2"><img src="', $context['verificiation_image_href'], ';letter=1" alt="', $txt['visual_verification_description'], '" id="verificiation_image_1" />
<img src="', $context['verificiation_image_href'], ';letter=2" alt="', $txt['visual_verification_description'], '" id="verificiation_image_2" />
<img src="', $context['verificiation_image_href'], ';letter=3" alt="', $txt['visual_verification_description'], '" id="verificiation_image_3" />
<img src="', $context['verificiation_image_href'], ';letter=4" alt="', $txt['visual_verification_description'], '" id="verificiation_image_4" />
<img src="', $context['verificiation_image_href'], ';letter=5" alt="', $txt['visual_verification_description'], '" id="verificiation_image_5" /></td>';
echo '
</tr>
<tr>
<td class="smalltext" colspan="2">
<a href="', $context['verificiation_image_href'], ';sound" onclick="return reqWin(this.href, 400, 120);">', $txt['visual_verification_sound'], '</a>
</td>
</tr>';
}
echo' | <a href="/register" onclick="refreshImages(); return false;">Request another image</a>
<tr>
<td colspan="2" align="center"><input type="submit" value="', $txt['register'], '" /></td>
</tr>
</table>
</form>
</div>
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
function verifyAgree()
{
if (document.forms.creator.passwrd1.value != document.forms.creator.passwrd2.value)
{
alert("The two passwords you entered are not the same!");
return false;
}
if (!document.forms.creator.regagree.checked)
{
alert("Please read and accept the agreement before registering.");
return false;
}
return true;
}
function checkAgree()
{
document.forms.creator.regSubmit.disabled = isEmptyText(document.forms.creator.user) || isEmptyText(document.forms.creator.email) || isEmptyText(document.forms.creator.passwrd1) || !document.forms.creator.regagree.checked;
setTimeout("checkAgree();", 1000);
}
setTimeout("checkAgree();", 1000);
function refreshImages()
{
// Make sure we are using a new rand code.
var new_url = new String("', $context['verificiation_image_href'] ,'");
new_url = new_url.substr(0, new_url.indexOf("rand=") + 5);
// Quick and dirty way of converting decimal to hex
var hexstr = "0123456789abcdef";
for(var i=0; i < 32; i++)
new_url = new_url + hexstr.substr(Math.floor(Math.random() * 16), 1);
document.getElementById("verificiation_image").src = new_url;
}
// ]]></script>
';
}
else
return false;
}
No one in here ?
As this is, also, this:
http://www.simplemachines.org/community/index.php?topic=485187.0
Consider this one to be locked, pending removal.