update: new auth

This commit is contained in:
tokumeikoi 2022-07-28 15:13:17 +08:00
commit 5ccf508040
48 changed files with 306 additions and 278 deletions

View File

@ -1,53 +0,0 @@
<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
class CheckUser extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'check: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()
{
$this->resetExpiredUserPlan();
}
private function resetExpiredUserPlan($day = 14)
{
User::where('expired_at', '<', $day * 86400)
->whereNotNull('expired_at')
->update([
'plan_id' => NULL,
'group_id' => NULL
]);
}
}

View File

@ -33,7 +33,6 @@ class Kernel extends ConsoleKernel
$schedule->command('check:order')->everyMinute();
$schedule->command('check:commission')->everyMinute();
$schedule->command('check:ticket')->everyMinute();
$schedule->command('check:user')->daily();
// reset
$schedule->command('reset:traffic')->daily();
$schedule->command('reset:log')->daily();

View File

@ -39,7 +39,7 @@ class ConfigController extends Controller
public function testSendMail(Request $request)
{
$obj = new SendEmailJob([
'email' => $request->session()->get('email'),
'email' => $request->user['email'],
'subject' => 'This is v2board test email',
'template_name' => 'notify',
'template_value' => [

View File

@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin;
use App\Http\Requests\Admin\PlanSave;
use App\Http\Requests\Admin\PlanSort;
use App\Http\Requests\Admin\PlanUpdate;
use App\Services\PlanService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Plan;
@ -16,17 +17,7 @@ class PlanController extends Controller
{
public function fetch(Request $request)
{
$counts = User::select(
DB::raw("plan_id"),
DB::raw("count(*) as count")
)
->where('plan_id', '!=', NULL)
->where(function ($query) {
$query->where('expired_at', '>=', time())
->orWhere('expired_at', NULL);
})
->groupBy("plan_id")
->get();
$counts = PlanService::countActiveUsers();
$plans = Plan::orderBy('sort', 'ASC')->get();
foreach ($plans as $k => $v) {
$plans[$k]->count = 0;

View File

@ -23,7 +23,7 @@ use Laravel\Horizon\Contracts\MasterSupervisorRepository;
class SystemController extends Controller
{
public function getStatus()
public function getSystemStatus()
{
return response([
'data' => [
@ -33,6 +33,11 @@ class SystemController extends Controller
]);
}
public function getQueueStatus()
{
}
protected function getScheduleStatus():bool
{
return (time() - 120) < Cache::get(CacheKey::get('SCHEDULE_LAST_CHECK_AT', null));

View File

@ -68,7 +68,7 @@ class TicketController extends Controller
$ticketService->replyByAdmin(
$request->input('id'),
$request->input('message'),
$request->session()->get('id')
$request->user['id']
);
return response([
'data' => true

View File

@ -167,8 +167,7 @@ class AuthController extends Controller
'token' => $user->token,
'auth_data' => base64_encode("{$user->email}:{$user->password}")
];
$request->session()->put('email', $user->email);
$request->session()->put('id', $user->id);
$user->last_login_at = time();
$user->save();
@ -210,16 +209,8 @@ class AuthController extends Controller
'token' => $user->token,
'auth_data' => base64_encode("{$user->email}:{$user->password}")
];
$request->session()->put('email', $user->email);
$request->session()->put('id', $user->id);
if ($user->is_admin) {
$request->session()->put('is_admin', true);
$data['is_admin'] = true;
}
if ($user->is_staff) {
$request->session()->put('is_staff', true);
$data['is_staff'] = true;
}
if ($user->is_admin) $data['is_admin'] = true;
return response([
'data' => $data
]);
@ -250,14 +241,13 @@ class AuthController extends Controller
if ($user->banned) {
abort(500, __('Your account has been suspended'));
}
$request->session()->put('email', $user->email);
$request->session()->put('id', $user->id);
if ($user->is_admin) {
$request->session()->put('is_admin', true);
}
$data = [
'token' => $user->token,
'auth_data' => base64_encode("{$user->email}:{$user->password}")
];
Cache::forget($key);
return response([
'data' => true
'data' => $data
]);
}
}
@ -302,19 +292,6 @@ class AuthController extends Controller
]);
}
public function check(Request $request)
{
$data = [
'is_login' => $request->session()->get('id') ? true : false
];
if ($request->session()->get('is_admin')) {
$data['is_admin'] = true;
}
return response([
'data' => $data
]);
}
public function forget(AuthForget $request)
{
if (Cache::get(CacheKey::get('EMAIL_VERIFY_CODE', $request->input('email'))) !== $request->input('email_code')) {
@ -335,5 +312,4 @@ class AuthController extends Controller
'data' => true
]);
}
}

View File

@ -57,7 +57,7 @@ class TicketController extends Controller
$ticketService->replyByAdmin(
$request->input('id'),
$request->input('message'),
$request->session()->get('id')
$request->user['id']
);
return response([
'data' => true

View File

@ -16,7 +16,7 @@ class CouponController extends Controller
}
$couponService = new CouponService($request->input('code'));
$couponService->setPlanId($request->input('plan_id'));
$couponService->setUserId($request->session()->get('id'));
$couponService->setUserId($request->user['id']);
$couponService->check();
return response([
'data' => $couponService->getCoupon()

View File

@ -14,11 +14,11 @@ class InviteController extends Controller
{
public function save(Request $request)
{
if (InviteCode::where('user_id', $request->session()->get('id'))->where('status', 0)->count() >= config('v2board.invite_gen_limit', 5)) {
if (InviteCode::where('user_id', $request->user['id'])->where('status', 0)->count() >= config('v2board.invite_gen_limit', 5)) {
abort(500, __('The maximum number of creations has been reached'));
}
$inviteCode = new InviteCode();
$inviteCode->user_id = $request->session()->get('id');
$inviteCode->user_id = $request->user['id'];
$inviteCode->code = Helper::randomChar(8);
return response([
'data' => $inviteCode->save()
@ -28,7 +28,7 @@ class InviteController extends Controller
public function details(Request $request)
{
return response([
'data' => CommissionLog::where('invite_user_id', $request->session()->get('id'))
'data' => CommissionLog::where('invite_user_id', $request->user['id'])
->where('get_amount', '>', 0)
->select([
'id',
@ -43,26 +43,26 @@ class InviteController extends Controller
public function fetch(Request $request)
{
$codes = InviteCode::where('user_id', $request->session()->get('id'))
$codes = InviteCode::where('user_id', $request->user['id'])
->where('status', 0)
->get();
$commission_rate = config('v2board.invite_commission', 10);
$user = User::find($request->session()->get('id'));
$user = User::find($request->user['id']);
if ($user->commission_rate) {
$commission_rate = $user->commission_rate;
}
$stat = [
//已注册用户数
(int)User::where('invite_user_id', $request->session()->get('id'))->count(),
(int)User::where('invite_user_id', $request->user['id'])->count(),
//有效的佣金
(int)Order::where('status', 3)
->where('commission_status', 2)
->where('invite_user_id', $request->session()->get('id'))
->where('invite_user_id', $request->user['id'])
->sum('commission_balance'),
//确认中的佣金
(int)Order::where('status', 3)
->where('commission_status', 0)
->where('invite_user_id', $request->session()->get('id'))
->where('invite_user_id', $request->user['id'])
->sum('commission_balance'),
//佣金比例
(int)$commission_rate,

View File

@ -19,14 +19,9 @@ class KnowledgeController extends Controller
->first()
->toArray();
if (!$knowledge) abort(500, __('Article does not exist'));
$user = User::find($request->session()->get('id'));
$user = User::find($request->user['id']);
$userService = new UserService();
if ($userService->isAvailable($user)) {
$appleId = config('v2board.apple_id');
$appleIdPassword = config('v2board.apple_id_password');
} else {
$appleId = __('No active subscription. Unable to use our provided Apple ID');
$appleIdPassword = __('No active subscription. Unable to use our provided Apple ID');
if (!$userService->isAvailable($user)) {
$this->formatAccessData($knowledge['body']);
}
$subscribeUrl = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$user['token']}");

View File

@ -29,7 +29,7 @@ class OrderController extends Controller
{
public function fetch(Request $request)
{
$model = Order::where('user_id', $request->session()->get('id'))
$model = Order::where('user_id', $request->user['id'])
->orderBy('created_at', 'DESC');
if ($request->input('status') !== null) {
$model->where('status', $request->input('status'));
@ -50,7 +50,7 @@ class OrderController extends Controller
public function detail(Request $request)
{
$order = Order::where('user_id', $request->session()->get('id'))
$order = Order::where('user_id', $request->user['id'])
->where('trade_no', $request->input('trade_no'))
->first();
if (!$order) {
@ -72,14 +72,14 @@ class OrderController extends Controller
public function save(OrderSave $request)
{
$userService = new UserService();
if ($userService->isNotCompleteOrderByUserId($request->session()->get('id'))) {
if ($userService->isNotCompleteOrderByUserId($request->user['id'])) {
abort(500, __('You have an unpaid or pending order, please try again later or cancel it'));
}
$planService = new PlanService($request->input('plan_id'));
$plan = $planService->plan;
$user = User::find($request->session()->get('id'));
$user = User::find($request->user['id']);
if (!$plan) {
abort(500, __('Subscription plan does not exist'));
@ -94,7 +94,7 @@ class OrderController extends Controller
}
if ($request->input('period') === 'reset_price') {
if (!$user->plan_id) {
if (!$user->plan_id || $user->expired_at < time() || $user->expired_at !== NULL) {
abort(500, __('Subscription has expired or no active subscription, unable to purchase Data Reset Package'));
} else {
if ($user->plan_id !== $plan->id) {
@ -121,7 +121,7 @@ class OrderController extends Controller
DB::beginTransaction();
$order = new Order();
$orderService = new OrderService($order);
$order->user_id = $request->session()->get('id');
$order->user_id = $request->user['id'];
$order->plan_id = $plan->id;
$order->period = $request->input('period');
$order->trade_no = Helper::generateOrderNo();
@ -177,7 +177,7 @@ class OrderController extends Controller
$tradeNo = $request->input('trade_no');
$method = $request->input('method');
$order = Order::where('trade_no', $tradeNo)
->where('user_id', $request->session()->get('id'))
->where('user_id', $request->user['id'])
->where('status', 0)
->first();
if (!$order) {
@ -216,7 +216,7 @@ class OrderController extends Controller
{
$tradeNo = $request->input('trade_no');
$order = Order::where('trade_no', $tradeNo)
->where('user_id', $request->session()->get('id'))
->where('user_id', $request->user['id'])
->first();
if (!$order) {
abort(500, __('Order does not exist'));
@ -249,7 +249,7 @@ class OrderController extends Controller
abort(500, __('Invalid parameter'));
}
$order = Order::where('trade_no', $request->input('trade_no'))
->where('user_id', $request->session()->get('id'))
->where('user_id', $request->user['id'])
->first();
if (!$order) {
abort(500, __('Order does not exist'));

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use App\Models\User;
use App\Services\PlanService;
use Illuminate\Http\Request;
use App\Models\Plan;
use Illuminate\Support\Facades\DB;
@ -12,7 +13,7 @@ class PlanController extends Controller
{
public function fetch(Request $request)
{
$user = User::find($request->session()->get('id'));
$user = User::find($request->user['id']);
if ($request->input('id')) {
$plan = Plan::where('id', $request->input('id'))->first();
if (!$plan) {
@ -24,29 +25,16 @@ class PlanController extends Controller
return response([
'data' => $plan
]);
} else {
$counts = User::select(
DB::raw("plan_id"),
DB::raw("count(*) as count")
)
->where('plan_id', '!=', NULL)
->where(function ($query) {
$query->where('expired_at', '>=', time())
->orWhere('expired_at', NULL);
})
->groupBy("plan_id")
->get()
->keyBy('plan_id');
}
$counts = PlanService::countActiveUsers();
$plans = Plan::where('show', 1)
->orderBy('sort', 'ASC')
->get();
if (isset($counts)) {
foreach ($plans as $k => $v) {
if ($plans[$k]->capacity_limit === NULL) continue;
if (!isset($counts[$plans[$k]->id])) continue;
$plans[$k]->capacity_limit = $plans[$k]->capacity_limit - $counts[$plans[$k]->id]->count;
}
foreach ($plans as $k => $v) {
if ($plans[$k]->capacity_limit === NULL) continue;
if (!isset($counts[$plans[$k]->id])) continue;
$plans[$k]->capacity_limit = $plans[$k]->capacity_limit - $counts[$plans[$k]->id]->count;
}
return response([
'data' => $plans

View File

@ -19,7 +19,7 @@ class ServerController extends Controller
{
public function fetch(Request $request)
{
$user = User::find($request->session()->get('id'));
$user = User::find($request->user['id']);
$servers = [];
$userService = new UserService();
if ($userService->isAvailable($user)) {

View File

@ -18,7 +18,7 @@ class StatController extends Controller
'user_id',
'server_rate'
])
->where('user_id', $request->session()->get('id'))
->where('user_id', $request->user['id'])
->where('record_at', '>=', strtotime(date('Y-m-1')))
->orderBy('record_at', 'DESC');
return response([

View File

@ -22,6 +22,6 @@ class TelegramController extends Controller
public function unbind(Request $request)
{
$user = User::where('user_id', $request->session()->get('id'))->first();
$user = User::where('user_id', $request->user['id'])->first();
}
}

View File

@ -21,7 +21,7 @@ class TicketController extends Controller
{
if ($request->input('id')) {
$ticket = Ticket::where('id', $request->input('id'))
->where('user_id', $request->session()->get('id'))
->where('user_id', $request->user['id'])
->first();
if (!$ticket) {
abort(500, __('Ticket does not exist'));
@ -38,7 +38,7 @@ class TicketController extends Controller
'data' => $ticket
]);
}
$ticket = Ticket::where('user_id', $request->session()->get('id'))
$ticket = Ticket::where('user_id', $request->user['id'])
->orderBy('created_at', 'DESC')
->get();
return response([
@ -49,21 +49,21 @@ class TicketController extends Controller
public function save(TicketSave $request)
{
DB::beginTransaction();
if ((int)Ticket::where('status', 0)->where('user_id', $request->session()->get('id'))->lockForUpdate()->count()) {
if ((int)Ticket::where('status', 0)->where('user_id', $request->user['id'])->lockForUpdate()->count()) {
abort(500, __('There are other unresolved tickets'));
}
$ticket = Ticket::create(array_merge($request->only([
'subject',
'level'
]), [
'user_id' => $request->session()->get('id')
'user_id' => $request->user['id']
]));
if (!$ticket) {
DB::rollback();
abort(500, __('Failed to open ticket'));
}
$ticketMessage = TicketMessage::create([
'user_id' => $request->session()->get('id'),
'user_id' => $request->user['id'],
'ticket_id' => $ticket->id,
'message' => $request->input('message')
]);
@ -87,7 +87,7 @@ class TicketController extends Controller
abort(500, __('Message cannot be empty'));
}
$ticket = Ticket::where('id', $request->input('id'))
->where('user_id', $request->session()->get('id'))
->where('user_id', $request->user['id'])
->first();
if (!$ticket) {
abort(500, __('Ticket does not exist'));
@ -95,14 +95,14 @@ class TicketController extends Controller
if ($ticket->status) {
abort(500, __('The ticket is closed and cannot be replied'));
}
if ($request->session()->get('id') == $this->getLastMessage($ticket->id)->user_id) {
if ($request->user['id'] == $this->getLastMessage($ticket->id)->user_id) {
abort(500, __('Please wait for the technical enginneer to reply'));
}
$ticketService = new TicketService();
if (!$ticketService->reply(
$ticket,
$request->input('message'),
$request->session()->get('id')
$request->user['id']
)) {
abort(500, __('Ticket reply failed'));
}
@ -119,7 +119,7 @@ class TicketController extends Controller
abort(500, __('Invalid parameter'));
}
$ticket = Ticket::where('id', $request->input('id'))
->where('user_id', $request->session()->get('id'))
->where('user_id', $request->user['id'])
->first();
if (!$ticket) {
abort(500, __('Ticket does not exist'));
@ -154,7 +154,7 @@ class TicketController extends Controller
)) {
abort(500, __('Unsupported withdrawal method'));
}
$user = User::find($request->session()->get('id'));
$user = User::find($request->user['id']);
$limit = config('v2board.commission_withdraw_limit', 100);
if ($limit > ($user->commission_balance / 100)) {
abort(500, __('The current required minimum withdrawal commission is :limit', ['limit' => $limit]));
@ -164,7 +164,7 @@ class TicketController extends Controller
$ticket = Ticket::create([
'subject' => $subject,
'level' => 2,
'user_id' => $request->session()->get('id')
'user_id' => $request->user['id']
]);
if (!$ticket) {
DB::rollback();
@ -175,7 +175,7 @@ class TicketController extends Controller
__('Withdrawal account') . "" . $request->input('withdraw_account')
);
$ticketMessage = TicketMessage::create([
'user_id' => $request->session()->get('id'),
'user_id' => $request->user['id'],
'ticket_id' => $ticket->id,
'message' => $message
]);

View File

@ -18,17 +18,22 @@ use Illuminate\Support\Facades\Cache;
class UserController extends Controller
{
public function logout(Request $request)
public function checkLogin(Request $request)
{
$request->session()->flush();
$data = [
'is_login' => $request->user['id'] ? true : false
];
if ($request->user['is_admin']) {
$data['is_admin'] = true;
}
return response([
'data' => true
'data' => $data
]);
}
public function changePassword(UserChangePassword $request)
{
$user = User::find($request->session()->get('id'));
$user = User::find($request->user['id']);
if (!$user) {
abort(500, __('The user does not exist'));
}
@ -46,7 +51,6 @@ class UserController extends Controller
if (!$user->save()) {
abort(500, __('Save failed'));
}
$request->session()->flush();
return response([
'data' => true
]);
@ -54,7 +58,7 @@ class UserController extends Controller
public function info(Request $request)
{
$user = User::where('id', $request->session()->get('id'))
$user = User::where('id', $request->user['id'])
->select([
'email',
'transfer_enable',
@ -86,12 +90,12 @@ class UserController extends Controller
{
$stat = [
Order::where('status', 0)
->where('user_id', $request->session()->get('id'))
->where('user_id', $request->user['id'])
->count(),
Ticket::where('status', 0)
->where('user_id', $request->session()->get('id'))
->where('user_id', $request->user['id'])
->count(),
User::where('invite_user_id', $request->session()->get('id'))
User::where('invite_user_id', $request->user['id'])
->count()
];
return response([
@ -101,7 +105,7 @@ class UserController extends Controller
public function getSubscribe(Request $request)
{
$user = User::where('id', $request->session()->get('id'))
$user = User::where('id', $request->user['id'])
->select([
'plan_id',
'token',
@ -131,7 +135,7 @@ class UserController extends Controller
public function resetSecurity(Request $request)
{
$user = User::find($request->session()->get('id'));
$user = User::find($request->user['id']);
if (!$user) {
abort(500, __('The user does not exist'));
}
@ -152,7 +156,7 @@ class UserController extends Controller
'remind_traffic'
]);
$user = User::find($request->session()->get('id'));
$user = User::find($request->user['id']);
if (!$user) {
abort(500, __('The user does not exist'));
}
@ -169,7 +173,7 @@ class UserController extends Controller
public function transfer(UserTransfer $request)
{
$user = User::find($request->session()->get('id'));
$user = User::find($request->user['id']);
if (!$user) {
abort(500, __('The user does not exist'));
}
@ -188,7 +192,7 @@ class UserController extends Controller
public function getQuickLoginUrl(Request $request)
{
$user = User::find($request->session()->get('id'));
$user = User::find($request->user['id']);
if (!$user) {
abort(500, __('The user does not exist'));
}

View File

@ -2,6 +2,7 @@
namespace App\Http;
use Fruitcake\Cors\HandleCors;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
@ -14,6 +15,7 @@ class Kernel extends HttpKernel
* @var array
*/
protected $middleware = [
\App\Http\Middleware\CORS::class,
\App\Http\Middleware\TrustProxies::class,
\App\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
@ -28,22 +30,20 @@ class Kernel extends HttpKernel
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \App\Http\Middleware\EncryptCookies::class,
// \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
// \Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\App\Http\Middleware\CORS::class,
// \Illuminate\View\Middleware\ShareErrorsFromSession::class,
// \App\Http\Middleware\VerifyCsrfToken::class,
// \Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \App\Http\Middleware\EncryptCookies::class,
// \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
// \Illuminate\Session\Middleware\StartSession::class,
\App\Http\Middleware\ForceJson::class,
\App\Http\Middleware\CORS::class,
\App\Http\Middleware\Language::class,
'bindings',
],

View File

@ -3,6 +3,7 @@
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Cache;
class Admin
{
@ -15,9 +16,28 @@ class Admin
*/
public function handle($request, Closure $next)
{
if (!$request->session()->get('is_admin')) {
abort(403, '权限不足');
$authorization = $request->input('auth_data') ?? $request->header('authorization');
if (!$authorization) abort(403, '未登录或登陆已过期');
$authData = explode(':', base64_decode($authorization));
if (!Cache::has($authorization)) {
if (!isset($authData[1]) || !isset($authData[0])) abort(403, '鉴权失败,请重新登入');
$user = \App\Models\User::where('password', $authData[1])
->where('email', $authData[0])
->select([
'id',
'email',
'is_admin',
'is_staff'
])
->first();
if (!$user) abort(403, '鉴权失败,请重新登入');
if (!$user->is_admin) abort(403, '鉴权失败,请重新登入');
Cache::put($authorization, $user->toArray(), 3600);
}
$request->merge([
'user' => Cache::get($authorization)
]);
return $next($request);
}
}

View File

@ -17,8 +17,8 @@ class CORS
}
$response = $next($request);
$response->header('Access-Control-Allow-Origin', trim($origin, '/'));
$response->header('Access-Control-Allow-Methods', 'GET,POST,OPTIONS');
$response->header('Access-Control-Allow-Headers', 'Content-Type,X-Requested-With');
$response->header('Access-Control-Allow-Methods', 'GET,POST,OPTIONS,HEAD');
$response->header('Access-Control-Allow-Headers', 'Origin,Content-Type,Accept,Authorization,X-Request-With');
$response->header('Access-Control-Allow-Credentials', 'true');
$response->header('Access-Control-Max-Age', 10080);

View File

@ -26,7 +26,9 @@ class Client
if (!$user) {
abort(403, 'token is error');
}
$request->user = $user;
$request->merge([
'user' => $user
]);
return $next($request);
}
}

View File

@ -3,6 +3,7 @@
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Cache;
class Staff
{
@ -15,9 +16,28 @@ class Staff
*/
public function handle($request, Closure $next)
{
if (!$request->session()->get('is_staff')) {
abort(403, '权限不足');
$authorization = $request->input('auth_data') ?? $request->header('authorization');
if (!$authorization) abort(403, '未登录或登陆已过期');
$authData = explode(':', base64_decode($authorization));
if (!Cache::has($authorization)) {
if (!isset($authData[1]) || !isset($authData[0])) abort(403, '鉴权失败,请重新登入');
$user = \App\Models\User::where('password', $authData[1])
->where('email', $authData[0])
->select([
'id',
'email',
'is_admin',
'is_staff'
])
->first();
if (!$user) abort(403, '鉴权失败,请重新登入');
if (!$user->is_staff) abort(403, '鉴权失败,请重新登入');
Cache::put($authorization, $user->toArray(), 3600);
}
$request->merge([
'user' => Cache::get($authorization)
]);
return $next($request);
}
}

View File

@ -3,6 +3,7 @@
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Cache;
class User
{
@ -16,19 +17,26 @@ class User
public function handle($request, Closure $next)
{
$authorization = $request->input('auth_data') ?? $request->header('authorization');
if ($authorization) {
$authData = explode(':', base64_decode($authorization));
if (!$authorization) abort(403, '未登录或登陆已过期');
$authData = explode(':', base64_decode($authorization));
if (!Cache::has($authorization)) {
if (!isset($authData[1]) || !isset($authData[0])) abort(403, '鉴权失败,请重新登入');
$user = \App\Models\User::where('password', $authData[1])
->where('email', $authData[0])
->select([
'id',
'email',
'is_admin',
'is_staff'
])
->first();
if (!$user) abort(403, '鉴权失败,请重新登入');
$request->session()->put('email', $user->email);
$request->session()->put('id', $user->id);
}
if (!$request->session()->get('id')) {
abort(403, '未登录或登陆已过期');
Cache::put($authorization, $user->toArray(), 3600);
}
$request->merge([
'user' => Cache::get($authorization)
]);
return $next($request);
}
}

View File

@ -112,7 +112,10 @@ class AdminRoute
$router->post('/payment/drop', 'Admin\\PaymentController@drop');
$router->post('/payment/show', 'Admin\\PaymentController@show');
// System
$router->get ('/system/getStatus', 'Admin\\SystemController@getStatus');
$router->get ('/system/getSystemStatus', 'Admin\\SystemController@getSystemStatus');
$router->get ('/system/getQueueStats', '\\Laravel\\Horizon\\Http\\Controllers\\DashboardStatsController@index');
$router->get ('/system/getQueueWorkload', '\\Laravel\\Horizon\\Http\\Controllers\\WorkloadController@index');
$router->get ('/system/getQueueMasters', '\\Laravel\\Horizon\\Http\\Controllers\\MasterSupervisorController@index');
// Theme
$router->get ('/theme/getThemes', 'Admin\\ThemeController@getThemes');
$router->post('/theme/saveThemeConfig', 'Admin\\ThemeController@saveThemeConfig');

View File

@ -14,9 +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->get ('/auth/check', 'Passport\\AuthController@check');
$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

@ -13,21 +13,19 @@ class UserRoute
], function ($router) {
// User
$router->get ('/resetSecurity', 'User\\UserController@resetSecurity');
$router->get ('/logout', 'User\\UserController@logout');
$router->get ('/info', 'User\\UserController@info');
$router->post('/changePassword', 'User\\UserController@changePassword');
$router->post('/update', 'User\\UserController@update');
$router->get ('/getSubscribe', 'User\\UserController@getSubscribe');
$router->get ('/getStat', 'User\\UserController@getStat');
$router->get ('/checkLogin', 'User\\UserController@checkLogin');
$router->post('/transfer', 'User\\UserController@transfer');
$router->post('/getQuickLoginUrl', 'User\\UserController@getQuickLoginUrl');
// Order
$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

@ -48,10 +48,10 @@ class StatServerJob implements ShouldQueue
//
}
$data = StatServer::where('record_at', $recordAt)
->where('server_id', $this->server['id'])
$data = StatServer::lockForUpdate()
->where('record_at', $recordAt)
->where('server_id', $this->server->id)
->where('server_type', $this->protocol)
->lockForUpdate()
->first();
if ($data) {
try {

View File

@ -4,6 +4,7 @@ namespace App\Services;
use App\Models\Plan;
use App\Models\User;
use Illuminate\Support\Facades\DB;
class PlanService
{
@ -18,6 +19,22 @@ 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()
{
return User::select(
DB::raw("plan_id"),
DB::raw("count(*) as count")
)
->where('plan_id', '!=', NULL)
->where(function ($query) {
$query->where('expired_at', '>=', time())
->orWhere('expired_at', NULL);
})
->groupBy("plan_id")
->get()
->keyBy('plan_id');
}
}

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;
}

View File

@ -2,11 +2,6 @@
namespace App\Utils;
use App\Models\ServerV2ray;
use App\Models\ServerShadowsocks;
use App\Models\ServerTrojan;
use App\Models\User;
class Helper
{
public static function guid($format = false)

View File

@ -74,7 +74,7 @@ return [
|
*/
'middleware' => ['web', 'admin'],
'middleware' => [],
/*
|--------------------------------------------------------------------------

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -147,7 +147,7 @@ window.settings.i18n['en-US'] = {
'重置订阅信息': 'Reset Subscription',
'没有可用节点,如果您未订阅或已过期请': 'No access points are available. If you have not subscribed or the subscription has expired, please',
'订阅': 'Subscribe',
'确定要重置当月流量?': 'Are you sure to reset your usage for the current month?',
'确定重置当前已用流量?': '确定重置当前已用流量?',
'点击「确定」将会跳转到收银台,支付订单后系统将会清空您当月已使用流量。': 'Click "Confirm" and you will be redirected to the payment page. The system will empty your current month\'s usage after your purchase.',
'确定': 'Confirm',
'确定要重置订阅信息?': 'Are you sure to reset your subscription?',
@ -231,7 +231,11 @@ window.settings.i18n['en-US'] = {
'余额支付': 'Balance payment',
'我的工单': 'My Tickets',
'工单历史': 'Ticket History',
'{reset_day} 日后重置流量': 'after {reset_day} days reset usage',
'已用流量将在 {reset_day} 日后重置': '已用流量将在 {reset_day} 日后重置',
'已用流量已在今日重置': '已用流量已在今日重置',
'重置当前已用流量': '重置当前已用流量',
'查看节点状态': '查看节点状态',
'当前已使用流量达{rate}%': '当前已使用流量达{rate}%',
'节点名称': 'Access Point Name',
'于 {date} 到期,距离到期还有 {day} 天。': 'Will expire on {date}, {day} days before expiration, ',
'Telegram 讨论组': 'Telegram Discussion Group',

View File

@ -147,7 +147,7 @@ window.settings.i18n['ja-JP'] = {
'重置订阅信息': 'サブスクリプションURLの変更',
'没有可用节点,如果您未订阅或已过期请': 'ご利用可能なサーバーがありません,プランの期限切れまたは購入なされていない場合は',
'订阅': '購入',
'确定要重置当月流量?': '当月分の使用済みデータ通信量をリセットしますか',
'确定重置当前已用流量?': '确定重置当前已用流量',
'点击「确定」将会跳转到收银台,支付订单后系统将会清空您当月已使用流量。': '「確定」をクリックし次のページへ移動,お支払い後に当月分のデータ通信量は即時リセットされます',
'确定': '確定',
'确定要重置订阅信息?': 'サブスクリプションURLやUUIDをご変更なされますか',
@ -231,7 +231,11 @@ window.settings.i18n['ja-JP'] = {
'余额支付': '残高ご利用分',
'我的工单': 'お問い合わせ',
'工单历史': 'お問い合わせ履歴',
'{reset_day} 日后重置流量': '{reset_day} 日後にカウントリセット',
'已用流量将在 {reset_day} 日后重置': '已用流量将在 {reset_day} 日后重置',
'已用流量已在今日重置': '已用流量已在今日重置',
'重置当前已用流量': '重置当前已用流量',
'查看节点状态': '查看节点状态',
'当前已使用流量达{rate}%': '当前已使用流量达{rate}%',
'节点名称': 'サーバー名',
'于 {date} 到期,距离到期还有 {day} 天。': 'ご利用期限は {date} まで,期限まであと {day} 日',
'Telegram 讨论组': 'Telegramグループ',

View File

@ -147,7 +147,7 @@ window.settings.i18n['ko-KR'] = {
'重置订阅信息': '구독 재설정',
'没有可用节点,如果您未订阅或已过期请': '사용 가능한 액세스 포인트가 없습니다. 구독을 신청하지 않았거나 구독이 만료된 경우',
'订阅': '구독',
'确定要重置当月流量?': '이번 달의 이체 데이터를 재설정하시겠습니까?',
'确定重置当前已用流量?': '确定重置当前已用流量?',
'点击「确定」将会跳转到收银台,支付订单后系统将会清空您当月已使用流量。': '확인"을 클릭하면 결제 페이지로 이동됩니다. 주문이 완료되면 시스템에서 해당 월의 사용 데이터를 삭제합니다.',
'确定': '확인',
'确定要重置订阅信息?': '구독을 재설정하시겠습니까?',
@ -231,7 +231,11 @@ window.settings.i18n['ko-KR'] = {
'余额支付': '잔액 지불',
'我的工单': '나의 티켓',
'工单历史': '티켓 기록',
'{reset_day} 日后重置流量': '{reset_day} 일 후 플로우 재설정',
'已用流量将在 {reset_day} 日后重置': '已用流量将在 {reset_day} 日后重置',
'已用流量已在今日重置': '已用流量已在今日重置',
'重置当前已用流量': '重置当前已用流量',
'查看节点状态': '查看节点状态',
'当前已使用流量达{rate}%': '当前已使用流量达{rate}%',
'节点名称': '환불 금액',
'于 {date} 到期,距离到期还有 {day} 天。': '{day}까지, 만료 {day}일 전.',
'Telegram 讨论组': '텔레그램으로 문의하세요',

View File

@ -147,7 +147,7 @@ window.settings.i18n['vi-VN'] = {
'重置订阅信息': 'Reset thông tin gói',
'没有可用节点,如果您未订阅或已过期请': 'Chưa có node khả dụng, nếu bạn chưa mua gói hoặc đã hết hạn hãy',
'订阅': 'Mua Gói',
'确定要重置当月流量?': 'Xác nhận muốn reset dung lượng tháng này?',
'确定重置当前已用流量?': '确定重置当前已用流量?',
'点击「确定」将会跳转到收银台,支付订单后系统将会清空您当月已使用流量。': 'Ấn 「OK」 sẽ chuyển đến trang thanh toán, sau khi thanh toán đơn hàng hệ thống sẽ xóa dung lượng đã dùng tháng này của bạn.',
'确定': 'OK',
'确定要重置订阅信息?': 'Xác nhận reset thông tin gói dịch vụ?',
@ -231,7 +231,11 @@ window.settings.i18n['vi-VN'] = {
'余额支付': 'Thanh toán số dư',
'我的工单': 'Liên Hệ Với Chúng Tôi',
'工单历史': 'Lịch sử đơn hàng',
'{reset_day} 日后重置流量': '{reset_day} ngày sau reset dung lượng',
'已用流量将在 {reset_day} 日后重置': '已用流量将在 {reset_day} 日后重置',
'已用流量已在今日重置': '已用流量已在今日重置',
'重置当前已用流量': '重置当前已用流量',
'查看节点状态': '查看节点状态',
'当前已使用流量达{rate}%': '当前已使用流量达{rate}%',
'节点名称': 'Tên node',
'于 {date} 到期,距离到期还有 {day} 天。': 'Hết hạn vào {date}, còn {day} ngày.',
'Telegram 讨论组': 'Nhóm Telegram',

View File

@ -147,7 +147,7 @@ window.settings.i18n['zh-CN'] = {
'重置订阅信息': '重置订阅信息',
'没有可用节点,如果您未订阅或已过期请': '没有可用节点,如果您未订阅或已过期请',
'订阅': '订阅',
'确定要重置当月流量?': '确定要重置当月流量?',
'确定重置当前已用流量?': '确定重置当前已用流量?',
'点击「确定」将会跳转到收银台,支付订单后系统将会清空您当月已使用流量。': '点击「确定」将会跳转到收银台,支付订单后系统将会清空您当月已使用流量。',
'确定': '确定',
'确定要重置订阅信息?': '确定要重置订阅信息?',
@ -231,7 +231,11 @@ window.settings.i18n['zh-CN'] = {
'余额支付': '余额支付',
'我的工单': '我的工单',
'工单历史': '工单历史',
'{reset_day} 日后重置流量': '{reset_day} 日后重置流量',
'已用流量将在 {reset_day} 日后重置': '已用流量将在 {reset_day} 日后重置',
'已用流量已在今日重置': '已用流量已在今日重置',
'重置当前已用流量': '重置当前已用流量',
'查看节点状态': '查看节点状态',
'当前已使用流量达{rate}%': '当前已使用流量达{rate}%',
'节点名称': '节点名称',
'于 {date} 到期,距离到期还有 {day} 天。': '于 {date} 到期,距离到期还有 {day} 天。',
'Telegram 讨论组': 'Telegram 讨论组',

View File

@ -147,7 +147,7 @@ window.settings.i18n['zh-TW'] = {
'重置订阅信息': '重置訂閲資訊',
'没有可用节点,如果您未订阅或已过期请': '沒有可用節點,如果您未訂閱或已過期請',
'订阅': '訂閱',
'确定要重置当月流量?': '確定要重置當月流量?',
'确定重置当前已用流量?': '确定重置当前已用流量?',
'点击「确定」将会跳转到收银台,支付订单后系统将会清空您当月已使用流量。': '點擊「確定」將會跳轉到收銀台,支付訂單後系統將會清空您當月已使用流量。',
'确定': '確定',
'确定要重置订阅信息?': '確定要重置訂閱資訊?',
@ -231,7 +231,11 @@ window.settings.i18n['zh-TW'] = {
'余额支付': '餘額支付',
'我的工单': '我的工單',
'工单历史': '工單歷史',
'{reset_day} 日后重置流量': '{reset_day} 日後重置流量',
'已用流量将在 {reset_day} 日后重置': '已用流量将在 {reset_day} 日后重置',
'已用流量已在今日重置': '已用流量已在今日重置',
'重置当前已用流量': '重置当前已用流量',
'查看节点状态': '查看节点状态',
'当前已使用流量达{rate}%': '当前已使用流量达{rate}%',
'节点名称': '節點名稱',
'于 {date} 到期,距离到期还有 {day} 天。': '於 {date} 到期,距離到期還有 {day} 天。',
'Telegram 讨论组': 'Telegram 討論組',

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>网站公告</title>
<title>网站通知</title>
<style type="text/css">
img {
max-width: 100%;
@ -102,7 +102,7 @@
<td class="alert alert-warning"
style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 22px; font-weight: bold; vertical-align: top; color: #fff; font-weight: 500; text-align: center; border-radius: 3px 3px 0 0; background-color: #0073ba; margin: 0; padding: 20px;"
align="center" bgcolor="#0073ba" valign="top">
网站公告
网站通知
</td>
</tr>
<tr

View File

@ -12,7 +12,7 @@
</thead>
<tbody>
<tr style="padding:40px 40px 0 40px;display:table-cell">
<td style="font-size:24px;line-height:1.5;color:#000;margin-top:40px">公告通知</td>
<td style="font-size:24px;line-height:1.5;color:#000;margin-top:40px">网站通知</td>
</tr>
<tr>
<td style="font-size:14px;color:#333;padding:24px 40px 0 40px">