BindAccountController.class.php
1.8 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
<?php
/**
* Created by IntelliJ IDEA.
* 绑定HR账号
* User: zhoutao
* Date: 16/9/22
* Time: 上午10:28
*/
namespace Apicp\Controller\Admin;
use VcySDK\Adminer;
use VcySDK\Service;
use VcySDK\Sms;
class BindAccountController extends AbstractController
{
public function Index()
{
extract_field($params, array(
'eaMobile',
'eaPassword',
'eaRealname',
'mobileCode',
'imgCaptchaToken',
'imgCaptchaCode'
));
// 验证验证码信息
$smsSdk = new Sms(Service::instance());
$smsSdk->verifyCode(['scMobile' => $params['eaMobile'], 'scCode' => $params['mobileCode']]);
// 管理员绑定手机号
$adminSdk = new Adminer(Service::instance());
$bindMobileData = [
'eaId' => $this->_login->user['eaId'],
'eaMobile' => $params['eaMobile'],
'eaRealname' => $params['eaRealname']
];
// 如果密码不为空, 则
if (! empty($params['eaPassword'])) {
$bindMobileData['eaPassword'] = $params['eaPassword'];
}
$this->_result = $adminSdk->bindMobile($bindMobileData);
// 新绑定的管理账号
$this->_bindAccount();
return true;
}
/**
* 更新 cookie
*
* @return bool
*/
protected function _bindAccount()
{
$newEaId = $this->_result['adminerInfo']['eaId'];
// 如果绑定后的账号eaId未改变, 则不需要写cookie
if ($newEaId == $this->_login->user['eaId']) {
return true;
}
$enumber = $this->_result['enterpriseInfo']['epEnumber'];
$this->_login->flushAuth($this->_result['adminerInfo'], $this->_login->getAuthPwd($newEaId, $enumber), $enumber);
return true;
}
}