Local.php
7.75 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
<?php
/**
* Created by PhpStorm.
* User: liuziyang
* Date: 14-2-17
* Time: 23:59
*/
class YHMAuth_User_Local extends YHMAuth_User_Abstract
{
public function isExistAuth($profile) {
//手机号
$isMobile = Q_Utils_Validate_Mobile::isValid($profile);
if ($isMobile) {
$exist = YHMPassport_Models_Auth_Client::getProfileByMobile($profile);
if (!empty($exist)) {
return true;
}
}
return false;
}
/**
* 登录
* @param $profile
* @param $inputPassword
* @param string $profileType
* @param string $persistent
* @throws Exception
*/
public function signin($profile, $inputPassword = '', $persistent = 'Y', $append=array())
{
###################### 登录开始触发 ######################
$this->signinPreDispatch($profile, $inputPassword);
###################### 登录开始触发 ######################
$isEmail = Q_Utils_Validate_EmailAddress::isValid($profile);
if($isEmail) {
$authInfo = YHMPassport_Models_Auth_Client::getProfileByEmail($profile);
} else {
$authInfo = YHMPassport_Models_Auth_Client::getProfileByMobile($profile);
}
if(empty($authInfo)) {
throw new Exception('没有找到该用户', 422);
}
//判断是否删除账户
$user_status = YHMPassport_Models_Profile_Client::getInfoByStatus($authInfo['uid'], 0);
if(!empty($user_status)){
throw new Exception('您输入的帐号无法登录,如有疑问请咨询客服', 427);
}
$uid = $authInfo['uid'];
$profile = YHMPassport_Models_Profile_Client::getByUid($uid);
$authPass = Q_Utils_AuthCode::authPassword($inputPassword, $profile['password']);
if(empty($authPass)) {
throw new Exception('账户或密码错误', 422);
}
$this->signinEndDispatch($uid, $append);
#################### 登录结束触发 ####################
$this->_uid = $uid;
return $uid;
}
/**
* 注册
* @param $profile
* @param $password
* @param string $profileType
* @param array $append
* @throws Exception
*/
public function register($profile, $password, array $append = array())
{
###################### 注册开始触发 ######################
$this->registerPreDispatch($profile, $password, $append);
$nick_name = $append['nick_name'];
$password = Q_Utils_AuthCode::makePass($password);
$isEmail = Q_Utils_Validate_EmailAddress::isValid($profile);
if($isEmail) {
//email
$exist = YHMPassport_Models_Auth_Client::getProfileByEmail($profile);
if (!empty($exist)) {
throw new Exception('该Email已经注册');
}
$uid = YHMPassport_Models_Profile_Client::addUserProfile($password, $nick_name);
if (empty($uid)) {
throw new Exception('添加用户失败');
}
$ret = YHMPassport_Models_Auth_Client::addAuth($uid, $profile, YHMConfig_Passport::PROFILE_TYPE_MAIL, $this->_channel, $this->_channelMap['channel_code']);
if(empty($ret)) {
throw new Exception('添加用户认证信息失败');
}
} else {
//mobile
$exist = YHMPassport_Models_Auth_Client::getProfileByMobile($profile);
if(!empty($exist)) {
throw new Exception('该手机号已经注册');
}
$uid = YHMPassport_Models_Profile_Client::addUserProfile($password, $nick_name);
$ret = YHMPassport_Models_Auth_Client::addAuth($uid, $profile, YHMConfig_Passport::PROFILE_TYPE_MOBILE, $this->_channel, $this->_channelMap['channel_code']);
if(empty($ret)) {
throw new Exception('添加用户认证信息失败');
}
}
$this->registerEndDispatch($uid, $append);
$this->_uid = $uid;
return $uid;
}
/**
* 退出
* @param $token
* @param string $sessionKey
* @param null $domain
* @return bool
*/
public function signOut($token, $sessionKey = '_UID', $domain = null)
{
if (!empty($token) && $token == $this->getSession('token_session_key')) {
$this->signOutPreDispatch($this->getSession());
$this->setCookieID('', null, '_UID', -1);
$this->unsetSession();
$this->signOutEndDispatch($this->getSession());
return true;
}
return false;
}
/*
* 第三方登录
*/
public function associate($profile, array $append = array())
{
###################### 登录开始触发 ######################
$this->associatePreDispatch($profile, $append);
###################### 登录开始触发 ######################
#### 检查是否关联过 #####
$auth = YHMPassport_Models_Auth_Client::getAuthByOpenID($profile, $append['profile_type']);
if (!empty($auth)) {
$uid = $auth['uid'];
} else {
$uid = YHMPassport_Models_Profile_Client::addUserProfile('', $append['nick_name'], $append['head_ico'], $append['birthday'], $append['gender']);
if (empty($uid)) {
return self::result(500, '创建用户失败.', $auth);
}
YHMPassport_Models_Auth_Client::addAuth($uid, $userProfile->profile, $append['nick_name'], $append['profile_type'], $this->_channel, $append['channel']);
}
#################### 结束时触发 ####################
$this->associateEndDispatch($uid, $append);
$this->_uid = $uid;
return $uid;
}
/**
* (non-PHPdoc)
* @see YHMAuth_User_Interface::updatePassword()
*/
public function updatePassword($uid, $inputPassword) {
if(intval($uid)<1 || empty($inputPassword)) {
return false;
}
$password = Q_Utils_AuthCode::makePass($inputPassword);
return YHMPassport_Models_Profile_Client::updatePassword($uid, $password);
}
/**
* (non-PHPdoc)
* @see YHMAuth_User_Interface::updateInfo()
*/
public function updateInfo($uid, $userInfo, $profile='', $profile_type=null){
$nick_name = !empty($userInfo['nickname']) ? $userInfo['nickname'] : '';
$gender = $userInfo['gender'];
$code_address = !empty($userInfo['area_code']) ? $userInfo['area_code'] : '';
//如果修改昵称进行后台审核
$user_info = YHMPassport_Models_Profile_Client::getByUid($uid);
if($user_info['nick_name']!=$nick_name){
YHMPassport_Models_Profile_Client::updateStatus($uid, 2);
}
return YHMPassport_Models_Profile_Client::setUserInfoById($uid, $nick_name, $gender, $code_address);
}
/**
* 添加一种认证方式
* @param integer $uid
* @param string $profile
* @param int $profile_type
*/
public function addAuth($uid, $profile, $profile_type, $channel, $password='', $account_name=''){
$profileInfo = YHMPassport_Models_Profile_Client::getByUid($uid);
if(empty($profileInfo)) {
throw new Exception('没有找到该用户', 421);
}
$existAuth = YHMPassport_Models_Auth_Client::checkBindByOpenID($profile, $profile_type);
if(!empty($existAuth)) {
throw new Exception($profile . '已经被绑定', 425);
}
if(in_array($profile_type, array(1,2))) {
//绑定的是手机号或者邮箱,必须要设置密码
if(strlen($profileInfo['password'])<32 && empty($password)) {
throw new Exception('必须设置一个密码才能完成绑定', 422);
}
$_password = Q_Utils_AuthCode::makePass($password);
YHMPassport_Models_Profile_Client::updatePassword($uid, $_password);
}
return YHMPassport_Models_Auth_Client::addAuth($uid, $profile, $account_name, $profile_type, $this->_channel, $channel);
}
}