Authored by xiaowei

防撞库

... ... @@ -7,6 +7,7 @@ use LibModels\Web\Home\IndexData;
use LibModels\Web\Home\UserData;
use WebPlugin\Images;
use WebPlugin\Captcha;
use WebPlugin\Cache;
/**
* web登录注册等相关数据构建
... ... @@ -134,4 +135,22 @@ class PassportModel
return $ret;
}
/*
* 重写递增计数 cache方法
* $key cache-key
* $offset 递增偏移量
* $initValue 初始化值
* $expiry 缓存时间
*/
public static function increment($key, $offset = 1, $initValue = 0, $expire = 1800)
{
//初始化key
if (!Cache::get($key)) {
Cache::set($key, $initValue, $expire);
}
//增加偏移量
$cacheValue = intval(Cache::get($key))+$offset;
Cache::set($key, $cacheValue, $expire);
}
}
... ...
... ... @@ -109,27 +109,22 @@ class LoginController extends WebAction
$ip = Helpers::getClientIp();
$ipKey = md5('ip_signin_' . $ip);
$accountKey = md5('account_signin_' . $account);
if (!Cache::get($ipKey)) {
Cache::set($ipKey, 0);
}
if (!Cache::get($accountKey)) {
Cache::set($accountKey, 0);
}
Cache::increment($ipKey, 1, 0, 3600);
PassportModel::increment($ipKey, 1, 0, 3600);
$accountTimes = Cache::get($accountKey);
$ipTimes = Cache::get($ipKey);
if ($accountTimes > 10) {
$data = array('code' => 400, 'message' => '您的账号已被暂时锁定,请稍后再试', 'data' => '');
break;
}
$ipTimes = Cache::get($ipKey);
if ($ipTimes > 100) {
$data = array('code' => 400, 'message' => '您尝试的次数过多,账号已被暂时锁定,请稍后再试', 'data' => '');
break;
}
$data = LoginData::signin($area, $account, $password, $shoppingKey);
if (!isset($data['code']) || $data['code'] != 200 || !isset($data['data']['uid'])) {
Cache::increment($accountKey, 1, 0, 1800);
$data = array('code' => 400, 'message' => '您输入的密码及账户名不匹配,是否<a href="'.Helpers::url('/passport/back/index').'" target="_blank">忘记密码?</a>', 'data' => '');
PassportModel::increment($accountKey, 1, 0, 1800);
$data = array('code' => 400, 'message' => '您输入的密码及账户名不匹配,是否<a href="'.Helpers::url('/passport/back/index').'" target="_blank">忘记密码?</a>', 'data' => '');
break;
}
... ...
... ... @@ -48,10 +48,8 @@ class RegisterController extends WebAction
$ip = Helpers::getClientIp();
$data = array('code' => 400, 'message' => '', 'data' => '');
$ipKey = md5('ip_checkmobile_' . $ip);
if (!Cache::get($ipKey)) {
Cache::set($ipKey, 0);
}
$ipTimes = Cache::increment($ipKey, 1, 0, 3600);
PassportModel::increment($ipKey, 1, 0, 3600);
$ipTimes = Cache::get($ipKey);
do{
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
... ... @@ -132,10 +130,8 @@ class RegisterController extends WebAction
}
//发送代码
$sendCodeKey = md5('send_code_' . $area . '_' . $mobile);
if (!Cache::get($sendCodeKey)) {
Cache::set($sendCodeKey, 0);
}
$sendCodeTimes = Cache::increment($sendCodeKey, 1, 0, 3600);
PassportModel::increment($sendCodeKey, 1, 0, 3600);
$sendCodeTimes = Cache::get($sendCodeKey);
if ($sendCodeTimes > 50) {
$data['message'] = '发送验证码太多';
break;
... ...
... ... @@ -25,6 +25,7 @@ class ThirdloginController extends WebAction
'openId' => $openId,
'sourceType' => $sourceType,
'region' => RegData::getAreasData(),
'serviceUrl' => Helpers::url('/help', array('category_id' => 9))
);
$this->_view->display('index', $data);
... ... @@ -57,6 +58,7 @@ class ThirdloginController extends WebAction
* 绑定成功
*
*/
public function bindSuccessAction()
{
... ...