Login.class.php
4.94 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
/**
* 登录控制器
*/
class Controller_Login extends Controller_Abstract
{
/**
* 首页
*/
public function indexAction()
{
return 'Run';
}
/**
* 登录
*/
public function backAction()
{
if ($this->_request->isPost())
{
$account = trim($this->_request->account) ;
$password = trim($this->_request->password) ;
$fields = trim($this->_request->fields) ;
////2015-4-13 wuxiao app增加国际手机号登录注册
//$result = Facade_Auth::checkLogin($account, $password);
//@file_put_contents('/tmp/sso',date('Y-m-d H:i:s', time()).'|'.$account.'|'.$password."\n", FILE_APPEND);
$area = trim($this->_request->area) ;
$result = Facade_Auth::checkLogin($account, $password, false, 0 , false, $area);
if ( isset($result['uid']) )
{
//构造信息返回
$data = Facade_Userinfo::getUserinfoForApp($result['uid'], $fields, $this->_appScope);
//返回密码
if (in_array($this->_appId, array('1392109210','1392109259','1392109260')))
{
$data['password'] = Facade_Auth::getPassword($result['uid']);
$data['list'] = Facade_Auth::getAllAuth($result['uid']);
}
return $this->returnJson($result['code'], $data,$result['message']);
}else{
if(defined('SSO_LOG') && SSO_LOG){
@file_put_contents('/Data/logs/php/sso-login-'.date('Y-m-d').'.log', '登录错误['.date('H:i:s').']-账户:'.$account.' 密码:'.$password.' 地区码:'.$area."\n", FILE_APPEND);
}
}
return $this->returnJson($result['code'], array(), $result['message']);
}
}
/**
* 校验有货账号的有效性
*/
public function validYohoBuyLoginAction()
{
if ($this->_request->isPost())
{
$account = trim($this->_request->account) ;
$password = trim($this->_request->password) ;
$result = Facade_Auth::checkLogin($account, $password,false,false,false);
if ( isset($result['uid']) )
{
//检验是否为有货账号
/* $userinfo = Facade_Userinfo::getUserinfoByUid($result['uid']);
if (!in_array($userinfo['app_id'], array('1392109259')))
{
return $this->returnJson(Config_Code::$error['user_not_exist']['code'], array(), Config_Code::$error['user_not_exist']['message']);
} */
$userinfo = array('uid' => $result['uid']);
$userinfo['list'] = Facade_Auth::getAllAuth($result['uid']);
return $this->returnJson($result['code'], $userinfo,$result['message']);
}
return $this->returnJson($result['code'], array(), $result['message']);
}
}
/**
* 登录回调
*/
public function callbackloginAction()
{
if ($this->_request->isPost())
{
$account = trim($this->_request->account) ;
$password = trim($this->_request->password) ;
$fields = trim($this->_request->fields) ;
$callback = trim($this->_request->callback);//回调地址
$method = trim($this->_request->method);//回调地址采用的方法
$data = array();
do
{
if (!$callback )
{
exit('Missing parameter: callback');
}
//校验参数
if (!$method )
{
$data['code'] = Config_Code::$error['missing_parameter']['code'] ;
$data['message'] = Config_Code::$error['missing_parameter']['message'] ;
break;
}
$result = Facade_Auth::checkLogin($account, $password);
if ( isset($result['uid']) )
{
//构造信息返回
$data = $data + Facade_Userinfo::getUserinfoForApp($result['uid'], $fields, $this->_appScope);
}else
{
$data['code'] = $result['code'] ;
$data['message'] = $result['message'] ;
break;
}
}while (false);
return $this->_callback($callback, $method, $data);
}
}
/**
* 根据session
*/
public function getUidBySidAction()
{
if ($this->_request->isPost())
{
$sid = trim($this->_request->sid);
if (!$sid)
{
return $this->returnJson(Config_Code::$error['missing_parameter']['code'], array('uid' => 0),Config_Code::$error['missing_parameter']['message']);
}
$session = Facade_Auth::getSessionBySid($sid);
$uid = isset($session['uid'])?$session['uid']:0 ;
if ($uid)
{
$result = array
(
'uid' => $uid ,
'password' => Facade_Auth::getPassword($uid),
'list' => Facade_Auth::getAllAuth($uid)
);
}else
{
$result = array('uid'=>0) ;
}
return $this->returnJson(Config_Code::$success['system']['code'], $result,Config_Code::$success['system']['code']);
}
}
}