Browse Source

登录防刷

lizhen_gitee 3 months ago
parent
commit
54bebfbbe6
2 changed files with 18 additions and 7 deletions
  1. 7 0
      application/api/controller/Index.php
  2. 11 7
      application/api/controller/User.php

+ 7 - 0
application/api/controller/Index.php

@@ -50,6 +50,13 @@ class Index extends Api
     //领取
     public function lingqu(){
 
+        $exam_user_top = Db::name('exam_user_top')->where('user_id',$this->auth->id)->order('id asc')->find();
+        if(!empty($exam_user_top) && !empty($exam_user_top['info'])){
+            $zhongjiang['zhongjiang_status'] = 1;
+            $zhongjiang['user_kami'] = $exam_user_top['info'];
+        }
+
+        $this->success('领取成功');
     }
 
 }

+ 11 - 7
application/api/controller/User.php

@@ -31,8 +31,8 @@ class User extends Api
      */
     public function mobilelogin()
     {
-        $mobile = $this->request->post('mobile');
-        $captcha = $this->request->post('captcha');
+        $mobile = $this->request->post('mobile','','trim,intval');
+        $captcha = $this->request->post('captcha','','trim,intval');
         if (!$mobile || !$captcha) {
             $this->error(__('Invalid parameters'));
         }
@@ -40,12 +40,15 @@ class User extends Api
             $this->error(__('Mobile is incorrect'));
         }
 
+        if(!$this->apiLimit(60,1,'60_'.$mobile)){
+            $this->error('您的手机号登录频繁,请一分钟后再试');
+        };
+        if(!$this->apiLimit(3600,10,'3600_'.$mobile)){
+            $this->error('您的手机号登录频繁,请一小时后再试!');
+        };
         if(!$this->apiLimit(60,10,request()->ip())){
             $this->error('当前登录人数过多,请稍后再试');
         };
-        if(!$this->apiLimit(3600,10,$mobile)){
-            $this->error('您的手机号登录频繁,请稍后再试');
-        };
 
 
         if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
@@ -54,11 +57,12 @@ class User extends Api
         $user = \app\common\model\User::getByMobile($mobile);
         if ($user) {
             if ($user->status != 1) {
-                $this->error(__('Account is locked'));
+                $this->error('网络开小差了请稍后重试');
             }
             //如果已经有账号则直接登录
             $ret = $this->auth->direct($user->id);
         } else {
+            $this->error('注册已截止');
             $ret = $this->auth->register('', '', '', $mobile, []);
         }
         if ($ret) {
@@ -100,7 +104,7 @@ class User extends Api
     public function profile()
     {
         $avatar   = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
-        $nickname = input('nickname', '');
+        $nickname = input('nickname', '', 'trim,htmlspecialchars');
 
         //修改用户
         $data = [];