servnest/pg-act/auth/approval.php

19 lines
686 B
PHP

<?php
if ($_SESSION['type'] !== 'testing')
output(403, 'Approbation impossible : votre compte est déjà approuvé.');
if (isset(query('select', 'approval-keys', ['key' => $_POST['key']], 'key')[0]) !== true)
output(403, 'Approbation impossible : cette clé d\'approbation n\'est pas disponible. Elle a été mal saisie, a expiré ou a déjà été utilisée pour un autre compte.');
query('delete', 'approval-keys', ['key' => $_POST['key']]);
DB->prepare('UPDATE users SET type = "approved" WHERE id = :id')
->execute([':id' => $_SESSION['id']]);
$_SESSION['type'] = 'approved';
insert('approval-keys', ['key' => bin2hex(random_bytes(16))]);
output(200, 'Compte approuvé.');