PageRenderTime 57ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/controllers/github.php

https://bitbucket.org/delpho/tickhub
PHP | 31 lines | 30 code | 1 blank | 0 comment | 9 complexity | 9bc5e431cca2d22eb4a73d1dcb8e72d6 MD5 | raw file
  1. <?php
  2. if ( strpos($_SERVER['REQUEST_URI'],'/github/callback/') === 0 ) {
  3. Log::getInstance()->log("Github Callback: " . print_r($_GET, true));
  4. $ref = isset($_GET['ref'])?$_GET['ref']:null;
  5. if ( $ref != null ) {
  6. $user = null;
  7. try{
  8. $user = new User($ref);
  9. } catch (Exception $ex) {
  10. Log::getInstance()->log("[github callback] Exception using ref '$ref' {$ex->getMessage()}");
  11. $user = null;
  12. }
  13. if ( $user != null ) {
  14. $code = isset($_GET['code'])?$_GET['code']:null;
  15. if ( $code != null ) {
  16. $github = new Github($user->getID());
  17. $accessToken = $github->getAccessToken($code);
  18. header('Location: ' .SERVER_URL.'dashboard/github/'.($accessToken!= null?'success':'invalid').'/');
  19. exit;
  20. } else {
  21. header('Location: ' .SERVER_URL.'dashboard/github/invalid_code/');
  22. exit;
  23. }
  24. }
  25. }
  26. header('Location: ' .SERVER_URL.'dashboard/github/error/');
  27. exit;
  28. } else {
  29. header('Location: ' .SERVER_URL.'dashboard/');
  30. }