authorize.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. helper::import('../../control.php');
  3. class myIm extends im
  4. {
  5. /**
  6. * Authorize and redirect user to url.
  7. *
  8. * @param string $account
  9. * @param string $token
  10. * @param string $device
  11. * @param string $url
  12. * @access public
  13. * @return void
  14. */
  15. public function authorize($account = '', $token = '', $device = '', $url = '')
  16. {
  17. if(!empty($url)) $url = str_replace('_', $this->config->requestFix, $url);
  18. if(empty($account) || empty($token)) die('Invalid params. Please provide account, token and url.');
  19. $user = $this->im->userIdentifyWithToken($account, $token, $device);
  20. if(!$user || is_string($user)) die('Invalid token.');
  21. if(empty($url)) die('Authorized, but no url to redirect to.');
  22. $user = $this->loadModel('user')->getByAccount($account);
  23. $user = $this->user->login($user);
  24. $url .= $this->config->requestType == 'GET' ? '&' : '?';
  25. $url .= "{$this->config->sessionVar}={$this->app->sessionID}";
  26. if ($this->config->requestType == 'GET') $url .= "&{$this->config->viewVar}=json";
  27. else $url = str_replace('.html', '.json', $url);
  28. header("Location: $url", true, 307);
  29. }
  30. }