Email.php
2.27 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
<?php
/**
*
* @author tongdesheng
*
*/
class EmailController extends QLib_Actions_Passport
{
/**
* 注册
*/
public function regAction() {
$code = Q_Utils_Function::base64_url_decode($this->_get('code'));
$strData = Q_Utils_AuthCode::decode($code, YHMConfig_Email::secret_key);
$data = json_decode($strData, true);
//解析后示例:{"email":"393936906@qq.com","type":"emailReg","create_time":1410320588}
$data = json_decode($strData, true);
if(!empty($data)) {
$authInfo = YHMPassport_Models_Auth_Client::getProfileByEmail($data['email']);
if(!empty($authInfo)) {
$ret = YHMPassport_Models_Auth_Client::setActive($authInfo['uid'], $authInfo['profile']);
}
}
}
/**
* 绑定
*/
public function bindAction() {
$code = $this->_get('code');
$strCode = Q_Utils_Function::base64_url_decode($code);
$strData = Q_Utils_AuthCode::decode($strCode, YHMConfig_Email::secret_key);
$data = json_decode($strData, true);
if(!empty($data)) {
//Array ( [email] => 21650828@qq.com [type] => emailBind [create_time] => 1410442907 [uid] => 1 [password] => 123123 )
$uid = $data['uid'];
//只做激活操作
$authInfo = YHMPassport_Models_Auth_Client::getProfileByEmail($data['email']);
if(!empty($authInfo)) {
$ret = YHMPassport_Models_Auth_Client::setActive($uid, $data['email']);
}
}
}
/**
* 找回密码
*/
public function findpwdAction() {
$code = $this->_get('code');
$strCode = Q_Utils_Function::base64_url_decode($code);
$strData = Q_Utils_AuthCode::decode($strCode, YHMConfig_Email::secret_key);
$data = json_decode($strData, true);
if(!empty($data)) {
$this->_assign('code', $code);
}
}
/**
* 重置密码
*/
public function resetpwdAction() {
$code = $this->_post('code');
$password = $this->_post('password');
if(!empty($code)) {
$strCode = Q_Utils_Function::base64_url_decode($code);
$strData = Q_Utils_AuthCode::decode($strCode, YHMConfig_Email::secret_key);
$data = json_decode($strData, true);
if(!empty($data)) {
try {
$authObj = YHMAuth_Factory::profile('web');
$ret = $authObj->updatePassword(0, $password, $data['email'], YHMConfig_Passport::PROFILE_TYPE_MAIL);
}catch (Exception $e) {
$this->_assign('error_msg', $e->getMessage());
}
}
}
}
}