backend api url added
This commit is contained in:
parent
47f35887bd
commit
e9ad6add4b
|
@ -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
|
||||
}
|
||||
}
|
|
@ -64,4 +64,5 @@ volumes:
|
|||
|
||||
networks:
|
||||
app_network:
|
||||
driver: bridge
|
||||
driver: bridge
|
||||
external: true
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue