backend url connected, fetching data not working
This commit is contained in:
parent
e9ad6add4b
commit
bcce93175b
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Livewire;
|
namespace App\Livewire;
|
||||||
|
|
||||||
|
use console;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\Facades\Session;
|
use Illuminate\Support\Facades\Session;
|
||||||
|
@ -18,34 +19,29 @@ class LoginForm extends Component
|
||||||
]);
|
]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = Http::post(env('BACKEND_API_URL') . '/api/login_password', [
|
$response = Http::post(config('services.backend_api.url') . '/api/cms/login_password', [
|
||||||
'username' => $this->username,
|
'username' => $this->username,
|
||||||
'password' => $this->password,
|
'password' => $this->password,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($response->successful()) {
|
|
||||||
$json = $response->json();
|
$json = $response->json();
|
||||||
|
|
||||||
|
if ($response->successful()) {
|
||||||
if ($json['code'] === 200) {
|
if ($json['code'] === 200) {
|
||||||
// Store UUID in session if needed
|
Session::put('user', $json['data']['user'] ?? null);
|
||||||
Session::put('admin_uuid', $json['data']['admin_uuid'] ?? null);
|
|
||||||
|
|
||||||
// Redirect if user must change password
|
|
||||||
if (!empty($json['data']['prompt_password'])) {
|
|
||||||
return redirect('/api/login_changePassword');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Redirect to profile after successful login
|
|
||||||
return redirect('/main/profile');
|
return redirect('/main/profile');
|
||||||
} else {
|
} else {
|
||||||
$this->addError('username', $json['message'] ?? 'Login failed.');
|
$this->addError('username', $json['message'] ?? 'Login failed.');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->addError('username', 'Login request failed. Please try again.');
|
$message = $json['message'] ?? 'Login request failed. Please try again.';
|
||||||
|
$this->addError('username', $message);
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->addError('username', 'An error occurred: ' . $e->getMessage());
|
$this->addError('username', 'An error occurred: ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
|
@ -54,3 +50,58 @@ class LoginForm extends Component
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// <?php
|
||||||
|
|
||||||
|
// namespace App\Livewire;
|
||||||
|
|
||||||
|
// use console;
|
||||||
|
// use Livewire\Component;
|
||||||
|
// use Illuminate\Support\Facades\Http;
|
||||||
|
// use Illuminate\Support\Facades\Session;
|
||||||
|
|
||||||
|
// class LoginForm extends Component
|
||||||
|
// {
|
||||||
|
// public $username, $password;
|
||||||
|
|
||||||
|
// public function submit()
|
||||||
|
// {
|
||||||
|
// $this->validate([
|
||||||
|
// 'username' => 'required|string',
|
||||||
|
// 'password' => 'required|string',
|
||||||
|
// ]);
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// $response = Http::post(config('services.backend_api.url') . '/api/cms/login_password', [
|
||||||
|
// 'username' => $this->username,
|
||||||
|
// 'password' => $this->password,
|
||||||
|
// ]);
|
||||||
|
|
||||||
|
// $json = $response->json();
|
||||||
|
|
||||||
|
// if ($response->successful()) {
|
||||||
|
// if ($json['code'] === 200) {
|
||||||
|
// Session::put('admin_uuid', $json['data']['admin_uuid'] ?? null);
|
||||||
|
|
||||||
|
// return redirect('/main/profile');
|
||||||
|
// } else {
|
||||||
|
// $this->addError('username', $json['message'] ?? 'Login failed.');
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// $message = $json['message'] ?? 'Login request failed. Please try again.';
|
||||||
|
// $this->addError('username', $message);
|
||||||
|
// }
|
||||||
|
// } catch (\Exception $e) {
|
||||||
|
// $this->addError('username', 'An error occurred: ' . $e->getMessage());
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public function render()
|
||||||
|
// {
|
||||||
|
// return view('livewire.auth.login-form'); // This will point to the resource/views/livewire/auth/login-form.blade.php component
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
|
@ -3,9 +3,22 @@
|
||||||
namespace App\Livewire;
|
namespace App\Livewire;
|
||||||
|
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
use Livewire\Attributes\On;
|
||||||
|
use Illuminate\Support\Facades\Session;
|
||||||
|
|
||||||
class Profile extends Component
|
class Profile extends Component
|
||||||
{
|
{
|
||||||
|
public $user;
|
||||||
|
|
||||||
|
public function mount()
|
||||||
|
{
|
||||||
|
$this->user = Session::get('user');
|
||||||
|
|
||||||
|
if (!$this->user) {
|
||||||
|
return $this->redirect('/login'); // Livewire 3 way
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
return view('livewire.profile.profile');
|
return view('livewire.profile.profile');
|
||||||
|
|
|
@ -35,4 +35,8 @@ return [
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'backend_api' => [
|
||||||
|
'url' => env('BACKEND_API_URL'),
|
||||||
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
|
@ -65,4 +65,3 @@ volumes:
|
||||||
networks:
|
networks:
|
||||||
app_network:
|
app_network:
|
||||||
driver: bridge
|
driver: bridge
|
||||||
external: true
|
|
|
@ -1,4 +1,3 @@
|
||||||
<!-- profile/profile.blade.php -->
|
|
||||||
<div>
|
<div>
|
||||||
{{-- Top Nav --}}
|
{{-- Top Nav --}}
|
||||||
@include('livewire.profile.top-nav.profile')
|
@include('livewire.profile.top-nav.profile')
|
||||||
|
@ -6,19 +5,29 @@
|
||||||
<div class="mt-10">
|
<div class="mt-10">
|
||||||
<div class="flex items-center space-x-4 px-5 py-4 bg-gray-300">
|
<div class="flex items-center space-x-4 px-5 py-4 bg-gray-300">
|
||||||
<x-heroicon-s-user-circle class="w-20 h-20 mr-2 text-gray-500"/>
|
<x-heroicon-s-user-circle class="w-20 h-20 mr-2 text-gray-500"/>
|
||||||
<h3 class="text-2xl font-semibold text-gray-800">LBTek Systems</h3>
|
<h3 class="text-2xl font-semibold text-gray-800">
|
||||||
|
{{ $user['firstname'] }} {{ $user['lastname'] }}
|
||||||
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="text-md px-10 p-10 bg-white">
|
<div class="text-md px-10 p-10 bg-white">
|
||||||
<div>
|
<div>
|
||||||
<h4 class="font-bold mb-5">My Information</h4>
|
<h4 class="font-bold mb-5">My Information</h4>
|
||||||
<p><span class="font-semibold">Username:</span> lbteksupport</p>
|
<p><span class="font-semibold">Username:</span> {{ $user['username'] ?? '-' }}</p>
|
||||||
<p><span class="font-semibold">Email:</span> <a href="mailto:support@lbteksystems.com"
|
<p>
|
||||||
class="text-blue-600 hover:underline">support@lbteksystems.com</a></p>
|
<span class="font-semibold">Email:</span>
|
||||||
|
<a href="mailto:{{ $user['email'] }}" class="text-blue-600 hover:underline">
|
||||||
|
{{ $user['email'] }}
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<h4 class="font-bold mt-10 mb-5">Access Role</h4>
|
<h4 class="font-bold mt-10 mb-5">Access Role</h4>
|
||||||
<p><span class="font-semibold">Role:</span> System Admin</p>
|
<p>
|
||||||
|
<span class="font-semibold">Role:</span>
|
||||||
|
{{ $user['role'] === 1 ? 'System Admin' : 'User' }}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue