<?php
if(!defined('R_P')) exit('Access Denied');
if($user_info['username']) qbase::showmsg( "你已经通过了邮件验证", $_SET['skin'], "user.php" );
$uid = intval($_GET['uid']);
$auto = intval($_GET['auto']);
$session = $_GET['session'];
$user_temp_info = qbase::get_object('login')->get_user_info($uid, $session);
if(empty($user_temp_info)) qbase::showmsg( "提交了错误的数据请求", $_SET['skin'], "user.php" );
if(AJAX){
	if($user_temp_info['email_verify'] > 0 ){
		$data = array('status'=>404);
	}else{
		$email = urldecode($_GET['email']);
		if(empty($email) || strlen($email) > 64 ||  !ereg("^[-a-zA-Z0-9_\.]+\@([0-9A-Za-z_][0-9A-Za-z-]+\.)+[A-Za-z]{2,5}$",$email )){
			$data = array('status'=>302, 'message'=>'请输入有效的邮件地址！');
		}else{
			if($email != $user_temp_info['email']){
				$num = qdb::queryAlone("select count(*) as num from ".TABLEPRE."user where email = '{$email}' and email_verify > 0 limit 1");
				if($num > 0){
					$data = array('status'=>302, 'message'=>'该邮件已经被别人使用过了，请换一个');
				}else{
					$uc_email =  $_SET['uc'] ? uc_user_checkemail($email) : 1;
					if($uc_email > 0) {
						$session = substr(md5(qbase::random(6) . qbase::get_ip() . $uid), 0, 12);
						qdb::query("update ".TABLEPRE."user set email = '{$email}', session = '{$session}' where uid = '{$uid}' ");
						$user_temp_info['email'] = $email;
						qbase::get_object('login')->delete_user_cache($uid);
						qbase::get_object("sendmail", $user_temp_info['username'], $user_temp_info['email'])->op_reg($uid, $session);
						$data = array('status'=>200, 'uid'=>$uid, 'session'=>$session);
					} elseif($uc_email == -4) {
						$data = array('status'=>302, 'message'=>'Email 格式有误');
					} elseif($uc_email == -5) {
						$data = array('status'=>302, 'message'=>'Email 不允许注册');
					} elseif($uc_email == -6) {
						$data = array('status'=>302, 'message'=>'该 Email 已经被注册');
					} else {
						$data = array('status'=>302, 'message'=>'system error');
					}
				}
			}else{
				//$data = array('status'=>200, 'uid'=>$uid, 'session'=>$session);
				//qbase::get_object("sendmail", $user_temp_info['username'], $user_temp_info['email'])->op_reg($uid, $session);
				//echo 1111111111111111;
			}
		}
	}
	echo qbase::xmlPrint(qbase::jsonencode($data));
}else{
	if($user_temp_info['email_verify'] == 0){
		include qbase::template($_SET['skin']  . '/user/mail_verify');
	}else{
		qbase::showmsg( "提交了错误的数据请求", $_SET['skin'], "user.php" );
	}
}
?>