Activation.class.php 2.32 KB
<?php
/**
 * 状态同步接口
 */
class Controller_Activation extends Controller_Abstract
{
    
    private $_callback = '' ;
    
    public function init()
    {
    	if ( $this->_request->action_name == 'state' ) 
    	{
    	    $this->_callback = $_GET['callback'];
    		unset($_GET['callback'],$_GET['_']);
    	}
    	if ($init = parent::init())
    	{
    	    return $init;
    	}
    }
    /**
     * 登录、登出状态同步
     * iframe/script浏览器设置状态调用接口
     */
    public function indexAction()
    {
    	$uid   = $this->_request->uid ;
    	$state = intval($this->_request->state) ; //1登录   2登出
    	if (!in_array($state,array(1,2))) 
    	{
    		return $this->returnJson(Config_Code::$error['missing_parameter']['code'],'',Config_Code::$error['missing_parameter']['message']);
    	}
    	if ($state == 1) 
    	{
    	    
    		if (Facade_Auth::getAuthedUid() != $uid) 
    		{
    			//登录
    			$sid = Facade_Auth::login($uid);
    		}else
    		{
    		    $session = Facade_Auth::getAuthedSessionArray();
    		    $sid = isset($session['sessionkey'])?$session['sessionkey']:0 ;
    		}
    	}else 
    	{
    		//登出
    		Facade_Auth::logout();
    		$sid = 0 ;
    	}
    	$apps = Facade_Subscribe::getAllApps() ;
    	$list = array();
    	foreach ($apps as $v)
    	{
    		if ($v['key'] != $this->_appId) 
    		{
    		    $data = Api_Uuc::buildData(array('sid' => $sid),$v['key'],$v['secret']);
    			$list[] = $v['domain'].'/passport/auth/signin?'.http_build_query($data);
    		}
    	}
    	
     	$string = 'var _b_o = document;' ;
    	//创建IFRMAE
    	foreach ($list as $v)
    	{
    	    $string .= <<<EOT
var newElement = document.createElement("iframe");
newElement.src="{$v}";newElement.style.display='none';
document.body.appendChild(newElement);
EOT;
    	} 
    	return $string ;
    	$this->_view['list'] = $list ;
    }
    
    /**
     * 获取当前登录用户
     */
    public function stateAction()
    {
    	$session = Facade_Auth::getAuthedSessionArray();
    	$sid = (isset($session['sessionkey']) && $session['sessionkey']) ? $session['sessionkey'] : 0 ;
    	return $this->_callback.'("'.$sid.'")';
    	//return $uid;
    	return $this->returnJson(Config_Code::$success['system']['code'],array('uid' => $uid),Config_Code::$success['system']['message']);
    }
    
}