- Add db.php with PDO singleton, migration runner, and all helper functions - Add migrations/001_initial_schema.sql (full schema) - Add migrations/002_import_json.php (one-time JSON → DB importer) - Add _incl/switch_tenant.php POST endpoint for tenant/centro switching - Update tools.auth.php: DB-backed login, cookie auth, session reload, init_active_centro() - Update all sysadmin pages (users, centros, aularios, invitations, reset_password) to use DB - Update aulatek/index.php, aulario.php, supercafe.php, supercafe_edit.php to use DB - Update aulatek/comedor.php and api/comedor.php to use DB - Update aulatek/paneldiario.php: aulario config + comedor data from DB - Update aulatek/proyectos.php: aulario config + sharing metadata from DB - Update club/cal.php, index.php, edit_data.php, upload/upload.php to use DB - Update account/index.php: rich profile, tenant list, aula list, session info, permissions - Update pre-body.php account dropdown: shows active org + inline tenant switcher - Update DATA_STRUCTURE.md to document DB approach and migration system Co-authored-by: naielv <109038805+naielv@users.noreply.github.com>
62 lines
3.0 KiB
PHP
62 lines
3.0 KiB
PHP
<?php
|
|
require_once "_incl/pre-body.php";
|
|
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|
$invi_code = strtoupper(trim($_POST['invitation_code'] ?? ''));
|
|
$invitation = db_get_invitation($invi_code);
|
|
if (!$invitation || !$invitation['active']) {
|
|
header("Location: /?_resultcolor=red&_result=" . urlencode("Código de invitación no válido."));
|
|
exit;
|
|
}
|
|
$username = strtolower(trim($_POST['username'] ?? ''));
|
|
if (db_get_user($username)) {
|
|
header("Location: /?_resultcolor=red&_result=" . urlencode("El nombre de usuario ya existe. Por favor, elige otro."));
|
|
exit;
|
|
}
|
|
db_upsert_user([
|
|
'username' => $username,
|
|
'display_name' => $_POST['display_name'] ?? '',
|
|
'email' => $_POST['email'] ?? '',
|
|
'password_hash' => password_hash($_POST['password'], PASSWORD_DEFAULT),
|
|
'permissions' => [],
|
|
'_meta_signup' => ['invitation_code' => $invi_code],
|
|
]);
|
|
if ($invitation['single_use']) {
|
|
db_deactivate_invitation($invi_code);
|
|
}
|
|
header("Location: /?_result=" . urlencode("Cuenta creada correctamente. Ya puedes iniciar sesión."));
|
|
exit;
|
|
}
|
|
?>
|
|
<div class="card pad">
|
|
<div>
|
|
<h1 class="card-title">¡Crea una cuenta!</h1>
|
|
<form method="post">
|
|
<div class="card pad" style="max-width: 500px;">
|
|
<div>
|
|
<div class="mb-3">
|
|
<label for="invitation_code" class="form-label"><b>Codigo de invitación:</b></label>
|
|
<input type="text" id="invitation_code" name="invitation_code" class="form-control" required />
|
|
<small>Codigo de invitación proporcionado por un administrador.<br>Formato: 123456-ABCDEF</small>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="username" class="form-label"><b>Usuario:</b></label>
|
|
<input type="text" id="username" name="username" class="form-control" required />
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="password" class="form-label"><b>Contraseña:</b></label>
|
|
<input type="password" id="password" name="password" class="form-control" required />
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="display_name" class="form-label"><b>Nombre:</b></label>
|
|
<input type="text" id="display_name" name="display_name" class="form-control" required />
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="email" class="form-label"><b>Correo electronico:</b></label>
|
|
<input type="email" id="email" name="email" class="form-control" required />
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Crear cuenta</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|