Authored by xiaowei

防撞库

@@ -7,6 +7,7 @@ use LibModels\Web\Home\IndexData; @@ -7,6 +7,7 @@ use LibModels\Web\Home\IndexData;
7 use LibModels\Web\Home\UserData; 7 use LibModels\Web\Home\UserData;
8 use WebPlugin\Images; 8 use WebPlugin\Images;
9 use WebPlugin\Captcha; 9 use WebPlugin\Captcha;
  10 +use WebPlugin\Cache;
10 11
11 /** 12 /**
12 * web登录注册等相关数据构建 13 * web登录注册等相关数据构建
@@ -134,4 +135,22 @@ class PassportModel @@ -134,4 +135,22 @@ class PassportModel
134 return $ret; 135 return $ret;
135 } 136 }
136 137
  138 + /*
  139 + * 重写递增计数 cache方法
  140 + * $key cache-key
  141 + * $offset 递增偏移量
  142 + * $initValue 初始化值
  143 + * $expiry 缓存时间
  144 + */
  145 + public static function increment($key, $offset = 1, $initValue = 0, $expire = 1800)
  146 + {
  147 + //初始化key
  148 + if (!Cache::get($key)) {
  149 + Cache::set($key, $initValue, $expire);
  150 + }
  151 + //增加偏移量
  152 + $cacheValue = intval(Cache::get($key))+$offset;
  153 + Cache::set($key, $cacheValue, $expire);
  154 + }
  155 +
137 } 156 }
@@ -109,26 +109,21 @@ class LoginController extends WebAction @@ -109,26 +109,21 @@ class LoginController extends WebAction
109 $ip = Helpers::getClientIp(); 109 $ip = Helpers::getClientIp();
110 $ipKey = md5('ip_signin_' . $ip); 110 $ipKey = md5('ip_signin_' . $ip);
111 $accountKey = md5('account_signin_' . $account); 111 $accountKey = md5('account_signin_' . $account);
112 - if (!Cache::get($ipKey)) {  
113 - Cache::set($ipKey, 0);  
114 - }  
115 - if (!Cache::get($accountKey)) {  
116 - Cache::set($accountKey, 0);  
117 - }  
118 - Cache::increment($ipKey, 1, 0, 3600); 112 + PassportModel::increment($ipKey, 1, 0, 3600);
119 $accountTimes = Cache::get($accountKey); 113 $accountTimes = Cache::get($accountKey);
120 - $ipTimes = Cache::get($ipKey);  
121 if ($accountTimes > 10) { 114 if ($accountTimes > 10) {
122 $data = array('code' => 400, 'message' => '您的账号已被暂时锁定,请稍后再试', 'data' => ''); 115 $data = array('code' => 400, 'message' => '您的账号已被暂时锁定,请稍后再试', 'data' => '');
123 break; 116 break;
124 } 117 }
  118 +
  119 + $ipTimes = Cache::get($ipKey);
125 if ($ipTimes > 100) { 120 if ($ipTimes > 100) {
126 $data = array('code' => 400, 'message' => '您尝试的次数过多,账号已被暂时锁定,请稍后再试', 'data' => ''); 121 $data = array('code' => 400, 'message' => '您尝试的次数过多,账号已被暂时锁定,请稍后再试', 'data' => '');
127 break; 122 break;
128 } 123 }
129 $data = LoginData::signin($area, $account, $password, $shoppingKey); 124 $data = LoginData::signin($area, $account, $password, $shoppingKey);
130 if (!isset($data['code']) || $data['code'] != 200 || !isset($data['data']['uid'])) { 125 if (!isset($data['code']) || $data['code'] != 200 || !isset($data['data']['uid'])) {
131 - Cache::increment($accountKey, 1, 0, 1800); 126 + PassportModel::increment($accountKey, 1, 0, 1800);
132 $data = array('code' => 400, 'message' => '您输入的密码及账户名不匹配,是否<a href="'.Helpers::url('/passport/back/index').'" target="_blank">忘记密码?</a>', 'data' => ''); 127 $data = array('code' => 400, 'message' => '您输入的密码及账户名不匹配,是否<a href="'.Helpers::url('/passport/back/index').'" target="_blank">忘记密码?</a>', 'data' => '');
133 break; 128 break;
134 } 129 }
@@ -48,10 +48,8 @@ class RegisterController extends WebAction @@ -48,10 +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 - if (!Cache::get($ipKey)) {  
52 - Cache::set($ipKey, 0);  
53 - }  
54 - $ipTimes = Cache::increment($ipKey, 1, 0, 3600); 51 + PassportModel::increment($ipKey, 1, 0, 3600);
  52 + $ipTimes = Cache::get($ipKey);
55 do{ 53 do{
56 /* 判断是不是AJAX请求 */ 54 /* 判断是不是AJAX请求 */
57 if (!$this->isAjax()) { 55 if (!$this->isAjax()) {
@@ -132,10 +130,8 @@ class RegisterController extends WebAction @@ -132,10 +130,8 @@ class RegisterController extends WebAction
132 } 130 }
133 //发送代码 131 //发送代码
134 $sendCodeKey = md5('send_code_' . $area . '_' . $mobile); 132 $sendCodeKey = md5('send_code_' . $area . '_' . $mobile);
135 - if (!Cache::get($sendCodeKey)) {  
136 - Cache::set($sendCodeKey, 0);  
137 - }  
138 - $sendCodeTimes = Cache::increment($sendCodeKey, 1, 0, 3600); 133 + PassportModel::increment($sendCodeKey, 1, 0, 3600);
  134 + $sendCodeTimes = Cache::get($sendCodeKey);
139 if ($sendCodeTimes > 50) { 135 if ($sendCodeTimes > 50) {
140 $data['message'] = '发送验证码太多'; 136 $data['message'] = '发送验证码太多';
141 break; 137 break;
@@ -25,6 +25,7 @@ class ThirdloginController extends WebAction @@ -25,6 +25,7 @@ class ThirdloginController extends WebAction
25 'openId' => $openId, 25 'openId' => $openId,
26 'sourceType' => $sourceType, 26 'sourceType' => $sourceType,
27 'region' => RegData::getAreasData(), 27 'region' => RegData::getAreasData(),
  28 + 'serviceUrl' => Helpers::url('/help', array('category_id' => 9))
28 ); 29 );
29 30
30 $this->_view->display('index', $data); 31 $this->_view->display('index', $data);
@@ -57,6 +58,7 @@ class ThirdloginController extends WebAction @@ -57,6 +58,7 @@ class ThirdloginController extends WebAction
57 * 绑定成功 58 * 绑定成功
58 * 59 *
59 */ 60 */
  61 +
60 public function bindSuccessAction() 62 public function bindSuccessAction()
61 { 63 {
62 64