Files
MoneyFlix/crm/Modules/Auth/Views/signup/basic.php
T
1sonhador 97eca96f83 MoneyFlix: Add Auth module, fix error monitoring, improve lock screen functionality
- 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
2025-10-22 18:09:43 +01:00

355 lines
17 KiB
PHP

<?php
use App\Core\View;
// Definir variáveis para o layout
$page_title = 'Auth signup basic';
$page_description = 'Página Auth signup basic';
// Incluir o layout principal
View::render('layouts/auth.php', [
'title' => $page_title,
'description' => $page_description,
'page_content' => function() {
?>
<?php
// Check if user is logged in
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
if (isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true) {
header("location: /");
exit;
}
?>
<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 class="shape">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 1440 120">
<path d="M 0,36 C 144,53.6 432,123.2 720,124 C 1008,124.8 1296,56.8 1440,40L1440 140L0 140z"></path>
</svg>
</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="" height="20">
</a>
</div>
<p class="mt-3 fs-15 fw-medium">BitReport CRM - Sistema de Gestão Empresarial</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">Create New Account</h5>
<p class="text-muted">Register a new user account</p>
</div>
<div class="p-2 mt-4">
<form id="registerForm" class="needs-validation" novalidate>
<div class="mb-3">
<label for="first_name" class="form-label">First Name <span class="text-danger">*</span></label>
<input type="text" class="form-control" name="first_name" id="first_name" placeholder="Enter first name" required>
<div class="invalid-feedback" id="first_name-error"></div>
</div>
<div class="mb-3">
<label for="last_name" class="form-label">Last Name <span class="text-danger">*</span></label>
<input type="text" class="form-control" name="last_name" id="last_name" placeholder="Enter last name" required>
<div class="invalid-feedback" id="last_name-error"></div>
</div>
<div class="mb-3">
<label for="useremail" class="form-label">Email <span class="text-danger">*</span></label>
<input type="email" class="form-control" name="email" id="useremail" placeholder="Enter email address" required>
<div class="invalid-feedback" id="email-error"></div>
</div>
<div class="mb-3">
<label for="username" class="form-label">Username <span class="text-danger">*</span></label>
<input type="text" class="form-control" name="username" id="username" placeholder="Enter username" required>
<div class="invalid-feedback" id="username-error"></div>
</div>
<div class="mb-3">
<label for="role" class="form-label">Role <span class="text-danger">*</span></label>
<select class="form-select" name="role" id="role" required>
<option value="">Select role</option>
<option value="user">User</option>
<option value="admin">Admin</option>
<option value="manager">Manager</option>
</select>
<div class="invalid-feedback" id="role-error"></div>
</div>
<div class="mb-3">
<label class="form-label" for="password-input">Password</label>
<div class="position-relative auth-pass-inputgroup">
<input type="password" class="form-control pe-5 password-input" name="password" onpaste="return false" placeholder="Enter password" id="password-input" aria-describedby="passwordInput" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" 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 class="invalid-feedback" id="password-error"></div>
</div>
</div>
<div class="mb-4">
<p class="mb-0 fs-12 text-muted fst-italic">By registering you agree to the <?php echo \App\Core\AppConfig::getCompanyName(); ?> <a href="#" class="text-primary text-decoration-underline fst-normal fw-medium">Terms of Use</a></p>
</div>
<div id="password-contain" class="p-3 bg-light mb-2 rounded">
<h5 class="fs-13">Password must contain:</h5>
<p id="pass-length" class="invalid fs-12 mb-2">Minimum <b>8 characters</b></p>
<p id="pass-lower" class="invalid fs-12 mb-2">At <b>lowercase</b> letter (a-z)</p>
<p id="pass-upper" class="invalid fs-12 mb-2">At least <b>uppercase</b> letter (A-Z)</p>
<p id="pass-number" class="invalid fs-12 mb-0">A least <b>number</b> (0-9)</p>
</div>
<div class="mt-4">
<button class="btn btn-success w-100" type="submit" id="registerBtn">
<span class="spinner-border spinner-border-sm d-none" role="status" aria-hidden="true"></span>
Create Account
</button>
</div>
</form>
</div>
</div>
<!-- end card body -->
</div>
<!-- end card -->
<div class="mt-4 text-center">
<p class="mb-0">Already have an account ? <a href="/login" class="fw-semibold text-primary text-decoration-underline"> Sign In </a> </p>
</div>
</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">&copy; <script>document.write(new Date().getFullYear())</script> <?php echo \App\Core\AppConfig::getCompanyName(); ?>. Crafted with <i class="mdi mdi-heart text-danger"></i> by Themesdesign</p>
</div>
</div>
</div>
</div>
</footer>
<!-- end Footer -->
</div>
<!-- end auth-page-wrapper -->
<!-- app-scripts.php removido para evitar warning de include inexistente -->
<script>
document.addEventListener('DOMContentLoaded', function() {
const registerForm = document.getElementById('registerForm');
const registerBtn = document.getElementById('registerBtn');
const spinner = registerBtn.querySelector('.spinner-border');
const btnText = registerBtn.querySelector('span:not(.spinner-border)');
// Password visibility toggle
const passwordAddon = document.getElementById('password-addon');
const passwordInput = document.getElementById('password-input');
passwordAddon.addEventListener('click', function() {
const type = passwordInput.getAttribute('type') === 'password' ? 'text' : 'password';
passwordInput.setAttribute('type', type);
this.querySelector('i').classList.toggle('ri-eye-fill');
this.querySelector('i').classList.toggle('ri-eye-off-fill');
});
// Password strength validation
passwordInput.addEventListener('input', function() {
const password = this.value;
const length = document.getElementById('pass-length');
const lower = document.getElementById('pass-lower');
const upper = document.getElementById('pass-upper');
const number = document.getElementById('pass-number');
// Check length
if (password.length >= 8) {
length.classList.remove('invalid');
length.classList.add('valid');
} else {
length.classList.remove('valid');
length.classList.add('invalid');
}
// Check lowercase
if (/[a-z]/.test(password)) {
lower.classList.remove('invalid');
lower.classList.add('valid');
} else {
lower.classList.remove('valid');
lower.classList.add('invalid');
}
// Check uppercase
if (/[A-Z]/.test(password)) {
upper.classList.remove('invalid');
upper.classList.add('valid');
} else {
upper.classList.remove('valid');
upper.classList.add('invalid');
}
// Check number
if (/[0-9]/.test(password)) {
number.classList.remove('invalid');
number.classList.add('valid');
} else {
number.classList.remove('valid');
number.classList.add('invalid');
}
});
// Form submission
registerForm.addEventListener('submit', async function(e) {
e.preventDefault();
// Clear previous errors
clearErrors();
// Get form data
const formData = new FormData(registerForm);
const userData = {
first_name: formData.get('first_name'),
last_name: formData.get('last_name'),
email: formData.get('email'),
username: formData.get('username'),
password: formData.get('password'),
role: formData.get('role')
};
// Validate input
if (!userData.first_name || !userData.last_name || !userData.email || !userData.username || !userData.password || !userData.role) {
showError('general', 'All fields are required');
return;
}
// Validate email format
if (!isValidEmail(userData.email)) {
showError('email', 'Invalid email format');
return;
}
// Validate password strength
if (userData.password.length < 8) {
showError('password', 'Password must be at least 8 characters long');
return;
}
// Show loading state
setLoading(true);
try {
const response = await fetch('/api/auth/register', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(userData)
});
const result = await response.json();
if (result.success) {
// Show success message
Swal.fire({
title: 'Success!',
text: result.message,
icon: 'success',
confirmButtonText: 'Continue',
timer: 2000,
timerProgressBar: true
}).then(() => {
// Reset form
registerForm.reset();
// Redirect to dashboard or user list
window.location.href = '/';
});
} else {
// Show error message
showError('general', result.message);
}
} catch (error) {
console.error('Registration error:', error);
showError('general', 'Network error. Please try again.');
} finally {
setLoading(false);
}
});
function clearErrors() {
document.querySelectorAll('.is-invalid').forEach(el => {
el.classList.remove('is-invalid');
});
document.querySelectorAll('.invalid-feedback').forEach(el => {
el.textContent = '';
});
}
function showError(field, message) {
if (field === 'general') {
// Show general error at top of form
const errorDiv = document.createElement('div');
errorDiv.className = 'alert alert-danger mb-3';
errorDiv.textContent = message;
registerForm.insertBefore(errorDiv, registerForm.firstChild);
// Remove after 5 seconds
setTimeout(() => {
errorDiv.remove();
}, 5000);
} else {
const input = document.getElementById(field === 'email' ? 'useremail' : field);
const errorDiv = document.getElementById(field === 'email' ? 'email-error' : field + '-error');
if (input && errorDiv) {
input.classList.add('is-invalid');
errorDiv.textContent = message;
}
}
}
function setLoading(loading) {
if (loading) {
registerBtn.disabled = true;
spinner.classList.remove('d-none');
btnText.textContent = 'Creating Account...';
} else {
registerBtn.disabled = false;
spinner.classList.add('d-none');
btnText.textContent = 'Create Account';
}
}
function isValidEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
});
</script>
<?php
}
]);
?>