2
0

cms.user.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <?php
  2. if (core::ifGet("add") and access::ifAccesss("add-user")) {
  3. $id_form = '<input type="hidden" name="id" value="add">';
  4. $submit = "Ajouter un profil";
  5. $titre = "Ajouter un profil";
  6. $protect = 0;
  7. } else {
  8. if (core::ifGet("id") == FALSE or (core::ifGet("id") and session::getId() == core::getGet("id"))) {
  9. $user = user::getUser(session::getId());
  10. $submit = "Modifier votre profil";
  11. $titre = "Votre fiche de profil";
  12. $protect = 1;
  13. if (debug::isFile("debug")) {
  14. debug::log($user, "Données brutes user");
  15. }
  16. } else {
  17. if (access::ifAccesss("add-user")) {
  18. $user = user::getUser(core::getGet("id"));
  19. if (is_array($user)) {
  20. $submit = "Modifier ce profil";
  21. $titre = "Fiche de " . $user["prenom"] . " " . $user["nom"];
  22. if ($user["deleted"] == 1) {
  23. $titre .= " (Supprimée)";
  24. $protect = 2;
  25. } else {
  26. $protect = 0;
  27. }
  28. } else {
  29. get::page("unknow");
  30. exit();
  31. }
  32. } else {
  33. get::page("unknow");
  34. exit();
  35. }
  36. }
  37. $id_form = '<input type="hidden" name="id" value="' . $user["id"] . '">';
  38. }
  39. ?>
  40. <header class="d-flex flex-column flex-md-row align-items-md-center p-3 bg-light row">
  41. <div class="col-11">
  42. <h2 class="bd-title" id="content">
  43. <span><?= $titre ?></span>
  44. </h2>
  45. <?php if (isset($user["id"]) && session::getId() != $user["id"] && $protect != 2): ?>
  46. <div class="fix-container-button-nav">
  47. <a href="/submit.php?from=parametres-user-delete&id=<?= $user['id']; ?>" onclick="return confirm('Voulez-vous supprimer le compte de <?= $user["prenom"] . " " . $user["nom"]; ?> ?')">
  48. <button type="submit" class="btn btn-outline-danger btn-sm"><?= icon::getFont(["icon" => "bi-trash-fill"]); ?> Supprimer</button>
  49. </a>
  50. </div>
  51. <?php elseif ($protect == 2): ?>
  52. <div class="fix-container-button-nav">
  53. <a href="/submit.php?from=parametres-user-restore&id=<?= $user['id']; ?>" onclick="return confirm('Voulez-vous restaurer le compte de <?= $user["prenom"] . " " . $user["nom"]; ?> ?')">
  54. <button type="submit" class="btn btn-outline-danger btn-sm"><?= icon::getFont(["icon" => "bi bi-box2-fill"]); ?> Restaurer</button>
  55. </a>
  56. </div>
  57. <?php endif; ?>
  58. </div>
  59. </header>
  60. <?php
  61. if (core::getGet("id")) {
  62. echo core::filAriane(array(
  63. "current" => $titre,
  64. "arbo" => array(
  65. "Administration" => NULL,
  66. "Utilisateurs" => "/parametres-users.html",
  67. $titre => "#"
  68. )
  69. ));
  70. }
  71. ?>
  72. <?php if (isset($user["last_connect"])): ?>
  73. <?php callout::print([
  74. "type" => "info",
  75. "size" => "tiny",
  76. "style" => "margin:-5px 0;",
  77. "p" => "Dernière connexion le " . core::convertDate($user["last_connect"]),
  78. ]); ?>
  79. <?php endif; ?>
  80. <br />
  81. <?php if ($protect != 2): ?>
  82. <form id="form-user" method="post" action="/submit.php" oninput='password2.setCustomValidity(password2.value != password.value ? "Les mots de passe ne sont pas identiques" : "")' onsubmit="return(false);">
  83. <input type="hidden" name="from" value="user">
  84. <?php
  85. echo $id_form;
  86. endif;
  87. ?>
  88. <div class="form-group">
  89. <label>Type de compte</label>
  90. <?php
  91. $id_type = [
  92. 2 => "Contrôleur QRCode (émargement)",
  93. 3 => "Assistance sociale",
  94. 4 => "Modérateur du CMS",
  95. 5 => "Membre du Bureau du CSE",
  96. 6 => "Elu du CSE",
  97. 7 => "Comptable",
  98. 1 => "Administrateur"
  99. ];
  100. ?>
  101. <?php if ($protect == 0): ?>
  102. <?php
  103. html::printSelect('name="id_type" class="form-select"', $id_type, @$user["id_type"]);
  104. ?>
  105. <?php endif; ?>
  106. <?php if ($protect == 1 or $protect == 2): ?>
  107. <?php
  108. html::printSelect('class="form-control" disabled', $id_type, @$user["id_type"]);
  109. html::printInput('type="hidden" name="id_type"', $user["id_type"]);
  110. ?>
  111. <?php endif; ?>
  112. </div>
  113. <br />
  114. <?php
  115. if (access::ifAccesss("add-user") and core::ifGet("id") and (isset($user["deleted"]) and $user["deleted"] == 0)) { ?>
  116. <div class="form-group">
  117. <label>Rôles aditionnels</label>
  118. <?= html::printInput('type="text" name="tags" id="tags"', @$user["tags"]) ?>
  119. </div>
  120. <br />
  121. <?php
  122. } elseif (isset($user["tags"])) { ?>
  123. <div class="form-group">
  124. <label>Rôles aditionnels</label>
  125. <?= html::printInput('type="text" class="form-control" name="tags" readonly="readonly"', @$user["tags"]) ?>
  126. </div>
  127. <br />
  128. <?php
  129. } else {
  130. html::printInput('type="hidden" name="tags"');
  131. }
  132. ?>
  133. <div class="form-group">
  134. <label>Prénom</label>
  135. <?php
  136. $confPrenom = 'type="text" name="prenom" class="form-control" ';
  137. $confPrenom .= $protect == 2 ? 'readonly="readonly"' : 'required';
  138. html::printInput($confPrenom, @$user["prenom"]);
  139. ?>
  140. </div>
  141. <br />
  142. <div class="form-group">
  143. <label>nom</label>
  144. <?php
  145. $confNom = 'type="text" name="nom" class="form-control" ';
  146. $confNom .= $protect == 2 ? 'readonly="readonly"' : 'required';
  147. html::printInput($confNom, @$user["nom"]);
  148. ?>
  149. </div>
  150. <br />
  151. <div class="form-group">
  152. <label>Email</label>
  153. <?php
  154. $confEmail = 'type="text" name="email" class="form-control" ';
  155. $confEmail .= $protect == 2 ? 'readonly="readonly"' : 'required';
  156. html::printInput($confEmail, @$user["email"]);
  157. ?>
  158. </div>
  159. <br />
  160. <?php if ($protect != 2): ?>
  161. <div class="form-group">
  162. <label>Mot de passe</label>
  163. <?php
  164. $confPassword = 'type="password" class="form-control" minlength="8" maxlength="25" name="password" ';
  165. $confPassword .= core::ifGet("add") ? 'required"' : NULL;
  166. html::printInput($confPassword);
  167. ?>
  168. </div>
  169. <br />
  170. <div class="form-group">
  171. <label>Confirmation du mot de passe</label>
  172. <?php
  173. $confPassword2 = 'type="password" class="form-control" minlength="8" maxlength="25" name="password2" ';
  174. $confPassword2 .= core::ifGet("add") ? 'required"' : NULL;
  175. html::printInput($confPassword2);
  176. ?>
  177. </div>
  178. <br />
  179. <div class="form-group">
  180. <label>Google Authenticator</label>
  181. <?php
  182. $googleAuthenticator = [
  183. 0 => "Désactivé",
  184. 1 => "Activé",
  185. ];
  186. // Vérifier si le 2FA est en attente de validation
  187. $is2FAPending = isset($user["id"]) ? user::is2FAPending($user["id"]) : false;
  188. $is2FAActive = isset($user["googleAuthenticator"]) && $user["googleAuthenticator"] == 1;
  189. if ($is2FAPending) {
  190. // Afficher "En attente de validation" quand le 2FA est pending
  191. echo '<div class="alert alert-warning"><i class="bi bi-hourglass-split"></i> En attente de validation du code</div>';
  192. html::printInput('type="hidden" name="googleAuthenticator" value="0"');
  193. } else {
  194. $bgStyle = $is2FAActive ? 'background-color: #d4edda; color: #155724;' : 'background-color: #f8d7da; color: #721c24;';
  195. $iconClass = $is2FAActive ? 'bi-shield-check' : 'bi-shield-x';
  196. ?>
  197. <div class="input-group">
  198. <span class="input-group-text" style="<?= $bgStyle ?>">
  199. <i class="bi <?= $iconClass ?>"></i>
  200. </span>
  201. <?php html::printSelect('name="googleAuthenticator" class="form-select" style="' . $bgStyle . '"', $googleAuthenticator, @$user["googleAuthenticator"]); ?>
  202. </div>
  203. <?php
  204. }
  205. ?>
  206. </div>
  207. <br />
  208. <?php endif; ?>
  209. <?php if ($protect == 0): ?>
  210. <div class="form-group">
  211. <label>Etat du compte</label>
  212. <?php
  213. $actif = [
  214. 0 => "Compte désactivé",
  215. 1 => "Compte activé",
  216. ];
  217. html::printSelect('name="actif" class="form-select"', $actif, @$user["actif"]);
  218. ?>
  219. </div>
  220. <br />
  221. <?php endif; ?>
  222. <?php if ($protect == 1): ?>
  223. <?= html::printInput('type="hidden" name="actif"', $user["actif"]); ?>
  224. <?php endif; ?>
  225. <?php if ((isset($user["deleted"]) and $user["deleted"] == 0) or core::ifGet("add")) : ?>
  226. <input class="btn btn-primary btn-lg" style="width: 100%; margin-bottom:20px;" type="button" value="<?php echo $submit ?>" onclick="validateAndSubmit()">
  227. <?php endif; ?>
  228. </form>
  229. <?php
  230. // Modal pour activer le 2FA si en attente de validation (pending)
  231. if (isset($user["id"]) and user::is2FAPending($user["id"]) and $protect == 1): ?>
  232. <style>
  233. .qrcode-container img {
  234. max-width: 100%;
  235. height: auto;
  236. display: block;
  237. margin: 0 auto;
  238. }
  239. #modal2FA .modal-content {
  240. border-radius: 15px;
  241. }
  242. #modal2FA .modal-header {
  243. border-radius: 15px 15px 0 0;
  244. }
  245. </style>
  246. <!-- Modal 2FA -->
  247. <div class="modal fade" id="modal2FA" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="modal2FALabel" aria-hidden="true">
  248. <div class="modal-dialog modal-dialog-centered">
  249. <div class="modal-content">
  250. <div class="modal-header bg-warning text-dark">
  251. <h5 class="modal-title" id="modal2FALabel">
  252. <i class="bi bi-shield-lock"></i> Activation de la double authentification
  253. </h5>
  254. </div>
  255. <div class="modal-body text-center">
  256. <div class="qrcode-container" style="max-width: 250px; margin: 0 auto;">
  257. <?php
  258. $qrCodeUrl = googleAuthenticator::getGoogleUrl("CMS CSE Invent: " . ENVIRONNEMENT, user::getMyGoogleAuthenticator(session::getId()));
  259. myQrcode::printQRCode($qrCodeUrl);
  260. ?>
  261. </div>
  262. <p class="mt-3 mb-2">
  263. <small>1. Scannez ce QR code avec votre application Google Authenticator</small><br>
  264. <small>2. Entrez le code à 6 chiffres généré par l'application</small>
  265. </p>
  266. <form method="post" action="/submit.php" class="mt-3" id="form-validate-2fa">
  267. <input type="hidden" name="from" value="validate-2fa">
  268. <input type="hidden" name="id" value="<?= $user["id"] ?>">
  269. <div class="input-group mb-3" style="max-width: 280px; margin: 0 auto;">
  270. <input type="text" class="form-control text-center" name="totp_code" id="totp_code"
  271. maxlength="6" pattern="[0-9]{6}" required
  272. placeholder="000000" autocomplete="off"
  273. style="font-size: 1.5rem; letter-spacing: 0.5rem; font-weight: bold;">
  274. <button class="btn btn-success" type="submit">
  275. <i class="bi bi-check-lg"></i>
  276. </button>
  277. </div>
  278. </form>
  279. <div class="mt-2 mb-2">
  280. <a href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2" target="_blank" class="text-muted me-2">
  281. <?= icon::getFont(["type" => "bi bi-android2", "size" => "24px"]) ?>
  282. </a>
  283. <a href="https://apps.apple.com/fr/app/google-authenticator/id388497605" target="_blank" class="text-muted">
  284. <?= icon::getFont(["type" => "bi bi-apple", "size" => "24px"]) ?>
  285. </a>
  286. </div>
  287. </div>
  288. <div class="modal-footer justify-content-center border-0">
  289. <form method="post" action="/submit.php">
  290. <input type="hidden" name="from" value="cancel-2fa-pending">
  291. <input type="hidden" name="id" value="<?= $user["id"] ?>">
  292. <button class="btn btn-outline-secondary btn-sm" type="submit">
  293. <i class="bi bi-x-lg"></i> Annuler l'activation
  294. </button>
  295. </form>
  296. </div>
  297. </div>
  298. </div>
  299. </div>
  300. <script>
  301. $(document).ready(function() {
  302. // Ouvrir automatiquement la modal
  303. var modal2FA = new bootstrap.Modal(document.getElementById('modal2FA'));
  304. modal2FA.show();
  305. // Focus sur le champ de code
  306. $('#modal2FA').on('shown.bs.modal', function() {
  307. $('#totp_code').focus();
  308. });
  309. });
  310. </script>
  311. <?php endif; ?>
  312. <script>
  313. $(document).ready(function() {
  314. $('#tags').inputTags({
  315. autocomplete: {
  316. values: <?php echo tags::getJquery(1) ?>,
  317. only: true
  318. },
  319. max: 3
  320. });
  321. });
  322. </script>
  323. <?php
  324. get::javascript("user");
  325. ?>