Authored by whb

Merge branch 'develop' of http://git.dev.yoho.cn/web/yohobuy into develop

@@ -49,7 +49,10 @@ class WebAction extends Controller_Abstract @@ -49,7 +49,10 @@ class WebAction extends Controller_Abstract
49 */ 49 */
50 public function init() 50 public function init()
51 { 51 {
52 - Mobile::isGoMobile(); 52 + if (!$this->isAjax()) {
  53 + Mobile::isGoMobile();
  54 + }
  55 +
53 $this->_request = $this->getRequest(); 56 $this->_request = $this->getRequest();
54 57
55 // 设置环境变量 58 // 设置环境变量
@@ -49,29 +49,29 @@ class Mobile @@ -49,29 +49,29 @@ class Mobile
49 49
50 public static function match($url, $host, $uri) 50 public static function match($url, $host, $uri)
51 { 51 {
52 - //guang.yohobuy.com  
53 - //guang.yohobuy.com/1.html  
54 - $list = array(  
55 - array(  
56 - 'match' => '#^([guang\.]*)yohobuy\.com(\/*)$#',  
57 - ),  
58 - array(  
59 - 'match' => '#([guang\.]*)yohobuy.com/([0-9]+).html#',  
60 - 'to' => 'guang.m.yohobuy.com/info/index?id='.substr($uri,1,(strpos($uri,'.')-1)) ,  
61 - ),  
62 - );  
63 - foreach ($list as $value) {  
64 - if (preg_match($value['match'], $url) && !empty($value['to'])) {  
65 - return $value['to'];  
66 - } else if (preg_match($value['match'], $url)) {  
67 - $newHost = self::newHost($host);  
68 - return $newHost . $uri;  
69 - }  
70 - }  
71 -  
72 - $continueList = array('www', 'list', 'search');  
73 - $hostSplit = explode('.', $host);  
74 - return 'm.yohobuy.com'; 52 +// //guang.yohobuy.com
  53 +// //guang.yohobuy.com/1.html
  54 +// $list = array(
  55 +// array(
  56 +// 'match' => '#^([guang\.]*)yohobuy\.com(\/*)$#',
  57 +// ),
  58 +// array(
  59 +// 'match' => '#([guang\.]*)yohobuy.com/([0-9]+).html#',
  60 +// 'to' => 'guang.m.yohobuy.com/info/index?id='.substr($uri,1,(strpos($uri,'.')-1)) ,
  61 +// ),
  62 +// );
  63 +// foreach ($list as $value) {
  64 +// if (preg_match($value['match'], $url) && !empty($value['to'])) {
  65 +// return $value['to'];
  66 +// } else if (preg_match($value['match'], $url)) {
  67 +// $newHost = self::newHost($host);
  68 +// return $newHost . $uri;
  69 +// }
  70 +// }
  71 +//
  72 +// $continueList = array('www', 'list', 'search');
  73 +// $hostSplit = explode('.', $host);
  74 + return 'm.yohobuy.com' . $uri;
75 } 75 }
76 76
77 /** 77 /**
@@ -91,18 +91,18 @@ class Mobile @@ -91,18 +91,18 @@ class Mobile
91 public static function isMobile() 91 public static function isMobile()
92 { 92 {
93 $userAgent = self::getUserAgent(); 93 $userAgent = self::getUserAgent();
94 - $mobile_agents = Array("240x320","acer","acoon","acs-","abacho","ahong","airness","alcatel","amoi","android","anywhereyougo.com","applewebkit/525","applewebkit/532","asus","audio","au-mic","avantogo","becker","benq","bilbo","bird","blackberry","blazer","bleu","cdm-","compal","coolpad","danger","dbtel","dopod","elaine","eric","etouch","fly ","fly_","fly-","go.web","goodaccess","gradiente","grundig","haier","hedy","hitachi","htc","huawei","hutchison","inno","ipad","ipaq","ipod","jbrowser","kddi","kgt","kwc","lenovo","lg ","lg2","lg3","lg4","lg5","lg7","lg8","lg9","lg-","lge-","lge9","longcos","maemo","mercator","meridian","micromax","midp","mini","mitsu","mmm","mmp","mobi","mot-","moto","nec-","netfront","newgen","nexian","nf-browser","nintendo","nitro","nokia","nook","novarra","obigo","palm","panasonic","pantech","philips","phone","pg-","playstation","pocket","pt-","qc-","qtek","rover","sagem","sama","samu","sanyo","samsung","sch-","scooter","sec-","sendo","sgh-","sharp","siemens","sie-","softbank","sony","spice","sprint","spv","symbian","tablet","talkabout","tcl-","teleca","telit","tianyu","tim-","toshiba","tsm","up.browser","utec","utstar","verykool","virgin","vk-","voda","voxtel","vx","wap","wellco","wig browser","wii","windows ce","wireless","xda","xde","zte");  
95 - $is_mobile = false;  
96 if (stristr($userAgent, 'ipad')) { 94 if (stristr($userAgent, 'ipad')) {
97 - return $is_mobile; 95 + return false;
98 } 96 }
99 - foreach ($mobile_agents as $device) { 97 + $mobileAgents = array('iphone','android',"240x320","acer","acoon","acs-","abacho","ahong","airness","alcatel","amoi","anywhereyougo.com","applewebkit/525","applewebkit/532","asus","audio","au-mic","avantogo","becker","benq","bilbo","bird","blackberry","blazer","bleu","cdm-","compal","coolpad","danger","dbtel","dopod","elaine","eric","etouch","fly ","fly_","fly-","go.web","goodaccess","gradiente","grundig","haier","hedy","hitachi","htc","huawei","hutchison","inno","ipad","ipaq","ipod","jbrowser","kddi","kgt","kwc","lenovo","lg ","lg2","lg3","lg4","lg5","lg7","lg8","lg9","lg-","lge-","lge9","longcos","maemo","mercator","meridian","micromax","midp","mini","mitsu","mmm","mmp","mobi","mot-","moto","nec-","netfront","newgen","nexian","nf-browser","nintendo","nitro","nokia","nook","novarra","obigo","palm","panasonic","pantech","philips","phone","pg-","playstation","pocket","pt-","qc-","qtek","rover","sagem","sama","samu","sanyo","samsung","sch-","scooter","sec-","sendo","sgh-","sharp","siemens","sie-","softbank","sony","spice","sprint","spv","symbian","tablet","talkabout","tcl-","teleca","telit","tianyu","tim-","toshiba","tsm","up.browser","utec","utstar","verykool","virgin","vk-","voda","voxtel","vx","wap","wellco","wig browser","wii","windows ce","wireless","xda","xde","zte");
  98 + $isMobile = false;
  99 + foreach ($mobileAgents as $device) {
100 if (stristr($userAgent, $device)) { 100 if (stristr($userAgent, $device)) {
101 - $is_mobile = true; 101 + $isMobile = true;
102 break; 102 break;
103 } 103 }
104 } 104 }
105 - return $is_mobile; 105 + return $isMobile;
106 } 106 }
107 107
108 /** 108 /**
@@ -112,10 +112,9 @@ class Mobile @@ -112,10 +112,9 @@ class Mobile
112 public static function isGoMobile() 112 public static function isGoMobile()
113 { 113 {
114 if (empty($_COOKIE['m2w']) && self::isMobile()) { 114 if (empty($_COOKIE['m2w']) && self::isMobile()) {
115 - $newUrl = self::getNewUrl();  
116 - Header("HTTP/1.1 301 Moved Permanently");  
117 - header('Location:http://'.$newUrl);  
118 - exit; 115 + header("HTTP/1.1 301 Moved Permanently");
  116 + header('Location:http://'.self::getNewUrl());
  117 + exit();
119 } 118 }
120 return true; 119 return true;
121 } 120 }
@@ -137,20 +137,26 @@ class PassportModel @@ -137,20 +137,26 @@ class PassportModel
137 137
138 /* 138 /*
139 * 重写递增计数 cache方法 139 * 重写递增计数 cache方法
140 - * $key cache-key 140 + * $key cache-key,递增存放变量
141 * $offset 递增偏移量 141 * $offset 递增偏移量
142 * $initValue 初始化值 142 * $initValue 初始化值
143 * $expiry 缓存时间 143 * $expiry 缓存时间
144 */ 144 */
145 - public static function increment($key, $offset = 1, $initValue = 0, $expire = 1800) 145 +
  146 + public static function increment($key, $timeKey, $offset = 1, $initValue = 0, $expire = 1800)
146 { 147 {
147 - //初始化key  
148 - if (!Cache::get($key)) {  
149 - Cache::set($key, $initValue, $expire); 148 + //有效期之外清除key
  149 + if (!Cache::get($timeKey) && Cache::get($key)) {
  150 + Cache::delete($key);
  151 + }
  152 + //初始化计时
  153 + if (!Cache::get($timeKey) && !Cache::get($key)) {
  154 + Cache::set($timeKey, TRUE, $expire);
  155 + Cache::set($key, $initValue);
150 } 156 }
151 - //增加偏移量  
152 - $cacheValue = intval(Cache::get($key))+$offset;  
153 - Cache::set($key, $cacheValue, $expire); 157 + //未过期则递增
  158 + $cacheValue = intval(Cache::get($key)) + $offset;
  159 + Cache::set($key, $cacheValue);
154 } 160 }
155 161
156 } 162 }
@@ -113,7 +113,7 @@ class AutouserinfoController extends WebAction @@ -113,7 +113,7 @@ class AutouserinfoController extends WebAction
113 } 113 }
114 //未注册 未绑定 114 //未注册 未绑定
115 if ($res['code'] == 200) { 115 if ($res['code'] == 200) {
116 - $next = Helpers::url('/thirdlogin/index', array( 116 + $next = Helpers::url('/thirdlogin/noregist', array(
117 'openId' => $openId, 117 'openId' => $openId,
118 'sourceType' => $sourceType, 118 'sourceType' => $sourceType,
119 'area' => $area, 119 'area' => $area,
@@ -135,6 +135,9 @@ class AutouserinfoController extends WebAction @@ -135,6 +135,9 @@ class AutouserinfoController extends WebAction
135 $this->echoJson($data); 135 $this->echoJson($data);
136 } 136 }
137 137
  138 + /*
  139 + * 根据手机号获取用户相关信息
  140 + */
138 public static function getUserInfo($area, $mobile) 141 public static function getUserInfo($area, $mobile)
139 { 142 {
140 $userInfo = UserData::getUserInfoByMobile($area, $mobile); 143 $userInfo = UserData::getUserInfoByMobile($area, $mobile);
@@ -162,16 +165,16 @@ class AutouserinfoController extends WebAction @@ -162,16 +165,16 @@ class AutouserinfoController extends WebAction
162 break; 165 break;
163 } 166 }
164 167
165 - $phoneNum = trim($this->post('mobile'));  
166 - $areaCode = trim($this->post('area')); 168 + $mobile = trim($this->post('mobile'));
  169 + $area = trim($this->post('area'));
167 //校验手机号格式 170 //校验手机号格式
168 - if (!is_numeric($phoneNum) || !is_numeric($areaCode)) { 171 + if (!is_numeric($mobile) || !is_numeric($area)) {
169 $data['code'] = 400; 172 $data['code'] = 400;
170 $data['message'] = '手机号码格式不正确'; 173 $data['message'] = '手机号码格式不正确';
171 break; 174 break;
172 } 175 }
173 176
174 - $data = BindData::sendBindMsg($areaCode, $phoneNum); 177 + $data = BindData::sendBindMsg($area, $mobile);
175 if (!isset($data['code'])) { 178 if (!isset($data['code'])) {
176 break; 179 break;
177 } 180 }
@@ -194,17 +197,17 @@ class AutouserinfoController extends WebAction @@ -194,17 +197,17 @@ class AutouserinfoController extends WebAction
194 break; 197 break;
195 } 198 }
196 199
197 - $phoneNum = trim($this->post('mobile'));  
198 - $areaCode = trim($this->post('area')); 200 + $mobile = trim($this->post('mobile'));
  201 + $area= trim($this->post('area'));
199 $code = trim($this->post('code')); //短信验证码 202 $code = trim($this->post('code')); //短信验证码
200 //校验手机号格式 203 //校验手机号格式
201 - if (!is_numeric($phoneNum) || !is_numeric($areaCode)) { 204 + if (!is_numeric($mobile) || !is_numeric($area)) {
202 $data['code'] = 400; 205 $data['code'] = 400;
203 $data['message'] = '手机号码格式不正确'; 206 $data['message'] = '手机号码格式不正确';
204 break; 207 break;
205 } 208 }
206 209
207 - $data = BindData::checkBindCode($areaCode, $phoneNum, $code); 210 + $data = BindData::checkBindCode($area, $mobile, $code);
208 if (!isset($data['code'])) { 211 if (!isset($data['code'])) {
209 break; 212 break;
210 } 213 }
@@ -227,8 +230,8 @@ class AutouserinfoController extends WebAction @@ -227,8 +230,8 @@ class AutouserinfoController extends WebAction
227 break; 230 break;
228 } 231 }
229 232
230 - $phoneNum = trim($this->post('mobile'));  
231 - $areaCode = trim($this->post('area', '86')); 233 + $mobile = trim($this->post('mobile'));
  234 + $area = trim($this->post('area', '86'));
232 $openId = trim($this->post('openId')); 235 $openId = trim($this->post('openId'));
233 $sourceType = trim($this->post('sourceType')); 236 $sourceType = trim($this->post('sourceType'));
234 $code = trim($this->post('code')); //短信验证码 237 $code = trim($this->post('code')); //短信验证码
@@ -236,20 +239,20 @@ class AutouserinfoController extends WebAction @@ -236,20 +239,20 @@ class AutouserinfoController extends WebAction
236 $password = empty($password) ? '' : $password; 239 $password = empty($password) ? '' : $password;
237 240
238 //校验手机号格式 241 //校验手机号格式
239 - if (!is_numeric($phoneNum) || !is_numeric($areaCode)) { 242 + if (!is_numeric($mobile) || !is_numeric($area)) {
240 $data['code'] = 400; 243 $data['code'] = 400;
241 $data['message'] = '手机号码格式不正确'; 244 $data['message'] = '手机号码格式不正确';
242 break; 245 break;
243 } 246 }
244 //校验手机验证码 247 //校验手机验证码
245 - $bindMsgFlag = BindData::checkBindCode($areaCode, $phoneNum, $code); 248 + $bindMsgFlag = BindData::checkBindCode($area, $mobile, $code);
246 if (isset($bindMsgFlag['code']) && $bindMsgFlag['code'] != 200) { 249 if (isset($bindMsgFlag['code']) && $bindMsgFlag['code'] != 200) {
247 $data['code'] = 400; 250 $data['code'] = 400;
248 $data['message'] = '短信验证码不正确'; 251 $data['message'] = '短信验证码不正确';
249 break; 252 break;
250 } 253 }
251 //绑定手机号 254 //绑定手机号
252 - $res = BindData::bindMobile($openId, $sourceType, $phoneNum, $areaCode, $password); 255 + $res = BindData::bindMobile($openId, $sourceType, $mobile, $area, $password);
253 if (!isset($res['code'])) { 256 if (!isset($res['code'])) {
254 break; 257 break;
255 } 258 }
@@ -28,7 +28,7 @@ class LoginController extends WebAction @@ -28,7 +28,7 @@ class LoginController extends WebAction
28 if (!strstr($refer, 'http')) { 28 if (!strstr($refer, 'http')) {
29 $refer = SITE_MAIN . $refer; 29 $refer = SITE_MAIN . $refer;
30 } 30 }
31 - 31 +
32 if (!empty($refer)) { 32 if (!empty($refer)) {
33 $this->setCookie('refer', $refer); 33 $this->setCookie('refer', $refer);
34 } 34 }
@@ -70,7 +70,7 @@ class LoginController extends WebAction @@ -70,7 +70,7 @@ class LoginController extends WebAction
70 */ 70 */
71 public function authAction() 71 public function authAction()
72 { 72 {
73 - $data = array('code' => 400, 'message' => '您输入的密码及账户名不匹配,是否<a href="'.Helpers::url('/passport/back/index').'" target="_blank">忘记密码?</a>', 'data' => ''); 73 + $data = array('code' => 400, 'message' => '您输入的密码及账户名不匹配,是否<a href="' . Helpers::url('/passport/back/index') . '" target="_blank">忘记密码?</a>', 'data' => '');
74 do { 74 do {
75 /* 判断是不是AJAX请求 */ 75 /* 判断是不是AJAX请求 */
76 if (!$this->isAjax()) { 76 if (!$this->isAjax()) {
@@ -108,26 +108,43 @@ class LoginController extends WebAction @@ -108,26 +108,43 @@ class LoginController extends WebAction
108 */ 108 */
109 $ip = Helpers::getClientIp(); 109 $ip = Helpers::getClientIp();
110 $ipKey = md5('ip_signin_' . $ip); 110 $ipKey = md5('ip_signin_' . $ip);
  111 + $ipTimeKey = md5('ip_signin_time' . $ip);
111 $accountKey = md5('account_signin_' . $account); 112 $accountKey = md5('account_signin_' . $account);
112 - PassportModel::increment($ipKey, 1, 0, 3600); 113 + $accountTimeKey = md5('account_signin_time' . $account);
  114 + //cache初始化,非有效时间内清除次数,有效时间内叠加cache计数
  115 + if (!Cache::get($accountTimeKey) && Cache::get($accountKey)) {
  116 + Cache::delete($accountKey);
  117 + }
  118 + if (!Cache::get($accountTimeKey) && !Cache::get($accountKey)) {
  119 + Cache::set($accountTimeKey, true, 1800);
  120 + Cache::set($accountKey, 0);
  121 + }
  122 + if (!Cache::get($ipTimeKey) && Cache::get($ipKey)) {
  123 + Cache::delete($ipKey);
  124 + }
  125 + if (!Cache::get($ipTimeKey) && !Cache::get($ipKey)) {
  126 + Cache::set($ipTimeKey, true, 3600);
  127 + Cache::set($ipKey, 0);
  128 + }
113 $accountTimes = Cache::get($accountKey); 129 $accountTimes = Cache::get($accountKey);
114 - if ($accountTimes > 10) { 130 + $ipTimes = Cache::get($ipKey);
  131 + if ($accountTimes >= 10) {
115 $data = array('code' => 400, 'message' => '您的账号已被暂时锁定,请稍后再试', 'data' => ''); 132 $data = array('code' => 400, 'message' => '您的账号已被暂时锁定,请稍后再试', 'data' => '');
116 break; 133 break;
117 } 134 }
118 -  
119 - $ipTimes = Cache::get($ipKey);  
120 - if ($ipTimes > 100) { 135 + if ($ipTimes >= 100) {
121 $data = array('code' => 400, 'message' => '您尝试的次数过多,账号已被暂时锁定,请稍后再试', 'data' => ''); 136 $data = array('code' => 400, 'message' => '您尝试的次数过多,账号已被暂时锁定,请稍后再试', 'data' => '');
122 break; 137 break;
123 } 138 }
124 $data = LoginData::signin($area, $account, $password, $shoppingKey); 139 $data = LoginData::signin($area, $account, $password, $shoppingKey);
125 if (!isset($data['code']) || $data['code'] != 200 || !isset($data['data']['uid'])) { 140 if (!isset($data['code']) || $data['code'] != 200 || !isset($data['data']['uid'])) {
126 - PassportModel::increment($accountKey, 1, 0, 1800);  
127 - $data = array('code' => 400, 'message' => '您输入的密码及账户名不匹配,是否<a href="'.Helpers::url('/passport/back/index').'" target="_blank">忘记密码?</a>', 'data' => ''); 141 + Cache::set($accountKey, intval(Cache::get($accountKey)) + 1);
  142 + Cache::set($ipKey, intval(Cache::get($ipKey)) + 1);
  143 + $data = array('code' => 400, 'message' => '您输入的密码及账户名不匹配,是否<a href="' . Helpers::url('/passport/back/index') . '" target="_blank">忘记密码?</a>', 'data' => '');
128 break; 144 break;
129 } 145 }
130 146
  147 + //登录成功
131 $refer = $this->getCookie('refer'); 148 $refer = $this->getCookie('refer');
132 if (empty($refer) || strstr($refer, 'signin.html') || strstr($refer, 'passport/login/index')) { 149 if (empty($refer) || strstr($refer, 'signin.html') || strstr($refer, 'passport/login/index')) {
133 $refer = SITE_MAIN; 150 $refer = SITE_MAIN;
@@ -48,7 +48,8 @@ class RegisterController extends WebAction @@ -48,7 +48,8 @@ class RegisterController extends WebAction
48 $ip = Helpers::getClientIp(); 48 $ip = Helpers::getClientIp();
49 $data = array('code' => 400, 'message' => '', 'data' => ''); 49 $data = array('code' => 400, 'message' => '', 'data' => '');
50 $ipKey = md5('ip_checkmobile_' . $ip); 50 $ipKey = md5('ip_checkmobile_' . $ip);
51 - PassportModel::increment($ipKey, 1, 0, 3600); 51 + $ipTimeKey = md5('ip_checkmobile_time_' . $ip);
  52 + PassportModel::increment($ipKey,$ipTimeKey,1, 0, 3600);
52 $ipTimes = Cache::get($ipKey); 53 $ipTimes = Cache::get($ipKey);
53 do{ 54 do{
54 /* 判断是不是AJAX请求 */ 55 /* 判断是不是AJAX请求 */
@@ -60,7 +61,7 @@ class RegisterController extends WebAction @@ -60,7 +61,7 @@ class RegisterController extends WebAction
60 $data['message'] = '手机号码格式不正确'; 61 $data['message'] = '手机号码格式不正确';
61 break; 62 break;
62 } 63 }
63 - if ($ipTimes >= 500) { 64 + if ($ipTimes > 500) {
64 $data['message'] = '由于你IP受限无法注册'; 65 $data['message'] = '由于你IP受限无法注册';
65 break; 66 break;
66 } 67 }
@@ -130,7 +131,8 @@ class RegisterController extends WebAction @@ -130,7 +131,8 @@ class RegisterController extends WebAction
130 } 131 }
131 //发送代码 132 //发送代码
132 $sendCodeKey = md5('send_code_' . $area . '_' . $mobile); 133 $sendCodeKey = md5('send_code_' . $area . '_' . $mobile);
133 - PassportModel::increment($sendCodeKey, 1, 0, 3600); 134 + $sendCodeTimeKey = md5('send_code_time_' . $area . '_' . $mobile);
  135 + PassportModel::increment($sendCodeKey,$sendCodeTimeKey, 1, 0, 3600);
134 $sendCodeTimes = Cache::get($sendCodeKey); 136 $sendCodeTimes = Cache::get($sendCodeKey);
135 if ($sendCodeTimes > 50) { 137 if ($sendCodeTimes > 50) {
136 $data['message'] = '发送验证码太多'; 138 $data['message'] = '发送验证码太多';
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 use Action\WebAction; 3 use Action\WebAction;
4 use Passport\PassportModel; 4 use Passport\PassportModel;
5 use LibModels\Wap\Passport\RegData; 5 use LibModels\Wap\Passport\RegData;
  6 +use WebPlugin\Helpers;
6 7
7 class ThirdloginController extends WebAction 8 class ThirdloginController extends WebAction
8 { 9 {
@@ -24,8 +25,8 @@ class ThirdloginController extends WebAction @@ -24,8 +25,8 @@ class ThirdloginController extends WebAction
24 'simpleHeader' => $simpleHeader, 25 'simpleHeader' => $simpleHeader,
25 'openId' => $openId, 26 'openId' => $openId,
26 'sourceType' => $sourceType, 27 'sourceType' => $sourceType,
27 - 'region' => RegData::getAreasData(),  
28 - 'serviceUrl' => Helpers::url('/help', array('category_id' => 9)) 28 + 'region' => RegData::getAreasData(),//区域
  29 + 'serviceUrl' => Helpers::url('/help', array('category_id' => 9))//服务条款
29 ); 30 );
30 31
31 $this->_view->display('index', $data); 32 $this->_view->display('index', $data);
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 use Action\WebAction; 3 use Action\WebAction;
4 use LibModels\Web\Product\FavoriteData; 4 use LibModels\Web\Product\FavoriteData;
5 use Product\BrandsModel; 5 use Product\BrandsModel;
6 -use product\HotrankModel; 6 +use Product\HotrankModel;
7 7
8 class IndexController extends WebAction 8 class IndexController extends WebAction
9 { 9 {