Activation.class.php
2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?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']);
}
}