index.php 967 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. header('Content-Type: application/json; charset=utf-8');
  3. require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'common.php');
  4. $response = array();
  5. try{
  6. if(!$myUser){
  7. if(isset($_['token'])){
  8. $userManager = new User();
  9. $myUser = $userManager->load(array('token'=>$_['token']));
  10. if(isset($myUser) && $myUser!=false)
  11. $myUser->loadRight();
  12. }
  13. if(isset($_['login'])){
  14. $userManager = new User();
  15. $myUser = $userManager->load(array('login'=>$_['login'],'password'=>$_['password']));
  16. if(!$myUser) throw new Exception('Mauvais identifiant ou mot de passe');
  17. $myUser->loadRight();
  18. }
  19. }
  20. $myUser = (!$myUser?new User():$myUser);
  21. Plugin::callHook("api", array(&$_,&$response));
  22. }catch(Exception $e){
  23. $response['error'] = Personality::response('WORRY_EMOTION').' : '.$e->getMessage();
  24. }
  25. $response = json_encode($response);
  26. if(isset($_['callback']))
  27. $response = $_['callback'].'('.$response.');';
  28. echo $response;
  29. ?>