locked-account page functionality works

This commit is contained in:
armiejean 2025-05-21 09:01:18 +08:00
parent 2d920f245a
commit aa46ddde7f
3 changed files with 179 additions and 41 deletions

View File

@ -175,8 +175,110 @@ class LockedAccountController extends Controller
} }
} }
public function show() public function show($uuid)
{ {
return view('pages.locked-account-view'); try {
// Verify session data
$user = Session::get('user');
Log::debug('Session user data', ['user' => $user]);
if (!$user || !isset($user['access_token'])) {
Log::warning('No user or access token found in session', ['uuid' => $uuid]);
return redirect()->route('login')->with('error', 'Please log in to view the account.');
}
$accessToken = $user['access_token'];
Log::debug('Access token in show method', ['access_token' => $accessToken]);
// Log the API request details
$apiUrl = "{$this->apiBaseUrl}/cms/member/{$uuid}";
Log::debug('Making API call to fetch locked account details', [
'url' => $apiUrl,
'uuid' => $uuid,
]);
// Make the API call
$response = Http::withHeaders([
'Accept' => 'application/json',
'Authorization' => 'Bearer ' . $accessToken,
])->timeout(10)->get($apiUrl);
// Log the raw response
Log::debug('Show API response received', [
'status' => $response->status(),
'headers' => $response->headers(),
'body' => $response->body(),
]);
// Handle specific HTTP status codes
if ($response->status() === 401 || $response->status() === 403) {
Log::warning('Unauthorized or Forbidden API response', [
'uuid' => $uuid,
'response' => $response->json(),
]);
return redirect()->route('login')->with('error', 'Your session has expired. Please log in again.');
}
if ($response->status() === 404) {
Log::warning('Account not found in API', [
'uuid' => $uuid,
'response' => $response->json(),
]);
return redirect()->route('locked-accounts')->with('error', 'The requested account does not exist.');
}
if (!$response->successful()) {
Log::error('API request failed', [
'uuid' => $uuid,
'status' => $response->status(),
'response' => $response->json(),
]);
return redirect()->route('locked-accounts')->with('error', 'Failed to fetch account data from the server. Status: ' . $response->status());
}
// Parse the response
$json = $response->json();
Log::debug('Parsed API response', ['json' => $json]);
if (!isset($json['data']) || !is_array($json['data'])) {
Log::warning('Invalid or missing data in API response', [
'uuid' => $uuid,
'response' => $json,
]);
return redirect()->route('locked-accounts')->with('error', 'Invalid account data received from the server.');
}
// Map the data
$account = [
'id' => $json['data']['lcard_uuid'] ?? null,
'cardNumber' => $json['data']['card_number'] ?? '',
'firstName' => $json['data']['firstname'] ?? '',
'lastName' => $json['data']['lastname'] ?? '',
'birthday' => $json['data']['birthdate'] ?? '',
'cardType' => $json['data']['card_type'] ?? '',
'status' => $json['data']['status'] ? 'Active' : 'Inactive',
'is_locked' => $json['data']['is_locked'] ?? 1,
];
Log::debug('Mapped account data', ['account' => $account]);
return view('pages.locked-account-view', [
'member' => $account,
]);
} catch (\Illuminate\Http\Client\ConnectionException $e) {
Log::error('Connection error in LockedAccountController show method', [
'uuid' => $uuid,
'message' => $e->getMessage(),
'trace' => $e->getTraceAsString(),
]);
return redirect()->route('locked-accounts')->with('error', 'Unable to connect to the server. Please try again later.');
} catch (\Exception $e) {
Log::error('Unexpected error in LockedAccountController show method', [
'uuid' => $uuid,
'message' => $e->getMessage(),
'trace' => $e->getTraceAsString(),
]);
return redirect()->route('locked-accounts')->with('error', 'An unexpected error occurred while fetching the account: ' . $e->getMessage());
} }
} }
}

View File

@ -3,45 +3,81 @@
@section('page_title', 'View Locked Account') @section('page_title', 'View Locked Account')
@section('content') @section('content')
<div class="container-fluid py-4">
<div class="row justify-content-center">
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header border-0 bg-transparent">
<h5 class="mb-0 fw-bold text-dark">View Locked Account</h5> <h5 class="mb-0">View Locked Account</h5>
</div> </div>
<div class="card-body"> <div class="card-body">
@if (session('success'))
<div class="alert alert-success alert-dismissible fade show" role="alert">
{{ session('success') }}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
@endif
@if (session('error')) @if (session('error'))
<div class="alert alert-danger alert-dismissible fade show" role="alert"> <div class="alert alert-danger alert-dismissible fade show" role="alert">
{{ session('error') }} {{ session('error') }}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div> </div>
@endif @endif
@if (isset($member))
<div class="row">
<div class="col-md-6">
<div class="mb-3"> <div class="mb-3">
<strong>Card Number:</strong> {{ $member['cardNumber'] }} <label class="form-label">Card Number</label>
<input type="text" class="form-control" value="{{ $member['cardNumber'] ?? 'N/A' }}" readonly>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<strong>First Name:</strong> {{ $member['firstName'] }} <label class="form-label">First Name</label>
<input type="text" class="form-control" value="{{ $member['firstName'] ?? 'N/A' }}" readonly>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<strong>Last Name:</strong> {{ $member['lastName'] }} <label class="form-label">Last Name</label>
<input type="text" class="form-control" value="{{ $member['lastName'] ?? 'N/A' }}" readonly>
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
<label class="form-label">Birthday</label>
<input type="text" class="form-control" value="{{ $member['birthday'] ? \Carbon\Carbon::parse($member['birthday'])->format('m/d/Y') : 'N/A' }}" readonly>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<strong>Birthday:</strong> {{ $member['birthday'] ? date('F d, Y', strtotime($member['birthday'])) : 'N/A' }} <label class="form-label">Card Type</label>
<input type="text" class="form-control" value="{{ $member['cardType'] ?? 'N/A' }}" readonly>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<strong>Card Type:</strong> {{ $member['cardType'] }} <label class="form-label">Status</label>
<input type="text" class="form-control" value="{{ $member['status'] ?? 'N/A' }}" readonly>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<strong>Status:</strong> {{ $member['status'] }} <label class="form-label">Lock Status</label>
<input type="text" class="form-control" value="{{ $member['is_locked'] == 1 ? 'Locked' : 'Unlocked' }}" readonly>
</div> </div>
<div class="mb-3">
<strong>Lock Status:</strong> {{ $member['is_locked'] == 1 ? 'Locked' : 'Unlocked' }}
</div> </div>
<div class="d-flex gap-2"> </div>
<a href="{{ route('locked-account') }}" class="btn btn-secondary">Back</a>
<form action="{{ route('locked-account.activate', $member['id']) }}" method="POST"> <div class="text-end">
@if ($member['is_locked'] == 1)
<form action="{{ route('locked-accounts.activate', $member['id']) }}" method="POST" class="d-inline">
@csrf @csrf
<button type="submit" class="btn btn-success" onclick="return confirm('Are you sure you want to activate this account?')">Activate Account</button> @method('POST')
<button type="submit" class="btn btn-success btn-sm me-2" onclick="return confirm('Are you sure you want to activate this account?')">
<i class="fa-solid fa-unlock me-1"></i> Activate Account
</button>
</form> </form>
@endif
<a href="{{ route('locked-accounts') }}" class="btn btn-primary btn-sm">
Back to Locked Accounts
</a>
</div>
@else
<p>No account data available.</p>
@endif
</div> </div>
</div> </div>
</div> </div>
</div>
@endsection @endsection

View File

@ -33,7 +33,7 @@
'showCheckboxes' => false, 'showCheckboxes' => false,
'showBatchDelete' => false, 'showBatchDelete' => false,
'showEditModal' => false, 'showEditModal' => false,
'showViewModal' => true, 'showViewModal' => false,
'currentPage' => $currentPage ?? 1, 'currentPage' => $currentPage ?? 1,
'lastPage' => $lastPage ?? 1, 'lastPage' => $lastPage ?? 1,
'total' => $total ?? 0, 'total' => $total ?? 0,