is_admin) { return null; } $profile = $request->server->get('XB_INSTANCE') ?? config('site.profile'); $instances = ['dpl' => 'xb-dpl', 'hn' => 'xb-hn', 'fuc-xb-test' => 'xb-fuc']; $instance = $instances[$profile] ?? null; if (!$instance || (!app()->environment('production') && !is_dir('/run/web-admin-login-'.$instance))) { return null; } require_once '/opt/web-admin-login/current/Ticket.php'; return Ticket::begin($instance, $request->server->all()); } public static function password(Request $request, string $email, callable $verify, callable $issue): array { // Match the account lookup used by this backend, including older releases. $query = method_exists(User::class, 'scopeByEmail') || method_exists(User::class, 'byEmail') ? User::byEmail($email) : User::where('email', $email); $candidate = $query->first(['id','is_admin']); return self::handle($request, $candidate, $verify, $issue); } public static function verified(Request $request, $user, callable $issue) { [, $data] = self::handle($request, $user, fn () => [true, $user], $issue); return $data; } private static function handle(Request $request, $candidate, callable $verify, callable $issue): array { try { $ticket = self::begin($request, $candidate); try { [$success, $result] = $verify(); if ($success) { // Account privileges may have changed during authentication. if ($ticket === null && $result->is_admin && (!$candidate || !$candidate->is_admin)) { $ticket = self::begin($request, $result); } $result = $issue($result); } } catch (\Throwable $error) { if ($ticket !== null) { $ticket->finish('error'); } throw $error; } if ($ticket !== null) { $ticket->finish($success ? 'success' : 'failure'); } return [$success, $result]; } catch (LoginBlocked $error) { abort(429, '该来源 IP 已触发管理员登录保护。'); } catch (GuardUnavailable $error) { abort(503, '管理员登录保护暂不可用,请稍后重试。'); } } }