<?php
if(!defined('R_P')) exit('Access Denied');
if($user_info['username']) qbase::showmsg( "您当前已经处于登录状态，不能进行Email验证", $_SET['skin'], "user.php" );
$verify_data = array();
parse_str(qbase::authcode(trim(urldecode($_GET['verify'])), "DECODE"), $verify_data);
if(!isset($verify_data['uid']) || !isset($verify_data['email']) || !isset($verify_data['session'])) qbase::showmsg( "提交了错误的数据请求", $_SET['skin'], "user.php" );
$verify_data['uid'] = intval($verify_data['uid']);
$verify_data['email'] = addslashes(urldecode($verify_data['email']));
$verify_data['session'] = addslashes(urldecode($verify_data['session']));
$user_temp_info = qbase::get_object('login')->get_user_info($verify_data['uid'], $verify_data['session']);
if(empty($user_temp_info) || $verify_data['email'] != $user_temp_info['email'] || $user_temp_info['email_verify']) qbase::showmsg( "提交了错误的数据请求", $_SET['skin'], "user.php?ac=login" );
if($user_temp_info['email_verify'] > 0) qbase::showmsg( "Email {$verify_data['email']} 已经被别人使用过了，请换一个", $_SET['skin'], "user.php?ac=mail_verify&uid={$verify_data['uid']}&session={$verify_data['session']}&auto=1" );

$session = substr(md5(qbase::random(6) . qbase::get_ip() . $verify_data['uid']), 0, 12);
qdb::query("update ".TABLEPRE."user set email_verify = 1, session = '{$session}' where uid = '{$verify_data['uid']}' ");
if($user_temp_info['gid'] == 1){
	qdb::query("update ".TABLEPRE."user_extend set gid = 2 where uid = '{$verify_data['uid']}' ");
	qbase::ChangePoint($verify_data['uid'], $usergroup[2]['point']);
}
qbase::get_object('login')->delete_user_cache($verify_data['uid']);
qbase::showmsg( "恭喜你，邮箱通过验证了！请登录", $_SET['skin'], "user.php?ac=login&username=" . urlencode($user_temp_info['username']) );
?>