backend api url added

This commit is contained in:
erishBRBS 2025-05-02 09:51:41 +08:00
parent 47f35887bd
commit e9ad6add4b
3 changed files with 45 additions and 12 deletions

View File

@ -3,23 +3,54 @@
namespace App\Livewire;
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(env('BACKEND_API_URL') . '/api/login_password', [
'username' => $this->username,
'password' => $this->password,
]);
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
return redirect('/main/profile');
} else {
$this->addError('username', $json['message'] ?? 'Login failed.');
}
} else {
$this->addError('username', 'Login request failed. Please try again.');
}
} 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
}
public function submit()
{
// Logic for login
}
public function forgotUsername()
{
// Logic for forgot username
}
}

View File

@ -64,4 +64,5 @@ volumes:
networks:
app_network:
driver: bridge
driver: bridge
external: true

View File

@ -25,8 +25,9 @@
<a href="#" class="text-blue-600 hover:underline" wire:click.prevent="forgotUsername">Forgot Username</a>
</div>
<!-- <button type="submit" class="w-full bg-orange-600 font-bold hover:bg-orange-400 text-white py-2 rounded-md">Log in</button> commented as of now for fast navigation-->
<a href="/main/profile" class="block text-center w-full bg-orange-600 font-bold hover:bg-orange-400 text-white py-2 rounded-md">Log in</a>
<button type="submit" class="w-full bg-orange-600 font-bold hover:bg-orange-400 text-white py-2 rounded-md">Log in</button>
<!-- <a href="/main/profile" class="block text-center w-full bg-orange-600 font-bold hover:bg-orange-400 text-white py-2 rounded-md">Log in</a> -->
</form>
</div>