<?php 

if($_G['pa_count'] < 1) {

    odz_error('²ÎÊý´íÎó', -112);

}



loaducenter();



// ÕÒ»ØÃÜÂë

if($_GET['username']) {

	list($tmp['uid'], , $tmp['email']) = uc_get_user(addslashes($_GET['username']));

	if($_GET['email'] != $tmp['email']) {

		odz_error('getpasswd_account_notmatch');

	}

	$member = getuserbyuid($tmp['uid'], 1);

} else {

	$emailcount = C::t('common_member')->count_by_email($_GET['email'], 1);

	if(!$emailcount) {

		odz_error('lostpasswd_email_not_exist');

	}

	if($emailcount > 1) {

		odz_error('lostpasswd_many_users_use_email');

	}

	$member = C::t('common_member')->fetch_by_email($_GET['email'], 1);

	list($tmp['uid'], , $tmp['email']) = uc_get_user(addslashes($member['username']));

}

if(!$member) {

	odz_error('getpasswd_account_notmatch');

} elseif($member['adminid'] == 1 || $member['adminid'] == 2) {

	odz_error('getpasswd_account_invalid');

}



$table_ext = $member['_inarchive'] ? '_archive' : '';

if($member['email'] != $tmp['email']) {

	C::t('common_member'.$table_ext)->update($tmp['uid'], array('email' => $tmp['email']));

}



$idstring = random(6);

C::t('common_member_field_forum'.$table_ext)->update($member['uid'], array('authstr' => "$_G[timestamp]\t1\t$idstring"));

require_once libfile('function/mail');

$get_passwd_subject = lang('email', 'get_passwd_subject');

$get_passwd_message = lang(

	'email',

	'get_passwd_message',

	array(

		'username' => $member['username'],

		'bbname' => $_G['setting']['bbname'],

		'siteurl' => $_G['siteurl'],

		'uid' => $member['uid'],

		'idstring' => $idstring,

		'clientip' => $_G['clientip'],

	)

);

if(!sendmail("$_GET[username] <$tmp[email]>", $get_passwd_subject, $get_passwd_message)) {

	runlog('sendmail', "$tmp[email] sendmail failed.");

}



odz_success('getpasswd_send_succeed');

?>