<?php
if(!defined('R_P')) exit('Access Denied');
if ($_POST['myFormAc'] == "update"){
	$username   = trim($_POST['username']);
	$password   = stripslashes(trim($_POST['password']));
	$cookietime = intval($_POST['cookietime']);
	if(intval($_SET['login_code']) > 0){
		$code = strtolower(trim($_SESSION['code']));
		$verify_code = strtolower(trim($_POST['verify_code']));
		unset($_SESSION['code']);
		if(!$code || $code != $verify_code) qbase::showmsg("出错了，验证码错误", SKIN, $location);
	}
	$msg  = qbase::get_object('login')->loginAc($username, $password, $cookietime);
	if(AJAX || JSONP){
		$msg['syn_js'] = array();
		if($msg['uc']){
			preg_match_all("'<\s*script\s.*?src\s*=\s*([\"\'])?	(?(1) (.*?)\\1 | ([^\s\>]+))'isx", $c, $msg['uc']);
			$match = array();
			while(list($key,$val) = each($links[2])){
				if(!empty($val))
					$match[] = $val;
			}
			while(list($key,$val) = each($links[3])){
				if(!empty($val))
					$match[] = $val;
			}
			$msg['syn_js'] = $match[2];
			$msg['uc'] = 'uc_syn_login';
		}
		echo qbase::xmlPrint(qbase::jsonencode($msg));
	}else{
		$forward = urldecode($_GET['forward']);
		if($msg['status'] == 200){
			$url = $forward ? $forward : "user.php";
		}else{
			$url = "user.php?ac=login&forward=" . urlencode($forward);
		}
		if($msg['uc']){
			$wait = 60;
			$msg['message'] = "恭喜您，登录成功！登录同步中，请等待{$msg['uc']}<script type='text/javascript'>window.onload = function(){window.location.href='{$url}';}</script>";
			qbase::showmsg($msg['message'], 'default', $url , '', false);
		}else{
			$msg['message'] = "恭喜您，登录成功！";
			qbase::showmsg($msg['message'], 'default', $url);
		}
	}
}else{
	if ($user_info['username'])	qbase::showmsg('你已经登陆','default','index.php');
	$username = urldecode($_GET['username']);
	$forward = urlencode($_GET['forward']);
	$forward_encode = addslashes($_GET['forward']);
	include qbase::template($_SET['skin']  . '/user/login');
}
?>