update: new auth

This commit is contained in:
tokumeikoi 2022-07-28 15:05:48 +08:00
parent df8ea58456
commit 5f573f5306
5 changed files with 82 additions and 45 deletions

View File

@ -168,7 +168,6 @@ class AuthController extends Controller
'auth_data' => base64_encode("{$user->email}:{$user->password}")
];
Helper::setSession($request, $user);
$user->last_login_at = time();
$user->save();
@ -242,10 +241,13 @@ class AuthController extends Controller
if ($user->banned) {
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);
return response([
'data' => true
'data' => $data
]);
}
}

View File

@ -14,8 +14,8 @@ class PassportRoute
$router->post('/auth/register', 'Passport\\AuthController@register');
$router->post('/auth/login', 'Passport\\AuthController@login');
$router->get ('/auth/token2Login', 'Passport\\AuthController@token2Login');
$router->post('/auth/forget', 'Passport\\AuthController@forget');
$router->post('/auth/getTempToken', 'Passport\\AuthController@getTempToken');
$router->post('/auth/forget', 'Passport\\AuthController@forget'); // TODO: 1.7.0 remove
$router->post('/auth/getTempToken', 'Passport\\AuthController@getTempToken'); // TODO: 1.7.0 remove
$router->post('/auth/getQuickLoginUrl', 'Passport\\AuthController@getQuickLoginUrl');
$router->post('/auth/loginWithMailLink', 'Passport\\AuthController@loginWithMailLink');
// Comm

View File

@ -25,9 +25,7 @@ class UserRoute
$router->post('/order/save', 'User\\OrderController@save');
$router->post('/order/checkout', 'User\\OrderController@checkout');
$router->get ('/order/check', 'User\\OrderController@check');
// TODO: 1.5.6 remove
$router->get ('/order/details', 'User\\OrderController@detail');
// TODO: 1.5.6 remove
$router->get ('/order/details', 'User\\OrderController@detail'); // TODO: 1.7.0 remove
$router->get ('/order/detail', 'User\\OrderController@detail');
$router->get ('/order/fetch', 'User\\OrderController@fetch');
$router->get ('/order/getPaymentMethod', 'User\\OrderController@getPaymentMethod');

View File

@ -19,7 +19,7 @@ class PlanService
{
if ($this->plan->capacity_limit === NULL) return true;
$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()

View File

@ -15,48 +15,85 @@ use Illuminate\Support\Facades\DB;
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)
{
if ($user->expired_at <= time() || $user->expired_at === NULL) return null;
// if reset method is not reset
if (isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 2) return null;
if ((int)config('v2board.reset_traffic_method') === 0 ||
(isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 0))
{
$day = date('d', $user->expired_at);
$today = date('d');
$lastDay = date('d', strtotime('last day of +0 months'));
return $lastDay - $today;
}
if ((int)config('v2board.reset_traffic_method') === 1 ||
(isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 1))
{
$day = date('d', $user->expired_at);
$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 (!isset($user->plan->reset_traffic_method)) return null;
if ($user->plan->reset_traffic_method === 2) return null;
switch (true) {
case ($user->plan->reset_traffic_method === NULL): {
$resetTrafficMethod = config('v2board.reset_traffic_method', 0);
switch ((int)$resetTrafficMethod) {
// month first day
case 0:
return $this->calcResetDayByMonthFirstDay();
// expire day
case 1:
return $this->calcResetDayByExpireDay($user->expired_at);
// no action
case 2:
return null;
// year first day
case 3:
return $this->calcResetDayByYearFirstDay();
// year expire day
case 4:
return $this->calcResetDayByYearExpiredAt($user->expired_at);
}
break;
}
if ((int)$day >= (int)$today) {
return $day - $today;
} else {
return $lastDay - $today + $day;
case ($user->plan->reset_traffic_method === 0): {
return $this->calcResetDayByMonthFirstDay();
}
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;
}