Compare commits
2 Commits
dbfd55908e
...
a27ac445c5
| Author | SHA1 | Date | |
|---|---|---|---|
| a27ac445c5 | |||
| c728744d9e |
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Traits\AuthenticatesUser;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@ -14,6 +15,8 @@ use function base_path;
|
||||
|
||||
class ReceiptController extends Controller
|
||||
{
|
||||
use AuthenticatesUser;
|
||||
|
||||
/**
|
||||
* 領収書宛名入力画面を表示する。
|
||||
* 契約IDに基づき、領収書宛名入力フォームを表示する。
|
||||
@ -24,13 +27,12 @@ class ReceiptController extends Controller
|
||||
*/
|
||||
public function input(string $management_code, string $contract_id): mixed
|
||||
{
|
||||
$user_id = session('user_id');
|
||||
if (!$user_id) {
|
||||
// 未認証アクセス(セッション切れ)を追跡するため、INFOログで記録
|
||||
\Log::info("[INFO] " . now()->format('Y-m-d H:i:s') . " 未認証ユーザーによるアクセス(セッション切れ): 領収書宛名入力画面アクセス");
|
||||
return redirect()->guest('/login');
|
||||
if ($redirect = $this->handleSessionExpired('領収書宛名入力', false)) {
|
||||
return $redirect;
|
||||
}
|
||||
|
||||
// ヘッダー表示のためユーザー名取得
|
||||
$user_id = session('user_id');
|
||||
$user_name = DB::table('user')->where('user_id', $user_id)->value('user_name');
|
||||
|
||||
$management = session('management');
|
||||
@ -70,13 +72,12 @@ class ReceiptController extends Controller
|
||||
*/
|
||||
public function issue(Request $request, string $management_code, string $contract_id): mixed
|
||||
{
|
||||
$user_id = session('user_id');
|
||||
if (!$user_id) {
|
||||
// 未認証アクセス(セッション切れ)を追跡するため、INFOログで記録
|
||||
\Log::info("[INFO] " . now()->format('Y-m-d H:i:s') . " 未認証ユーザーによるアクセス(セッション切れ): 領収書発行");
|
||||
return redirect('/login');
|
||||
if ($redirect = $this->handleSessionExpired('領収書宛名入力', false)) {
|
||||
return $redirect;
|
||||
}
|
||||
|
||||
$user_id = session('user_id');
|
||||
|
||||
// 既存レコードがある場合、再発行を促す
|
||||
$exists = DB::table('inv_publish')->where('contract_id', $contract_id)->exists();
|
||||
if ($exists) {
|
||||
@ -148,12 +149,11 @@ class ReceiptController extends Controller
|
||||
public function download(string $management_code, string $contract_id, bool $is_reissue = true): mixed
|
||||
{
|
||||
try {
|
||||
$user_id = session('user_id');
|
||||
if (!$user_id) {
|
||||
// 未認証アクセス(セッション切れ)を追跡するため、INFOログで記録
|
||||
\Log::info("[INFO] " . now()->format('Y-m-d H:i:s') . " 未認証ユーザーによるアクセス(セッション切れ): 領収書ダウンロード");
|
||||
return redirect('/login');
|
||||
if ($redirect = $this->handleSessionExpired('領収書ダウンロード', false)) {
|
||||
return $redirect;
|
||||
}
|
||||
|
||||
$user_id = session('user_id');
|
||||
$management = session('management');
|
||||
$management_id = $management->management_id;
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Traits\AuthenticatesUser;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
@ -12,6 +13,7 @@ use Carbon\Carbon;
|
||||
|
||||
class RegularContractController extends Controller
|
||||
{
|
||||
use AuthenticatesUser;
|
||||
public function showInfo(Request $request)
|
||||
{
|
||||
$user_id = session('user_id');
|
||||
@ -89,13 +91,12 @@ class RegularContractController extends Controller
|
||||
* @param Request $request 受信したHTTPリクエスト
|
||||
* @return mixed ビュー応答またはリダイレクト
|
||||
*/
|
||||
$user_id = session('user_id');
|
||||
if (!$user_id) {
|
||||
// 未認証アクセス(セッション切れ)を追跡するため、INFOログで記録
|
||||
\Log::info("[INFO] " . now()->format('Y-m-d H:i:s') . " 未認証ユーザーによるアクセス(セッション切れ): 定期契約履歴確認画面アクセス");
|
||||
return redirect()->guest('/login');
|
||||
if ($redirect = $this->handleSessionExpired('定期契約履歴確認')) {
|
||||
return $redirect;
|
||||
}
|
||||
|
||||
// ヘッダー表示のためユーザー名取得
|
||||
$user_id = session('user_id');
|
||||
$user_name = DB::table('user')->where('user_id', $user_id)->value('user_name');
|
||||
|
||||
// マルチテナント対応のため、運営元コード、IDを取得
|
||||
|
||||
@ -6,8 +6,6 @@ use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
||||
class ManagementMiddleware
|
||||
{
|
||||
@ -17,10 +15,10 @@ class ManagementMiddleware
|
||||
*
|
||||
* @param Request $request 受信したHTTPリクエスト
|
||||
* @param Closure $next 次のミドルウェア処理
|
||||
* @return Response 次の処理のレスポンス
|
||||
* @return mixed 次の処理のレスポンス
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\HttpException 運営元コードが見つからない場合
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response|RedirectResponse
|
||||
public function handle(Request $request, Closure $next): mixed
|
||||
{
|
||||
// マルチテナント対応のため、URLの最初のセグメントを運営元コードとして扱う
|
||||
$path = $request->getPathInfo(); // パス全体を取得
|
||||
|
||||
48
app/Http/Traits/AuthenticatesUser.php
Normal file
48
app/Http/Traits/AuthenticatesUser.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Traits;
|
||||
|
||||
trait AuthenticatesUser
|
||||
{
|
||||
/**
|
||||
* セッション切れ時のログインリダイレクト(マルチテナント対応)
|
||||
*
|
||||
* @param string|null $screenName ログに記録する画面名
|
||||
* @param bool $saveIntended ログイン後に元のURLに戻るか(true: 戻る, false: マイページ)
|
||||
* @return \Illuminate\Http\RedirectResponse|null
|
||||
*/
|
||||
protected function handleSessionExpired(?string $screenName = null, bool $saveIntended = true)
|
||||
{
|
||||
$userId = session('user_id');
|
||||
|
||||
if ($userId) {
|
||||
return null; // 認証済み
|
||||
}
|
||||
|
||||
// 運営元コード取得
|
||||
$management = session('management');
|
||||
$managementCode = $management->management_code ?? request()->segment(1);
|
||||
|
||||
if (!$managementCode) {
|
||||
\Log::error("[ERROR] " . now()->format('Y-m-d H:i:s') . " 運営元取得失敗 url=" . request()->fullUrl());
|
||||
abort(404);
|
||||
}
|
||||
|
||||
// ログ記録
|
||||
$logMessage = "[INFO] " . now()->format('Y-m-d H:i:s') . " 未認証ユーザーアクセス(セッション切れ)";
|
||||
if ($screenName) {
|
||||
$logMessage .= " {$screenName}画面";
|
||||
}
|
||||
$logMessage .= " management_code=" . $managementCode;
|
||||
\Log::info($logMessage);
|
||||
|
||||
if ($saveIntended) {
|
||||
// ログイン後に元の画面に戻る
|
||||
return redirect()->guest(route('swo8_1', ['management_code' => $managementCode]));
|
||||
} else {
|
||||
// ログイン後はマイページトップへ
|
||||
session()->forget('url.intended');
|
||||
return redirect()->route('swo8_1', ['management_code' => $managementCode]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user