account.api.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. global $myUser, $myFirm, $conf;
  3. if (!$myUser->connected()) throw new Exception("Vous devez être connecté pour accéder à la page",401);
  4. $api_enabled = $myUser->preference('api_enabled');
  5. $api_id = decrypt($myUser->preference('api_id'));
  6. $api_secret = decrypt($myUser->preference('api_secret'));
  7. if(empty($api_id)){
  8. $myUser->preference('api_id',encrypt(bin2hex(random_bytes(15))));
  9. $myUser->preference('api_secret',encrypt(bin2hex(random_bytes(15))));
  10. $api_id = decrypt($myUser->preference('api_id'));
  11. $api_secret = decrypt($myUser->preference('api_secret'));
  12. $myUser->loadPreferences();
  13. $_SESSION['currentUser'] = serialize($myUser);
  14. }
  15. ?>
  16. <div id="account-api-form" class="account-api-form">
  17. <br>
  18. <div onclick="core_account_api_save()" class="btn btn-success float-right"><i class="fas fa-check"></i> Enregistrer</div>
  19. <h3>API & TOKEN</h3>
  20. <div class="clear"></div>
  21. <hr>
  22. <div class="row">
  23. <div class="col-md-6 api_section" data-enabled="<?php echo $api_enabled?1:0 ?>">
  24. <label><input id="api-enabled" type="checkbox" <?php echo $api_enabled?"checked='checked'":"" ?> onclick="$(this).closest('.api_section').attr('data-enabled',$(this).prop('checked')?1:0)" data-type="checkbox"> Activer les API pour ce compte</label>
  25. <div class="api_credentials" >
  26. <div><strong>ID API : </strong><input type="text" id="api_id" value="<?php echo $api_id; ?>" class="form-control" readonly="readonly"></div>
  27. <div><strong>SECRET API : </strong><input type="text" data-type="password" id="api_secret" value="<?php echo $api_secret; ?>" class="form-control" readonly="readonly"></div>
  28. </div>
  29. </div>
  30. </div>
  31. </div>