latest commit
This commit is contained in:
parent
d025e2c3ea
commit
557570d9cb
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
@extends('layouts.login')
|
@extends('layouts.login')
|
||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
|
@ -13,9 +12,19 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Error/Success Messages -->
|
<!-- Error/Success Messages -->
|
||||||
<div id="alert" class="alert d-none" role="alert"></div>
|
@if (session('success'))
|
||||||
|
<div class="alert alert-success" role="alert">
|
||||||
|
{{ session('success') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
@if (session('error'))
|
||||||
|
<div class="alert alert-danger" role="alert">
|
||||||
|
{{ session('error') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
<form id="loginForm">
|
<form method="POST" action="{{ url('/login') }}">
|
||||||
|
@csrf
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label fw-semibold" style="font-size: 13px; color: #003366;">Enter Username</label>
|
<label class="form-label fw-semibold" style="font-size: 13px; color: #003366;">Enter Username</label>
|
||||||
<input type="text" class="form-control" id="username" name="username" placeholder="Username" required>
|
<input type="text" class="form-control" id="username" name="username" placeholder="Username" required>
|
||||||
|
@ -58,56 +67,4 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@endsection
|
||||||
<!-- Axios CDN -->
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
document.getElementById('loginForm').addEventListener('submit', async function (e) {
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
const username = document.getElementById('username').value.trim();
|
|
||||||
const password = document.getElementById('password').value.trim();
|
|
||||||
const alertBox = document.getElementById('alert');
|
|
||||||
|
|
||||||
// Use environment variable for the API base URL
|
|
||||||
const apiBaseUrl = '{{ env('API_URL', 'http://192.168.56.1:8080') }}/api';
|
|
||||||
|
|
||||||
// Reset alert box
|
|
||||||
alertBox.classList.add('d-none');
|
|
||||||
alertBox.classList.remove('alert-success', 'alert-danger');
|
|
||||||
alertBox.textContent = '';
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
|
|
||||||
// Validate password
|
|
||||||
const passwordResponse = await axios.post(`${apiBaseUrl}/cms/login_password`, { username, password });
|
|
||||||
if (!passwordResponse.data.success) {
|
|
||||||
throw new Error(passwordResponse.data.message || 'Invalid password');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Success
|
|
||||||
alertBox.classList.remove('d-none', 'alert-danger');
|
|
||||||
alertBox.classList.add('alert-success');
|
|
||||||
alertBox.textContent = 'Login successful! Redirecting...';
|
|
||||||
|
|
||||||
// Store token
|
|
||||||
if (passwordResponse.data.token) {
|
|
||||||
localStorage.setItem('authToken', passwordResponse.data.token);
|
|
||||||
}
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
window.location.href = '{{ url("/my-profile") }}';
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
// Log detailed error to console for debugging
|
|
||||||
console.error('Login error:', error, error.response);
|
|
||||||
alertBox.classList.remove('d-none', 'alert-success');
|
|
||||||
alertBox.classList.add('alert-danger');
|
|
||||||
alertBox.textContent = error.response?.data?.message || error.message || 'Login failed. Please try again.';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
@endsection
|
|
|
@ -5,11 +5,11 @@ use Illuminate\Support\Facades\Http;
|
||||||
use App\Http\Controllers\AuthController;
|
use App\Http\Controllers\AuthController;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Route::get('/', function () {
|
Route::get('/', function () {
|
||||||
return view('login');
|
return view('login');
|
||||||
})->name('login');
|
})->name('login');
|
||||||
|
Route::post('/login', [AuthController::class, 'login'])->name('login');
|
||||||
|
|
||||||
|
|
||||||
Route::get('/dashboard', function () {
|
Route::get('/dashboard', function () {
|
||||||
return view('dashboard');
|
return view('dashboard');
|
||||||
|
|
Loading…
Reference in New Issue