mirror of
				https://github.com/v2board/v2board.git
				synced 2025-11-01 01:41:47 +08:00 
			
		
		
		
	update: new auth
This commit is contained in:
		| @@ -168,7 +168,6 @@ class AuthController extends Controller | |||||||
|             'auth_data' => base64_encode("{$user->email}:{$user->password}") |             'auth_data' => base64_encode("{$user->email}:{$user->password}") | ||||||
|         ]; |         ]; | ||||||
|  |  | ||||||
|         Helper::setSession($request, $user); |  | ||||||
|         $user->last_login_at = time(); |         $user->last_login_at = time(); | ||||||
|         $user->save(); |         $user->save(); | ||||||
|  |  | ||||||
| @@ -242,10 +241,13 @@ class AuthController extends Controller | |||||||
|             if ($user->banned) { |             if ($user->banned) { | ||||||
|                 abort(500, __('Your account has been suspended')); |                 abort(500, __('Your account has been suspended')); | ||||||
|             } |             } | ||||||
|             Helper::setSession($request, $user); |             $data = [ | ||||||
|  |                 'token' => $user->token, | ||||||
|  |                 'auth_data' => base64_encode("{$user->email}:{$user->password}") | ||||||
|  |             ]; | ||||||
|             Cache::forget($key); |             Cache::forget($key); | ||||||
|             return response([ |             return response([ | ||||||
|                 'data' => true |                 'data' => $data | ||||||
|             ]); |             ]); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -14,8 +14,8 @@ class PassportRoute | |||||||
|             $router->post('/auth/register', 'Passport\\AuthController@register'); |             $router->post('/auth/register', 'Passport\\AuthController@register'); | ||||||
|             $router->post('/auth/login', 'Passport\\AuthController@login'); |             $router->post('/auth/login', 'Passport\\AuthController@login'); | ||||||
|             $router->get ('/auth/token2Login', 'Passport\\AuthController@token2Login'); |             $router->get ('/auth/token2Login', 'Passport\\AuthController@token2Login'); | ||||||
|             $router->post('/auth/forget', 'Passport\\AuthController@forget'); |             $router->post('/auth/forget', 'Passport\\AuthController@forget');                                           // TODO: 1.7.0 remove | ||||||
|             $router->post('/auth/getTempToken', 'Passport\\AuthController@getTempToken'); |             $router->post('/auth/getTempToken', 'Passport\\AuthController@getTempToken');                               // TODO: 1.7.0 remove | ||||||
|             $router->post('/auth/getQuickLoginUrl', 'Passport\\AuthController@getQuickLoginUrl'); |             $router->post('/auth/getQuickLoginUrl', 'Passport\\AuthController@getQuickLoginUrl'); | ||||||
|             $router->post('/auth/loginWithMailLink', 'Passport\\AuthController@loginWithMailLink'); |             $router->post('/auth/loginWithMailLink', 'Passport\\AuthController@loginWithMailLink'); | ||||||
|             // Comm |             // Comm | ||||||
|   | |||||||
| @@ -25,9 +25,7 @@ class UserRoute | |||||||
|             $router->post('/order/save', 'User\\OrderController@save'); |             $router->post('/order/save', 'User\\OrderController@save'); | ||||||
|             $router->post('/order/checkout', 'User\\OrderController@checkout'); |             $router->post('/order/checkout', 'User\\OrderController@checkout'); | ||||||
|             $router->get ('/order/check', 'User\\OrderController@check'); |             $router->get ('/order/check', 'User\\OrderController@check'); | ||||||
|             // TODO: 1.5.6 remove |             $router->get ('/order/details', 'User\\OrderController@detail');                                            // TODO: 1.7.0 remove | ||||||
|             $router->get ('/order/details', 'User\\OrderController@detail'); |  | ||||||
|             // TODO: 1.5.6 remove |  | ||||||
|             $router->get ('/order/detail', 'User\\OrderController@detail'); |             $router->get ('/order/detail', 'User\\OrderController@detail'); | ||||||
|             $router->get ('/order/fetch', 'User\\OrderController@fetch'); |             $router->get ('/order/fetch', 'User\\OrderController@fetch'); | ||||||
|             $router->get ('/order/getPaymentMethod', 'User\\OrderController@getPaymentMethod'); |             $router->get ('/order/getPaymentMethod', 'User\\OrderController@getPaymentMethod'); | ||||||
|   | |||||||
| @@ -19,7 +19,7 @@ class PlanService | |||||||
|     { |     { | ||||||
|         if ($this->plan->capacity_limit === NULL) return true; |         if ($this->plan->capacity_limit === NULL) return true; | ||||||
|         $count = User::where('plan_id', $this->plan->plan_id)->count(); |         $count = User::where('plan_id', $this->plan->plan_id)->count(); | ||||||
|         return $this->plan->capacity_limit - $count; |         return ($this->plan->capacity_limit - $count) > 0; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static function countActiveUsers() |     public static function countActiveUsers() | ||||||
|   | |||||||
| @@ -15,48 +15,85 @@ use Illuminate\Support\Facades\DB; | |||||||
|  |  | ||||||
| class UserService | class UserService | ||||||
| { | { | ||||||
|  |     private function calcResetDayByMonthFirstDay() | ||||||
|  |     { | ||||||
|  |         $today = date('d'); | ||||||
|  |         $lastDay = date('d', strtotime('last day of +0 months')); | ||||||
|  |         return $lastDay - $today; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     private function calcResetDayByExpireDay(int $expiredAt) | ||||||
|  |     { | ||||||
|  |         $day = date('d', $expiredAt); | ||||||
|  |         $today = date('d'); | ||||||
|  |         $lastDay = date('d', strtotime('last day of +0 months')); | ||||||
|  |         if ((int)$day >= (int)$today && (int)$day >= (int)$lastDay) { | ||||||
|  |             return $lastDay - $today; | ||||||
|  |         } | ||||||
|  |         if ((int)$day >= (int)$today) { | ||||||
|  |             return $day - $today; | ||||||
|  |         } else { | ||||||
|  |             return $lastDay - $today + $day; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     private function calcResetDayByYearFirstDay() | ||||||
|  |     { | ||||||
|  |         $nextYear = strtotime(date("Y-01-01", strtotime('+1 year'))); | ||||||
|  |         return (int)(($nextYear - time()) / 86400); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     private function calcResetDayByYearExpiredAt(int $expiredAt) | ||||||
|  |     { | ||||||
|  |         $md = date('m-d', $expiredAt); | ||||||
|  |         $nowYear = strtotime(date("Y-{$md}")); | ||||||
|  |         $nextYear = strtotime('+1 year', $nowYear); | ||||||
|  |         return (int)(($nextYear - time()) / 86400); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public function getResetDay(User $user) |     public function getResetDay(User $user) | ||||||
|     { |     { | ||||||
|         if ($user->expired_at <= time() || $user->expired_at === NULL) return null; |         if ($user->expired_at <= time() || $user->expired_at === NULL) return null; | ||||||
|         // if reset method is not reset |         // if reset method is not reset | ||||||
|         if (isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 2) return null; |         if (!isset($user->plan->reset_traffic_method)) return null; | ||||||
|  |         if ($user->plan->reset_traffic_method === 2) return null; | ||||||
|         if ((int)config('v2board.reset_traffic_method') === 0 || |         switch (true) { | ||||||
|             (isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 0)) |             case ($user->plan->reset_traffic_method === NULL): { | ||||||
|         { |                 $resetTrafficMethod = config('v2board.reset_traffic_method', 0); | ||||||
|             $day = date('d', $user->expired_at); |                 switch ((int)$resetTrafficMethod) { | ||||||
|             $today = date('d'); |                     // month first day | ||||||
|             $lastDay = date('d', strtotime('last day of +0 months')); |                     case 0: | ||||||
|             return $lastDay - $today; |                         return $this->calcResetDayByMonthFirstDay(); | ||||||
|         } |                     // expire day | ||||||
|         if ((int)config('v2board.reset_traffic_method') === 1 || |                     case 1: | ||||||
|             (isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 1)) |                         return $this->calcResetDayByExpireDay($user->expired_at); | ||||||
|         { |                     // no action | ||||||
|             $day = date('d', $user->expired_at); |                     case 2: | ||||||
|             $today = date('d'); |                         return null; | ||||||
|             $lastDay = date('d', strtotime('last day of +0 months')); |                     // year first day | ||||||
|             if ((int)$day >= (int)$today && (int)$day >= (int)$lastDay) { |                     case 3: | ||||||
|                 return $lastDay - $today; |                         return $this->calcResetDayByYearFirstDay(); | ||||||
|  |                     // year expire day | ||||||
|  |                     case 4: | ||||||
|  |                         return $this->calcResetDayByYearExpiredAt($user->expired_at); | ||||||
|  |                 } | ||||||
|  |                 break; | ||||||
|             } |             } | ||||||
|             if ((int)$day >= (int)$today) { |             case ($user->plan->reset_traffic_method === 0): { | ||||||
|                 return $day - $today; |                 return $this->calcResetDayByMonthFirstDay(); | ||||||
|             } else { |             } | ||||||
|                 return $lastDay - $today + $day; |             case ($user->plan->reset_traffic_method === 1): { | ||||||
|  |                 return $this->calcResetDayByExpireDay($user->expired_at); | ||||||
|  |             } | ||||||
|  |             case ($user->plan->reset_traffic_method === 2): { | ||||||
|  |                 return null; | ||||||
|  |             } | ||||||
|  |             case ($user->plan->reset_traffic_method === 3): { | ||||||
|  |                 return $this->calcResetDayByYearFirstDay(); | ||||||
|  |             } | ||||||
|  |             case ($user->plan->reset_traffic_method === 4): { | ||||||
|  |                 return $this->calcResetDayByYearExpiredAt($user->expired_at); | ||||||
|             } |             } | ||||||
|         } |  | ||||||
|         if ((int)config('v2board.reset_traffic_method') === 3 || |  | ||||||
|             (isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 3)) |  | ||||||
|         { |  | ||||||
|             $nextYear = strtotime(date("Y-01-01", strtotime('+1 year'))); |  | ||||||
|             return (int)(($nextYear - time()) / 86400); |  | ||||||
|         } |  | ||||||
|         if ((int)config('v2board.reset_traffic_method') === 4 || |  | ||||||
|             (isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 4)) |  | ||||||
|         { |  | ||||||
|             $md = date('m-d', $user->expired_at); |  | ||||||
|             $nowYear = strtotime(date("Y-{$md}")); |  | ||||||
|             $nextYear = strtotime('+1 year', $nowYear); |  | ||||||
|             return (int)(($nextYear - time()) / 86400); |  | ||||||
|         } |         } | ||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user