backend url connected, fetching data not working
This commit is contained in:
parent
e9ad6add4b
commit
bcce93175b
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Livewire;
|
||||
|
||||
use console;
|
||||
use Livewire\Component;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
@ -9,7 +10,7 @@ use Illuminate\Support\Facades\Session;
|
|||
class LoginForm extends Component
|
||||
{
|
||||
public $username, $password;
|
||||
|
||||
|
||||
public function submit()
|
||||
{
|
||||
$this->validate([
|
||||
|
@ -18,34 +19,29 @@ class LoginForm extends Component
|
|||
]);
|
||||
|
||||
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,
|
||||
'password' => $this->password,
|
||||
]);
|
||||
|
||||
|
||||
$json = $response->json();
|
||||
|
||||
if ($response->successful()) {
|
||||
$json = $response->json();
|
||||
|
||||
if ($json['code'] === 200) {
|
||||
// Store UUID in session if needed
|
||||
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
|
||||
Session::put('user', $json['data']['user'] ?? null);
|
||||
|
||||
return redirect('/main/profile');
|
||||
} else {
|
||||
$this->addError('username', $json['message'] ?? 'Login failed.');
|
||||
}
|
||||
} 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) {
|
||||
$this->addError('username', 'An error occurred: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function render()
|
||||
|
@ -53,4 +49,59 @@ class LoginForm extends Component
|
|||
return view('livewire.auth.login-form'); // This will point to the resource/views/livewire/auth/login-form.blade.php 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,11 +3,24 @@
|
|||
namespace App\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
use Livewire\Attributes\On;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
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()
|
||||
{
|
||||
return view('livewire.profile.profile');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -34,5 +34,9 @@ return [
|
|||
'channel' => env('SLACK_BOT_USER_DEFAULT_CHANNEL'),
|
||||
],
|
||||
],
|
||||
|
||||
'backend_api' => [
|
||||
'url' => env('BACKEND_API_URL'),
|
||||
],
|
||||
|
||||
];
|
||||
|
|
|
@ -64,5 +64,4 @@ volumes:
|
|||
|
||||
networks:
|
||||
app_network:
|
||||
driver: bridge
|
||||
external: true
|
||||
driver: bridge
|
|
@ -1,25 +1,34 @@
|
|||
<!-- profile/profile.blade.php -->
|
||||
<div>
|
||||
{{-- Top Nav --}}
|
||||
@include('livewire.profile.top-nav.profile')
|
||||
|
||||
<div class="mt-10">
|
||||
<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"/>
|
||||
<h3 class="text-2xl font-semibold text-gray-800">LBTek Systems</h3>
|
||||
<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"/>
|
||||
<h3 class="text-2xl font-semibold text-gray-800">
|
||||
{{ $user['firstname'] }} {{ $user['lastname'] }}
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
<div class="text-md px-10 p-10 bg-white">
|
||||
<div>
|
||||
<h4 class="font-bold mb-5">My Information</h4>
|
||||
<p><span class="font-semibold">Username:</span> {{ $user['username'] ?? '-' }}</p>
|
||||
<p>
|
||||
<span class="font-semibold">Email:</span>
|
||||
<a href="mailto:{{ $user['email'] }}" class="text-blue-600 hover:underline">
|
||||
{{ $user['email'] }}
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="text-md px-10 p-10 bg-white">
|
||||
<div>
|
||||
<h4 class="font-bold mb-5">My Information</h4>
|
||||
<p><span class="font-semibold">Username:</span> lbteksupport</p>
|
||||
<p><span class="font-semibold">Email:</span> <a href="mailto:support@lbteksystems.com"
|
||||
class="text-blue-600 hover:underline">support@lbteksystems.com</a></p>
|
||||
</div>
|
||||
<div>
|
||||
<h4 class="font-bold mt-10 mb-5">Access Role</h4>
|
||||
<p><span class="font-semibold">Role:</span> System Admin</p>
|
||||
</div>
|
||||
<div>
|
||||
<h4 class="font-bold mt-10 mb-5">Access Role</h4>
|
||||
<p>
|
||||
<span class="font-semibold">Role:</span>
|
||||
{{ $user['role'] === 1 ? 'System Admin' : 'User' }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue