<?php
if (!isset($_GET['tokey']))
    yun_error(mlang('激活码为空'));
$tokey = decrypt($_GET['tokey']);
@$arr = unserialize($tokey);
if (!is_array($arr))
    yun_error(mlang('无效的激活码'));
$uarr = $conf['sys_email_regs'];
foreach ($uarr as $k => $v)
{
    if ((TIME - $v['reg_time']) > 24 * 3600)
    {
        unset($uarr[$k]);
        continue;
    }
}
$key = array_search($arr, $uarr);
if ($key === false)
    yun_error(mlang('该激活码已失效'));
unset($uarr[$key]);
$sql = sql_insert($arr);
if ($db->query("insert into " . PF . "user $sql"))
{
    setcookie(PF . 'yun_user', encrypt($db->insert_id() . "\t" . $arr['name']), TIME +
        30 * 24 * 3600, ROOTPATH);
    set_conf('sys_email_regs', $uarr);
    yun_succeed(mlang('激活成功'), url(RPG . 'user/'));
} else
{
    yun_error(mlang('激活失败'));
}
?>