locked-account page functionality works
This commit is contained in:
parent
2d920f245a
commit
aa46ddde7f
|
@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
|
@ -3,45 +3,81 @@
|
||||||
@section('page_title', 'View Locked Account')
|
@section('page_title', 'View Locked Account')
|
||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<div class="card">
|
<div class="container-fluid py-4">
|
||||||
<div class="card-header">
|
<div class="row justify-content-center">
|
||||||
<h5 class="mb-0 fw-bold text-dark">View Locked Account</h5>
|
<div class="card">
|
||||||
</div>
|
<div class="card-header border-0 bg-transparent">
|
||||||
<div class="card-body">
|
<h5 class="mb-0">View Locked Account</h5>
|
||||||
@if (session('error'))
|
|
||||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
|
||||||
{{ session('error') }}
|
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
||||||
</div>
|
|
||||||
@endif
|
|
||||||
<div class="mb-3">
|
|
||||||
<strong>Card Number:</strong> {{ $member['cardNumber'] }}
|
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="card-body">
|
||||||
<strong>First Name:</strong> {{ $member['firstName'] }}
|
@if (session('success'))
|
||||||
</div>
|
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||||
<div class="mb-3">
|
{{ session('success') }}
|
||||||
<strong>Last Name:</strong> {{ $member['lastName'] }}
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
@endif
|
||||||
<strong>Birthday:</strong> {{ $member['birthday'] ? date('F d, Y', strtotime($member['birthday'])) : 'N/A' }}
|
@if (session('error'))
|
||||||
</div>
|
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||||
<div class="mb-3">
|
{{ session('error') }}
|
||||||
<strong>Card Type:</strong> {{ $member['cardType'] }}
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
@endif
|
||||||
<strong>Status:</strong> {{ $member['status'] }}
|
|
||||||
</div>
|
@if (isset($member))
|
||||||
<div class="mb-3">
|
<div class="row">
|
||||||
<strong>Lock Status:</strong> {{ $member['is_locked'] == 1 ? 'Locked' : 'Unlocked' }}
|
<div class="col-md-6">
|
||||||
</div>
|
<div class="mb-3">
|
||||||
<div class="d-flex gap-2">
|
<label class="form-label">Card Number</label>
|
||||||
<a href="{{ route('locked-account') }}" class="btn btn-secondary">Back</a>
|
<input type="text" class="form-control" value="{{ $member['cardNumber'] ?? 'N/A' }}" readonly>
|
||||||
<form action="{{ route('locked-account.activate', $member['id']) }}" method="POST">
|
</div>
|
||||||
@csrf
|
<div class="mb-3">
|
||||||
<button type="submit" class="btn btn-success" onclick="return confirm('Are you sure you want to activate this account?')">Activate Account</button>
|
<label class="form-label">First Name</label>
|
||||||
</form>
|
<input type="text" class="form-control" value="{{ $member['firstName'] ?? 'N/A' }}" readonly>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<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 class="mb-3">
|
||||||
|
<label class="form-label">Card Type</label>
|
||||||
|
<input type="text" class="form-control" value="{{ $member['cardType'] ?? 'N/A' }}" readonly>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Status</label>
|
||||||
|
<input type="text" class="form-control" value="{{ $member['status'] ?? 'N/A' }}" readonly>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Lock Status</label>
|
||||||
|
<input type="text" class="form-control" value="{{ $member['is_locked'] == 1 ? 'Locked' : 'Unlocked' }}" readonly>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="text-end">
|
||||||
|
@if ($member['is_locked'] == 1)
|
||||||
|
<form action="{{ route('locked-accounts.activate', $member['id']) }}" method="POST" class="d-inline">
|
||||||
|
@csrf
|
||||||
|
@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>
|
||||||
|
@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
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue