mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-31 09:21:46 +08:00 
			
		
		
		
	update: register limit by ip
This commit is contained in:
		
							
								
								
									
										51
									
								
								app/Console/Commands/ClearUser.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								app/Console/Commands/ClearUser.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,51 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Console\Commands; | ||||
|  | ||||
| use App\Models\Ticket; | ||||
| use App\Models\User; | ||||
| use Illuminate\Console\Command; | ||||
|  | ||||
| class ClearUser extends Command | ||||
| { | ||||
|     /** | ||||
|      * The name and signature of the console command. | ||||
|      * | ||||
|      * @var string | ||||
|      */ | ||||
|     protected $signature = 'clear:user'; | ||||
|  | ||||
|     /** | ||||
|      * The console command description. | ||||
|      * | ||||
|      * @var string | ||||
|      */ | ||||
|     protected $description = '清理用户'; | ||||
|  | ||||
|     /** | ||||
|      * Create a new command instance. | ||||
|      * | ||||
|      * @return void | ||||
|      */ | ||||
|     public function __construct() | ||||
|     { | ||||
|         parent::__construct(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Execute the console command. | ||||
|      * | ||||
|      * @return mixed | ||||
|      */ | ||||
|     public function handle() | ||||
|     { | ||||
|         $builder = User::where('plan_id', NULL) | ||||
|             ->where('transfer_enable', 0) | ||||
|             ->where('expired_at', 0) | ||||
|             ->where('last_login_at', NULL); | ||||
|         $count = $builder->count(); | ||||
|         if ($builder->delete()) { | ||||
|             $this->info("已删除${count}位没有任何数据的用户"); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -20,6 +20,10 @@ class AuthController extends Controller | ||||
| { | ||||
|     public function register(AuthRegister $request) | ||||
|     { | ||||
|         $registerCountByIP = CacheKey::get('REGISTER_IP_RATE_LIMIT', $request->ip()) || 0; | ||||
|         if ($registerCountByIP >= 3) { | ||||
|             abort(500, __('Register frequently, please try again after 1 hour')); | ||||
|         } | ||||
|         if ((int)config('v2board.recaptcha_enable', 0)) { | ||||
|             $recaptcha = new ReCaptcha(config('v2board.recaptcha_key')); | ||||
|             $recaptchaResp = $recaptcha->verify($request->input('recaptcha_data')); | ||||
| @@ -109,6 +113,9 @@ class AuthController extends Controller | ||||
|         ]; | ||||
|         $request->session()->put('email', $user->email); | ||||
|         $request->session()->put('id', $user->id); | ||||
|         $user->last_login_at = time(); | ||||
|         $user->save(); | ||||
|         Cache::put(CacheKey::get('REGISTER_IP_RATE_LIMIT', $request->ip()), $registerCountByIP + 1, 3600); | ||||
|         return response()->json([ | ||||
|             'data' => $data | ||||
|         ]); | ||||
|   | ||||
| @@ -18,7 +18,8 @@ class CacheKey | ||||
|         'SERVER_SHADOWSOCKS_LAST_PUSH_AT' => 'ss节点最后推送时间', | ||||
|         'TEMP_TOKEN' => '临时令牌', | ||||
|         'LAST_SEND_EMAIL_REMIND_TRAFFIC' => '最后发送流量邮件提醒', | ||||
|         'SCHEDULE_LAST_CHECK_AT' => '计划任务最后检查时间' | ||||
|         'SCHEDULE_LAST_CHECK_AT' => '计划任务最后检查时间', | ||||
|         'REGISTER_IP_RATE_LIMIT' => '注册频率限制' | ||||
|     ]; | ||||
|  | ||||
|     public static function get(string $key, $uniqueValue) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user