part four
=============
/*-------------------------------------------------------------------------*/
// LOST PASSWORD: SEND
/*-------------------------------------------------------------------------*/
function lost_password_end()
{
if ($this->ipsclass->vars['bot_antispam'])
{
// Validate CAPTCHA
require_once( KERNEL_PATH . 'class_captcha.php' );
$captchaClass = new class_captcha( $this->ipsclass, $this->ipsclass->vars['bot_antispam_type'] );
if ( $captchaClass->validate() !== TRUE )
{
$this->lost_password_start('err_reg_code');
return;
}
}
//-----------------------------------------
// Back to the usual programming!

//-----------------------------------------
if ($_POST['member_name'] == "" AND $_POST['email_addy'] == "")
{
$this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'no_username' ) );
}
//-----------------------------------------
// Check for input and it's in a valid format.
//-----------------------------------------
$member_name = trim(strtolower($this->ipsclass->input['member_name']));
$email_addy = trim(strtolower($this->ipsclass->input['email_addy']));
if ($member_name == "" AND $email_addy == "" )
{
$this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'no_username' ) );
}
//-----------------------------------------
// Attempt to get the user details from the DB
//-----------------------------------------
if ( $this->ipsclass->vars['ipbli_usertype'] == 'username' )
{
if( $member_name )
{
$this->ipsclass->DB->simple_construct( array( 'select' => 'members_display_name, name, id, email, mgroup', 'from' => 'members', 'where' => "members_l_username='{$member_name}'" ) );
$this->ipsclass->DB->simple_exec();
}
else if( $email_addy )
{
$this->ipsclass->DB->simple_construct( array( 'select' => 'members_display_name, name, id, email, mgroup', 'from' => 'members', 'where' => "email='{$email_addy}'" ) );
$this->ipsclass->DB->simple_exec();
}
}
else
{
// We don't use the 'email_addy' input if usertype is email
$email_addy = "";
$this->ipsclass->DB->simple_construct( array( 'select' => 'members_display_name, name, id, email, mgroup', 'from' => 'members', 'where' => "email='{$member_name}'" ) );
$this->ipsclass->DB->simple_exec();
}
if ( ! $this->ipsclass->DB->get_num_rows() )
{
$this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'no_such_user' ) );
}
else
{
$member = $this->ipsclass->DB->fetch_row();
//-----------------------------------------
// Is there a validation key? If so, we'd better not touch it
//-----------------------------------------
if ($member['id'] == "")
{
$this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'no_such_user' ) );
}
$validate_key = md5( $this->ipsclass->make_password() . uniqid( mt_rand(), TRUE ) );
//-----------------------------------------
// Get rid of old entries for this member
//-----------------------------------------
$this->ipsclass->DB->do_delete( 'validating', "member_id={$member['id']} AND lost_pass=1" );
//-----------------------------------------
// Update the DB for this member.
//-----------------------------------------
$db_str = array(
'vid' => $validate_key,
'member_id' => $member['id'],
#'real_group' => $member['mgroup'],
'temp_group' => $member['mgroup'],
'entry_date' => time(),
'coppa_user' => 0,
'lost_pass' => 1,
'ip_address' => $this->ipsclass->input['IP_ADDRESS'],
);
// Are they already in the validating group?
if( $member['mgroup'] != $this->ipsclass->vars['auth_group'] )
{
$db_str['real_group'] = $member['mgroup'];
}
$this->ipsclass->DB->do_insert( 'validating', $db_str );
//-----------------------------------------
// Send out the email.
//-----------------------------------------
$this->email->get_template("lost_pass");
$this->email->build_message( array(
'NAME' => $member['members_display_name'],
'THE_LINK' => $this->base_url_nosess."?act=Reg&CODE=lostpassform&uid=".$member['id']."&aid=".$validate_key,
'MAN_LINK' => $this->base_url_nosess."?act=Reg&CODE=lostpassform",
'EMAIL' => $member['email'],
'ID' => $member['id'],
'CODE' => $validate_key,
'IP_ADDRESS' => $this->ipsclass->input['IP_ADDRESS'],
)
);
$this->email->subject = $this->ipsclass->lang['lp_subject'].' '.$this->ipsclass->vars['board_name'];
$this->email->to = $member['email'];
$this->email->send_mail();
$this->output = $this->ipsclass->compiled_templates['skin_register']->show_lostpasswait( $member );
}
$this->page_title = $this->ipsclass->lang['lpf_title'];
}
/*-------------------------------------------------------------------------*/
// show_reg_form
/*-------------------------------------------------------------------------*/
function show_reg_form($form_errors = array())
{
//-----------------------------------------
// INIT
//-----------------------------------------
$final_errors = array();
$captchaHTML = '';
if ( $this->ipsclass->vars['no_reg'] == 1 )
{
$this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'reg_off' ) );
}
$coppa = $this->ipsclass->my_getcookie( 'coppa' );
//$coppa = (isset($this->ipsclass->input['coppa_user']) AND $this->ipsclass->input['coppa_user'] == 1) ? 1 : 0;
if( $coppa == 'yes' )
{
$this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'awaiting_coppa' ) );
}
$this->ipsclass->vars['username_errormsg'] = str_replace( '{chars}', $this->ipsclass->vars['username_characters'], $this->ipsclass->vars['username_errormsg'] );
//-----------------------------------------
// Read T&Cs yet?
//-----------------------------------------
if ( !isset($this->ipsclass->input['termsread']) OR !$this->ipsclass->input['termsread'] )
{
if ( $this->ipsclass->member['id'] )
{
//-----------------------------------------
// Log member out
//-----------------------------------------
require_once( ROOT_PATH.'sources/action_public/login.php' );
$login = new login();
$login->ipsclass =& $this->ipsclass;
$login->do_log_out( 0 );
}
//-----------------------------------------
// Continue
//-----------------------------------------
$cache = $this->ipsclass->DB->simple_exec_query( array( 'select' => '*', 'from' => 'conf_settings', 'where' => "conf_key='reg_rules'" ) );
$text = $cache['conf_value'] ? $cache['conf_value'] : $cache['conf_default'];
$this->page_title = $this->ipsclass->lang['registration_form'];
$this->nav = array( $this->ipsclass->lang['registration_form'] );
$this->output .= $this->ipsclass->compiled_templates['skin_register']->show_terms( $this->ipsclass->my_nl2br($text), $coppa );
return;
}
else
{
//-----------------------------------------
// Did we agree to the t&c?
//-----------------------------------------
if ( ! $this->ipsclass->input['agree_to_terms'] )
{
$this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'reg_no_agree', 'EXTRA' => $this->ipsclass->base_url ) );
}
}
//-----------------------------------------
// Do we have another URL that one needs
// to visit to register?
//-----------------------------------------
$this->login_method = $this->ipsclass->DB->build_and_exec_query( array( 'select' => '*', 'from' => 'login_methods', 'where' => 'login_enabled=1' ) );
if ( $this->login_method['login_register_url'] )
{
$this->ipsclass->boink_it( $this->login_method['login_register_url'] );
exit();
}
//-----------------------------------------
// Continue...
//-----------------------------------------
if ( $this->ipsclass->vars['reg_auth_type'] )
{
if ( $this->ipsclass->vars['reg_auth_type'] == 'admin_user' OR $this->ipsclass->vars['reg_auth_type'] == 'user' )
{
$this->ipsclass->lang['std_text'] .= "<br />" . $this->ipsclass->lang['email_validate_text'];
}
//-----------------------------------------
// User then admin?
//-----------------------------------------
if ( $this->ipsclass->vars['reg_auth_type'] == 'admin_user' )
{
$this->ipsclass->lang['std_text'] .= "<br />" . $this->ipsclass->lang['user_admin_validation'];
}
if ( $this->ipsclass->vars['reg_auth_type'] == 'admin' )
{
$this->ipsclass->lang['std_text'] .= "<br />" . $this->ipsclass->lang['just_admin_validation'];
}
}
//-----------------------------------------
// Clean out anti-spam stuffy
//-----------------------------------------
if ( $this->ipsclass->vars['bot_antispam'] )
{
// Grab CAPTCHA template bit
require_once( KERNEL_PATH . 'class_captcha.php' );
$captchaClass = new class_captcha( $this->ipsclass, $this->ipsclass->vars['bot_antispam_type'] );
$captchaHTML = $captchaClass->getTemplate();
}
//-----------------------------------------
// Custom profile fields stuff
//-----------------------------------------
$required_output = "";
$optional_output = "";
require_once( ROOT_PATH.'sources/classes/class_custom_fields.php' );
$fields = new custom_fields( $this->ipsclass->DB );
$fields->cache_data = $this->ipsclass->cache['profilefields'];
$fields->init_data();
$fields->parse_to_register();
foreach( $fields->out_fields as $id => $data )
{
$error = "";
if ( $fields->cache_data[ $id ]['pf_not_null'] == 1 )
{
$ftype = 'required_output';
}
else
{
$ftype = 'optional_output';
}
if( isset($form_errors['cfield_'.$id]) AND count( $form_errors['cfield_'.$id] ) )
{
$error = implode( "<br />", $form_errors['cfield_'.$id] );
}
if ( $fields->cache_data[ $id ]['pf_type'] == 'drop' )
{
$form_element = $this->ipsclass->compiled_templates['skin_register']->field_dropdown( 'field_'.$id, $data, $error );
}
else if ( $fields->cache_data[ $id ]['pf_type'] == 'area' )
{
$data = $this->ipsclass->input['field_'.$id] ? $this->ipsclass->input['field_'.$id] : $data;
$data = $this->ipsclass->my_br2nl( $data );
$form_element = $this->ipsclass->compiled_templates['skin_register']->field_textarea( 'field_'.$id, $data, $error );
}
else
{
$data = isset($this->ipsclass->input['field_'.$id]) ? $this->ipsclass->input['field_'.$id] : $data;
$form_element = $this->ipsclass->compiled_templates['skin_register']->field_textinput( 'field_'.$id, $data, $error );
}
${$ftype} .= $this->ipsclass->compiled_templates['skin_register']->field_entry( $fields->field_names[ $id ], $fields->field_desc[ $id ], $form_element, $id, $error );
}
$this->page_title = $this->ipsclass->lang['registration_form'];
$this->nav = array( $this->ipsclass->lang['registration_form'] );
//-----------------------------------------
// ERROR CHECK
//-----------------------------------------
if ( isset($form_errors['general']) AND is_array( $form_errors['general'] ) AND count( $form_errors['general'] ) )
{
$this->output .= $this->ipsclass->compiled_templates['skin_register']->errors( implode( "<br />", $form_errors['general'] ) );
}
//-----------------------------------------
// Other errors
//-----------------------------------------
$final_errors = array( 'username' => NULL, 'dname' => NULL, 'password' => NULL, 'email' => NULL );
foreach( array( 'username', 'dname', 'password', 'email' ) as $thing )
{
if ( isset($form_errors[ $thing ]) AND is_array( $form_errors[ $thing ] ) AND count( $form_errors[ $thing ] ) )
{
$final_errors[ $thing ] = implode( "<br />", $form_errors[ $thing ] );
}
}
$this->ipsclass->input['UserName'] = isset($this->ipsclass->input['UserName']) ? $this->ipsclass->input['UserName'] : '';
$this->ipsclass->input['PassWord'] = isset($this->ipsclass->input['PassWord']) ? $this->ipsclass->input['PassWord'] : '';
$this->ipsclass->input['EmailAddress'] = isset($this->ipsclass->input['EmailAddress']) ? $this->ipsclass->input['EmailAddress'] : '';
$this->ipsclass->input['EmailAddress_two'] = isset($this->ipsclass->input['EmailAddress_two']) ? $this->ipsclass->input['EmailAddress_two'] : '';
$this->ipsclass->input['PassWord_Check'] = isset($this->ipsclass->input['PassWord_Check']) ? $this->ipsclass->input['PassWord_Check'] : '';
$this->ipsclass->input['members_display_name'] = isset($this->ipsclass->input['members_display_name']) ? $this->ipsclass->input['members_display_name'] : '';
$this->ipsclass->input['time_offset'] = isset($this->ipsclass->input['time_offset']) ? $this->ipsclass->input['time_offset'] : '';
$this->ipsclass->input['allow_member_mail'] = isset($this->ipsclass->input['allow_member_mail']) ? $this->ipsclass->input['allow_member_mail'] : '';
$this->ipsclass->input['dst'] = isset($this->ipsclass->input['dst']) ? $this->ipsclass->input['dst'] : '';
$this->output .= $this->ipsclass->compiled_templates['skin_register']->ShowForm( array( 'TEXT' => $this->ipsclass->lang['std_text'], 'coppa_user' => $coppa ), $final_errors );
//-----------------------------------------
// Replace elements
//-----------------------------------------
if ($this->ipsclass->vars['bot_antispam'] )
{
$this->output = str_replace( "<!--{REG.ANTISPAM}-->", $captchaHTML, $this->output );
}
if ($required_output != "")
{
$this->output = str_replace( "<!--{REQUIRED.FIELDS}-->", "\n".$required_output, $this->output );
}
if ($optional_output != "")
{
$this->output = str_replace( "<!--{OPTIONAL.FIELDS}-->", $this->ipsclass->compiled_templates['skin_register']->optional_title()."\n".$optional_output, $this->output );
}
//-----------------------------------------
// Time zone...
//-----------------------------------------
$this->ipsclass->load_language('lang_ucp');
$offset = ( $this->ipsclass->input['time_offset'] != "" ) ? $this->ipsclass->input['time_offset'] : $this->ipsclass->vars['time_offset'];
$time_select = "<select name='time_offset' class='forminput'>";
foreach( $this->ipsclass->lang as $off => $words )
{
if (preg_match("/^time_([\d\.\-]+)$/", $off, $match))
{
$time_select .= $match[1] == $offset ? "<option value='{$match[1]}' selected='selected'>$words</option>"
: "<option value='{$match[1]}'>$words</option>";
}
}
$time_select .= "</select>";
$this->output = str_replace( "<!--{TIME_ZONE}-->", "\n".$time_select, $this->output );
//-----------------------------------------
// Boxes checked?
//-----------------------------------------
$admin_checked = 'checked="checked"';
if ( $this->ipsclass->input['CODE'] == '02' )
{
//-----------------------------------------
// Form submitted...
//-----------------------------------------
if ( ! $this->ipsclass->input['allow_admin_mail'] )
{
$admin_checked = '';
}
}
$member_checked = $this->ipsclass->input['allow_member_mail'] ? 'checked="checked"' : '';
$dst_checked = $this->ipsclass->input['dst'] ? 'checked="checked"' : '';
$this->output = str_replace( "<!--[admin.checked]-->" , $admin_checked , $this->output );
$this->output = str_replace( "<!--[member.checked]-->", $member_checked, $this->output );
$this->output = str_replace( "<!--[dst.checked]-->" , $dst_checked , $this->output );