Userinfo.class.php
11.2 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<?php
/**
* 用户信息
*/
class Controller_Userinfo extends Controller_Abstract
{
/**
* 首页
*/
public function indexAction()
{
return 'Run';
}
/**
* 获取用户信息接口
*/
public function getUserinfoAction()
{
if ($this->_request->isPost())
{
$account = trim($this->_request->account) ;
$uid = trim($this->_request->uid) ;
$fields = trim($this->_request->fields) ;
$area = isset($this->_request->area) ? trim($this->_request->area) : '';
//两个参数不能同时为空
if (!$uid && !$account)
{
return $this->returnJson(Config_Code::$error['missing_parameter']['code'],'',Config_Code::$error['missing_parameter']['message']);
}
//如果传递了Account并且uid为空,则根据Account获取口令信息
if (!$uid && $account)
{
$authInfo = Facade_Auth::getAuthByAccount($account, '', $area);
if (!$authInfo)
{
return $this->returnJson(Config_Code::$error['user_not_exist']['code'],'',Config_Code::$error['user_not_exist']['message']);
}
$uid = $authInfo['uid'];
}
//查询用户
$user = Facade_Userinfo::getUserinfoByUid($uid);
if (!$user)
{
return $this->returnJson(Config_Code::$error['user_not_exist']['code'],'',Config_Code::$error['user_not_exist']['message']);
}
//获取用户状态
if ( $user['state'] == Facade_Userinfo::USER_STATE_DISABLED )
{
return $this->returnJson(Config_Code::$error['user_disabled']['code'],'',Config_Code::$error['user_disabled']['message']);
}
$data = Facade_Userinfo::getUserinfoForApp($uid, $fields, $this->_appScope);
//返回密码
if (in_array($this->_appId, array('1392109210','1392109259','1392109260')))
{
$data['password'] = Facade_Auth::getPassword($uid);
}
return $this->returnJson(Config_Code::$success['system']['code'], $data, Config_Code::$success['system']['message']);
}
}
/**
* 更新用户信息
*/
public function updateAction()
{
if ($this->_request->isPost())
{
$uid = trim($this->_request->uid) ;
do
{
//参数不能同时为空
if (!$uid)
{
$ret = $this->returnJson(Config_Code::$error['missing_parameter']['code'],'',Config_Code::$error['missing_parameter']['message']);
break ;
}
//查询用户
$user = Facade_Userinfo::getUserinfoByUid($uid);
if (!$user)
{
$ret = $this->returnJson(Config_Code::$error['user_not_exist']['code'],'',Config_Code::$error['user_not_exist']['message']);
break ;
}
//获取用户状态
if ( $user['state'] == Facade_Userinfo::USER_STATE_DISABLED )
{
$ret = $this->returnJson(Config_Code::$error['user_disabled']['code'],'',Config_Code::$error['user_disabled']['message']);
break ;
}
//@TODO 获取该应用可以更新的信息
$allow_fields = explode(',',$this->_appScope) ;
$updateDate = array() ;
$value = null;
foreach ($allow_fields as $column)
{
$value = trim($this->_request->query($column , '*&^%$#@!@#$%^&'));
// 2014/03/26 hf: 修复平台来源被更新的问题
if ($column != 'app_id' && $value != '*&^%$#@!@#$%^&')
{
$updateDate[$column] = $value;
}
}
if ($updateDate)
{
Facade_Userinfo::updateUserinfo($uid, $updateDate);
$ret = $this->returnJson(Config_Code::$success['userinfo_set']['code'],'',Config_Code::$success['userinfo_set']['message']);
break ;
}
$ret = $this->returnJson(Config_Code::$error['userinfo_set']['code'],'',Config_Code::$error['userinfo_set']['message']);
break ;
}while (false);
return $ret ;
}
}
/**
* 获取所有口令
* @return json
*/
public function getAllAccountAction()
{
if ($this->_request->isPost() || true)
{
$uid = trim($this->_request->uid) ;
if (!$uid)
{
return $this->returnJson(Config_Code::$success['system']['code'], array(), Config_Code::$success['system']['message']);
}
$result = array
(
'password' => Facade_Auth::getPassword($uid),
'list' => Facade_Auth::getAllAuth($uid),
'userinfo' => Facade_Userinfo::getUserinfoForApp($uid),
);
return $this->returnJson(Config_Code::$success['system']['code'], $result, Config_Code::$success['system']['message']);
}
}
/**
* 设置/更新 auth 账号
*/
public function setauthAction()
{
if ($this->_request->isPost())
{
$uid = trim($this->_request->uid) ;
$type = intval($this->_request->type) ;
$auth = trim($this->_request->auth);
$result = Facade_Auth::setAuth($uid, $type, $auth);
if (is_array($result))
{
return $this->returnJson($result['code'], '', $result['message']);
}
return $this->returnJson(Config_Code::$success['system']['code'], '', Config_Code::$success['system']['message']);
}
}
/**
* 解除账号绑定
*
* @return json
*/
public function delauthAction()
{
if ($this->_request->isPost())
{
$uid = trim($this->_request->uid) ;
$auth_type = intval($this->_request->auth_type) ;
$auth_id = trim($this->_request->auth_id);
$result = Facade_Auth::delAuth($uid, $auth_type, $auth_id);
if (is_array($result))
{
return $this->returnJson($result['code'], '', $result['message']);
}
return $this->returnJson(Config_Code::$success['system']['code'], '', Config_Code::$success['system']['message']);
}
}
/**
* 修改密码
*/
public function changepwdAction()
{
if ($this->_request->isPost())
{
$uid = trim($this->_request->uid) ;
$password = $this->_request->password ;
$result = Facade_Auth::setPassword($uid, $password,true);
if ($result !== true)
{
return $this->returnJson($result['code'], '', $result['message']);
}
return $this->returnJson(Config_Code::$success['system']['code'], '', Config_Code::$success['system']['message']);
}
}
/**
* 获取登录账号的相关信息
*
* @return json
*/
public function getauthAction()
{
$authId = $this->_request->query('auth_id', '');
$authType = $this->_request->query('auth_type', '');
$result = array();
if ($authId && is_numeric($authType))
{
$result = Facade_Auth::getAuthByTypeAndAid($authType, $authId);
}
return $this->returnJson(Config_Code::$success['system']['code'], $result, Config_Code::$success['system']['message']);
}
/**
* 移动有货账号关联
*/
public function removeYohobuyAccountAction()
{
$uid = $this->_request->query('uid', '');
$sso_uid = $this->_request->query('sso_uid', '');
if ($uid)
{
if (!$sso_uid)
{
$find = Facade_Userinfo::getYohobuyAccountByShowId($uid) ;
$sso_uid = $find ? $find['sso_uid']:0;
}
if (!$sso_uid)
{
//用户不存在
return $this->returnJson(Config_Code::$error['system']['code'], array(),Config_Code::$error['user_not_exist']['message']);
}
$ret = Facade_Userinfo::removeYohobuyAccount($uid,$sso_uid);
if ($ret['code'] == 200)
{
//成功移除
return $this->returnJson(Config_Code::$success['system']['code'], array(), Config_Code::$success['system']['message']);
}else
{
return $this->returnJson(Config_Code::$error['system']['code'], array(), $ret['message']);
}
}
return $this->returnJson(Config_Code::$error['system']['code'], array(), Config_Code::$error['system']['message']);
}
public function relevanceYohobuyAccountAction()
{
$uid = $this->_request->query('uid', '');
$yohobuy_name = $this->_request->query('yohobuy_name', '');
$yohobuy_pwd = $this->_request->query('yohobuy_pwd', '');
if ($uid && $yohobuy_name && $yohobuy_pwd)
{
$ret = Facade_Userinfo::relevanceYohobuyAccount($uid,$yohobuy_name,$yohobuy_pwd);
if ($ret['code'] == 200)
{
$sso_uid = $ret['sso_uid'];
$name = $this->getYohobuyAccount($sso_uid);
//成功
return $this->returnJson(Config_Code::$success['system']['code'], array('account' => $name), Config_Code::$success['system']['message']);
}else
{
return $this->returnJson(Config_Code::$error['system']['code'], array(), $ret['message']);
}
}
return $this->returnJson(Config_Code::$error['system']['code'], array(), Config_Code::$error['system']['message']);
}
/**
* 获取关联的有货账号
*/
public function getYohobuyAccountAction()
{
$uid = $this->_request->query('uid', '');
if ($uid)
{
$info = Facade_Userinfo::getYohobuyAccountByShowId($uid);
if ($info)
{
$name = $this->getYohobuyAccount($info['sso_uid']);
return $this->returnJson(Config_Code::$success['system']['code'], array('account' => $name,'sso_uid' => $info['sso_uid'],'list' => Facade_Auth::getAllAuth($info['sso_uid'])), Config_Code::$success['system']['message']);
}
return $this->returnJson(Config_Code::$success['system']['code'], array(), Config_Code::$success['system']['message']);
}
return $this->returnJson(Config_Code::$error['system']['code'], array(), Config_Code::$error['system']['message']);
}
private function getYohobuyAccount($sso_uid)
{
$name = '' ;
$accounts = Facade_Auth::getAllAuth($sso_uid);
$email = isset($accounts[Facade_Auth::AUTH_TYPE_EMAIL]) ? $accounts[Facade_Auth::AUTH_TYPE_EMAIL]['auth_id']:'';
$mobile = isset($accounts[Facade_Auth::AUTH_TYPE_MOBILE]) ? $accounts[Facade_Auth::AUTH_TYPE_MOBILE]['auth_id']:'';
if ($email)
{
$name = $email ;
if ($mobile && strstr($email,'@yohoinc'))
{
$name = $mobile ;
}
}elseif ($mobile)
{
$name = $mobile ;
}
return $name ;
}
/**
* 通过SSO_id获取要SHOW_uid
*/
public function getShowUidAction()
{
$sso_uid = $this->_request->sso_uid ;
if ($sso_uid)
{
$find = Facade_Userinfo::getShowUidBySsoId($sso_uid);
if ($find)
{
return $this->returnJson(Config_Code::$success['system']['code'], $find, Config_Code::$success['system']['message']);
}
}
return $this->returnJson(Config_Code::$error['system']['code'], array(), '暂无关联用户');
}
}