|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione |
| 5 | + * Copyright (C) DevCode s.r.l. |
| 6 | + * |
| 7 | + * This program is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation, either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | + |
| 21 | +include_once __DIR__.'/../../core.php'; |
| 22 | + |
| 23 | +switch (post('op')) { |
| 24 | + case 'update': |
| 25 | + $id_utente = post('id_utente'); |
| 26 | + $descrizione = post('descrizione'); |
| 27 | + $tipo_accesso = post('tipo_accesso'); |
| 28 | + $valido_dal = post('valido_dal') ?: null; |
| 29 | + $valido_al = post('valido_al') ?: null; |
| 30 | + $id_module_target = post('id_module_target') ?: 0; |
| 31 | + $id_record_target = post('id_record_target') ?: 0; |
| 32 | + $permessi = post('permessi') ?: null; |
| 33 | + $email = post('email'); |
| 34 | + |
| 35 | + // Validazione email per token OTP |
| 36 | + if ($tipo_accesso == 'otp' && empty($email)) { |
| 37 | + flash()->error(tr('L\'email è obbligatoria per i token con OTP')); |
| 38 | + break; |
| 39 | + } |
| 40 | + |
| 41 | + if ($tipo_accesso == 'otp' && !filter_var($email, FILTER_VALIDATE_EMAIL)) { |
| 42 | + flash()->error(tr('Inserire un indirizzo email valido')); |
| 43 | + break; |
| 44 | + } |
| 45 | + |
| 46 | + // Aggiornamento record |
| 47 | + $dbo->update('zz_otp_tokens', [ |
| 48 | + 'id_utente' => $id_utente, |
| 49 | + 'descrizione' => $descrizione, |
| 50 | + 'tipo_accesso' => $tipo_accesso, |
| 51 | + 'valido_dal' => $valido_dal, |
| 52 | + 'valido_al' => $valido_al, |
| 53 | + 'id_module_target' => $id_module_target, |
| 54 | + 'id_record_target' => $id_record_target, |
| 55 | + 'permessi' => $permessi, |
| 56 | + 'email' => $email, |
| 57 | + ], ['id' => $id_record]); |
| 58 | + |
| 59 | + flash()->info(tr('Token aggiornato correttamente')); |
| 60 | + break; |
| 61 | + |
| 62 | + case 'add': |
| 63 | + $descrizione = post('descrizione'); |
| 64 | + // Generazione token sicuro |
| 65 | + $token = secure_random_string(32); |
| 66 | + |
| 67 | + // Inserimento nuovo record |
| 68 | + $dbo->insert('zz_otp_tokens', [ |
| 69 | + 'token' => $token, |
| 70 | + 'descrizione' => $descrizione, |
| 71 | + 'enabled' => 0, |
| 72 | + ]); |
| 73 | + |
| 74 | + $id_record = $dbo->lastInsertedID(); |
| 75 | + |
| 76 | + if (isAjaxRequest()) { |
| 77 | + echo json_encode(['id' => $id_record, 'text' => $descrizione]); |
| 78 | + } |
| 79 | + |
| 80 | + flash()->info(tr('Token creato correttamente')); |
| 81 | + break; |
| 82 | + |
| 83 | + case 'delete': |
| 84 | + $dbo->query('DELETE FROM zz_otp_tokens WHERE id='.prepare($id_record)); |
| 85 | + flash()->info(tr('Token eliminato!')); |
| 86 | + break; |
| 87 | + |
| 88 | + case 'enable': |
| 89 | + $dbo->update('zz_otp_tokens', [ |
| 90 | + 'enabled' => 1, |
| 91 | + ], ['id' => $id_record]); |
| 92 | + |
| 93 | + flash()->info(tr('Token abilitato!')); |
| 94 | + break; |
| 95 | + |
| 96 | + case 'disable': |
| 97 | + $dbo->update('zz_otp_tokens', [ |
| 98 | + 'enabled' => 0, |
| 99 | + ], ['id' => $id_record]); |
| 100 | + |
| 101 | + flash()->info(tr('Token disabilitato!')); |
| 102 | + break; |
| 103 | + |
| 104 | + case 'delete': |
| 105 | + $dbo->query('DELETE FROM zz_otp_tokens WHERE id='.prepare($id_record)); |
| 106 | + |
| 107 | + flash()->info(tr('Token eliminato!')); |
| 108 | + break; |
| 109 | +} |
0 commit comments