ajoute le portail Laravel : connexion prof/élève, session unique, gestion de classe, salle d'attente
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
aa31b6112f
commit
30e14b1c54
191 changed files with 25324 additions and 0 deletions
43
portail/app/Services/GenerateurCompteEleve.php
Normal file
43
portail/app/Services/GenerateurCompteEleve.php
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Eleve;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Génère les identifiants (prénom.initiale, avec un numéro pour les
|
||||
* homonymes) et les codes secrets des élèves (étape 8 du déploiement).
|
||||
*/
|
||||
class GenerateurCompteEleve
|
||||
{
|
||||
// Sans 0/O ni 1/I/L, pour qu'un élève ne confonde pas à la lecture.
|
||||
private const ALPHABET_CODE = 'ABCDEFGHJKMNPQRSTUVWXYZ23456789';
|
||||
|
||||
public function genererIdentifiant(string $prenom, ?string $nom): string
|
||||
{
|
||||
$base = Str::slug($prenom, '');
|
||||
if ($nom !== null && $nom !== '') {
|
||||
$base .= '.'.Str::slug(mb_substr($nom, 0, 1));
|
||||
}
|
||||
|
||||
$identifiant = $base;
|
||||
$suffixe = 2;
|
||||
while (Eleve::where('identifiant', $identifiant)->exists()) {
|
||||
$identifiant = $base.$suffixe;
|
||||
$suffixe++;
|
||||
}
|
||||
|
||||
return $identifiant;
|
||||
}
|
||||
|
||||
public function genererCodeSecret(): string
|
||||
{
|
||||
$code = '';
|
||||
for ($i = 0; $i < 6; $i++) {
|
||||
$code .= self::ALPHABET_CODE[random_int(0, strlen(self::ALPHABET_CODE) - 1)];
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue