Passport.php
6.38 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
<?php
namespace Passport;
use LibModels\Web\Home\IndexData;
use LibModels\Web\Home\UserData;
use Configs\WebCacheConfig;
use Configs\ChannelConfig;
use WebPlugin\Images;
use WebPlugin\Captcha;
use WebPlugin\Cache;
use WebPlugin\Helpers;
/**
* web登录注册等相关数据构建
*
* @name PassportModel
* @package models
* @copyright yoho.inc
* @version 1.0 (2015-12-29 14:38:00)
* @author xiaowei <xiaowei.gong@yoho.cn>
*/
class PassportModel
{
const REGISTER_LEFT_BANNER_CODE = 'c479ec90120cae7f96e52922b4917064'; //注册左边的banner
const BACK_LFFT_BANNER_CODE = '3bbaf502c447a2ddad60879042e286d8'; //找回密码左边的banner
const SIGNIN_LEFT_BANNER_CODE = 'db350894e01e90eac55cd3a13ad77331'; //登录页左边的banner
const AUTOUSERINFO_LEFT_BANNER_CODE = 'c62d5da06d843b6ed78d8d27e87fa143'; //完善信息页左边的banner
const BACK_FIND_SECRET_KEY = '_+@#$%^';
/**
* 获取左侧banner
*
* @param string $code
* @return array
*/
public static function getLeftBanner($code)
{
$ret = array();
do {
$key = WebCacheConfig::KEY_WEB_LOGIN_LEFT_BANNER . '_' . $code;
$ret = Cache::get($key);
if (!empty($ret)) {
break;
}
$resource = IndexData::getResourceData($code);
if (!isset($resource['data'][0])) {
$ret = Cache::get($key, 'slave');
if (empty($ret)) {
$ret = array('img' => 'http://img12.static.yhbimg.com/yhb-img01/2015/12/01/07/020a0b6e7ff908d0c2bc4045b4fef42b9f.png?imageView/2/w/252/h/190', 'url' => '');
}
break;
}
if ($resource['data'][0]['template_name'] == 'single_image') {
$val = current($resource['data'][0]['data']);
}
else if ($resource['data'][0]['template_name'] == 'single_name_image') {
$val = $resource['data'][0]['data'];
}
$ret['img'] = Images::getImageUrl($val['src'], 252, 190);
$ret['url'] = $val['url'];
// 设置缓存
Cache::set($key, $ret);
}
while (false);
return $ret;
}
/**
* 校验验证码
*
* @param string $verifyCode
* @return boolean
*/
public static function verifyCode($verifyCode)
{
$verifyCode = strtolower($verifyCode);
$ret = true;
//检测验证码不正确
if ($verifyCode != strtolower(Captcha::getFromSession('passport_istration'))) {
$ret = false;
}
return $ret;
}
/**
* 根据手机号获取用户信息
*
* @param string $area
* @param string $mobile
* @return array
*/
public static function getUserInfoByMobile($area, $mobile)
{
$key = WebCacheConfig::KEY_PASSPORT_USER_DATA . '_' . $area . '_' . $mobile;
$ret = Cache::get($key);
if (empty($ret)) {
$data = UserData::getUserInfoByMobile($area, $mobile);
if ($data['code'] == 200) {
if (!empty($data['data'])) {
$ret = $data['data'];
Cache::set($key, $ret, 600);
}
}
}
return $ret;
}
/**
* 根据邮箱获取用户信息
*
* @param string $email
* @return array
*/
public static function getUserInfoByEmail($email)
{
$key = WebCacheConfig::KEY_PASSPORT_USER_DATA . '_' . $email;
$ret = Cache::get($key);
if (empty($ret)) {
$data = UserData::getUserInfoByEmail($email);
if ($data['code'] == 200) {
if (!empty($data['data'])) {
$ret = $data['data'];
Cache::set($key, $ret, 600);
}
}
}
return $ret;
}
/**
* 确认邮箱登录是否绑定过手机号
* @param type $email
*/
public static function emailBindCheck($email)
{
$ret = false;
$key = WebCacheConfig::KEY_PASSPORT_USER_DATA . '_bind_' . $email;
$userInfo = Cache::get($key);
if (empty($userInfo)) {
$userInfo = UserData::getUserInfoByEmail($email);
if ($userInfo['code'] == 200 && !empty($userInfo['data'])) {
Cache::set($key, $userInfo, 600);
}
}
$user = isset($userInfo['data']) ? $userInfo['data'] : '';
if (isset($user['mobile']) && !$user['mobile']) {
$ret = true;
}
return $ret;
}
/**
* URL中是否包含关键字,需要跳转首页
*/
public static function redirectHome($url)
{
$ret = false;
$keyArr = ChannelConfig::$loginUrlKeys;
foreach ($keyArr as $key) {
if (strstr($url, $key)) {
$ret = true;
break;
}
}
return $ret;
}
/**
* 第三方登录 根据手机号获取用户相关信息
*/
public static function getUserInfo($area, $mobile)
{
$userInfo = UserData::getUserInfoByMobile($area, $mobile);
$user = array('username' => '', 'headImg' => '', 'bindLogin' => '');
$userTmp = array();
if (isset($userInfo['data'])) {
$userTmp = $userInfo['data'];
}
if ($userTmp) {
//*号临时处理
$profileName = isset($userTmp['profile_name']) ? trim($userTmp['profile_name']) : '';
if (!$profileName) {
$profileName = $mobile;
}
if ((strlen($profileName) == 11 && !strpos('*', $profileName)) || (strpos($profileName, "-") && !strpos('*', $profileName))) {
$profileName = substr_replace($profileName, '****', 3, 4);
}
$user = array(
'username' => $profileName,
'headImg' => (isset($userTmp['head_ico']) && !empty($userTmp['head_ico'])) ? Images::getImageUrl($userTmp['head_ico'], 100, 100, 2, 'yhb-head') : ChannelConfig::$headDefaultImgIco,
'bindLogin' => Helpers::url('/signin.html', array('bindMobile' => $mobile, 'bindArea' => $area)),
);
}
return $user;
}
}