- Add complete Auth module with login, logout, lock screen functionality - Fix 401 error on error monitoring page by adding /error-monitoring/ to public patterns - Improve lock screen with proper form handling and unlock functionality - Add RoleModel and role management views - Add BaseModel for common model functionality - Update authentication system and middleware - Add troubleshooting documentation - Update assets and build tools
171 lines
7.2 KiB
PHP
171 lines
7.2 KiB
PHP
<?php
|
|
use App\Core\InputSanitizer;
|
|
?>
|
|
|
|
<div class="auth-page-wrapper pt-5">
|
|
<!-- auth page bg -->
|
|
<div class="auth-one-bg-position auth-one-bg" id="auth-particles">
|
|
<div class="bg-overlay"></div>
|
|
</div>
|
|
|
|
<!-- auth page content -->
|
|
<div class="auth-page-content">
|
|
<div class="container">
|
|
<div class="row">
|
|
<div class="col-lg-12">
|
|
<div class="text-center mt-sm-5 mb-4 text-white-50">
|
|
<div>
|
|
<a href="/" class="d-inline-block auth-logo">
|
|
<img src="<?php echo \App\Core\AppConfig::getLogoLight(); ?>" alt="<?php echo \App\Core\AppConfig::getCompanyName(); ?>" height="40">
|
|
</a>
|
|
</div>
|
|
<p class="mt-3 fs-15 fw-medium"><?php echo \App\Core\AppConfig::getCompanyName(); ?></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!-- end row -->
|
|
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-8 col-lg-6 col-xl-5">
|
|
<div class="card mt-4">
|
|
<div class="card-body p-4">
|
|
<div class="text-center mt-2">
|
|
<h5 class="text-primary">Welcome Back!</h5>
|
|
<p class="text-muted">Sign in to continue to <?php echo \App\Core\AppConfig::getCompanyName(); ?>.</p>
|
|
</div>
|
|
|
|
<?php if (null !== InputSanitizer::get('error', 'GET')): ?>
|
|
<div class="alert alert-danger mt-3" role="alert">
|
|
Invalid email or password.
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="p-2 mt-4">
|
|
<div id="login-error" class="alert alert-danger d-none" role="alert"></div>
|
|
|
|
<form id="login-form" action="/login" method="POST">
|
|
<div class="mb-3">
|
|
<label for="email" class="form-label">Email</label>
|
|
<input type="email" class="form-control" id="email" name="email" placeholder="Enter email" required>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<div class="float-end">
|
|
<a href="#" class="text-muted">Forgot password?</a>
|
|
</div>
|
|
<label class="form-label" for="password-input">Password</label>
|
|
<div class="position-relative auth-pass-inputgroup mb-3">
|
|
<input type="password" class="form-control pe-5 password-input" placeholder="Enter password" id="password-input" name="password" required>
|
|
<button class="btn btn-link position-absolute end-0 top-0 text-decoration-none text-muted password-addon" type="button" id="password-addon"><i class="ri-eye-fill align-middle"></i></button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" value="1" id="auth-remember-check" name="remember_me">
|
|
<label class="form-check-label" for="auth-remember-check">Remember me</label>
|
|
</div>
|
|
|
|
<div class="mt-4">
|
|
<button class="btn btn-success w-100" type="submit" id="login-btn">Sign In</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<!-- end card body -->
|
|
</div>
|
|
<!-- end card -->
|
|
|
|
</div>
|
|
</div>
|
|
<!-- end row -->
|
|
</div>
|
|
<!-- end container -->
|
|
</div>
|
|
<!-- end auth page content -->
|
|
|
|
<!-- footer -->
|
|
<footer class="footer">
|
|
<div class="container">
|
|
<div class="row">
|
|
<div class="col-lg-12">
|
|
<div class="text-center">
|
|
<p class="mb-0 text-muted">©
|
|
<script>document.write(new Date().getFullYear())</script> <?php echo \App\Core\AppConfig::getCompanyName(); ?>.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</footer>
|
|
<!-- end Footer -->
|
|
</div>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const form = document.getElementById('login-form');
|
|
const errorDiv = document.getElementById('login-error');
|
|
const submitBtn = document.getElementById('login-btn');
|
|
|
|
form.addEventListener('submit', async function(e) {
|
|
e.preventDefault();
|
|
|
|
// Disable button and show loading state
|
|
submitBtn.disabled = true;
|
|
submitBtn.innerHTML = '<span class="spinner-border spinner-border-sm me-2" role="status" aria-hidden="true"></span>Signing in...';
|
|
|
|
// Hide previous errors
|
|
errorDiv.classList.add('d-none');
|
|
|
|
// Get form data
|
|
const formData = new FormData(form);
|
|
|
|
try {
|
|
const response = await fetch('/login', {
|
|
method: 'POST',
|
|
body: formData
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (response.ok && data.success) {
|
|
// Redirect to dashboard on success
|
|
window.location.href = '/';
|
|
} else {
|
|
// Show error message
|
|
errorDiv.textContent = data.message || 'Invalid credentials';
|
|
errorDiv.classList.remove('d-none');
|
|
|
|
// Re-enable button
|
|
submitBtn.disabled = false;
|
|
submitBtn.innerHTML = 'Sign In';
|
|
}
|
|
} catch (error) {
|
|
console.error('Login error:', error);
|
|
errorDiv.textContent = 'An error occurred. Please try again.';
|
|
errorDiv.classList.remove('d-none');
|
|
|
|
// Re-enable button
|
|
submitBtn.disabled = false;
|
|
submitBtn.innerHTML = 'Sign In';
|
|
}
|
|
});
|
|
|
|
// Password visibility toggle
|
|
const passwordAddon = document.getElementById('password-addon');
|
|
const passwordInput = document.getElementById('password-input');
|
|
|
|
if (passwordAddon && passwordInput) {
|
|
passwordAddon.addEventListener('click', function() {
|
|
const type = passwordInput.type === 'password' ? 'text' : 'password';
|
|
passwordInput.type = type;
|
|
|
|
const icon = this.querySelector('i');
|
|
if (icon) {
|
|
icon.classList.toggle('ri-eye-fill');
|
|
icon.classList.toggle('ri-eye-off-fill');
|
|
}
|
|
});
|
|
}
|
|
});
|
|
</script>
|