profile.php 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/prerequisites.inc.php';
  3. if (!$oauth2_server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) {
  4. $oauth2_server->getResponse()->send();
  5. die;
  6. }
  7. $token = $oauth2_server->getAccessTokenData(OAuth2\Request::createFromGlobals());
  8. $stmt = $pdo->prepare("SELECT * FROM `mailbox` WHERE `username` = :username AND `active` = '1'");
  9. $stmt->execute(array(':username' => $token['user_id']));
  10. $mailbox = $stmt->fetch(PDO::FETCH_ASSOC);
  11. if (!empty($mailbox)) {
  12. if ($token['scope'] == 'profile') {
  13. header('Content-Type: application/json');
  14. echo json_encode(array(
  15. 'success' => true,
  16. 'username' => $token['user_id'],
  17. 'id' => $token['user_id'],
  18. 'identifier' => $token['user_id'],
  19. 'email' => (!empty($mailbox['username']) ? $mailbox['username'] : ''),
  20. 'full_name' => (!empty($mailbox['name']) ? $mailbox['name'] : 'mailcow administrative user'),
  21. 'displayName' => (!empty($mailbox['name']) ? $mailbox['name'] : 'mailcow administrative user'),
  22. 'created' => (!empty($mailbox['created']) ? $mailbox['created'] : ''),
  23. 'modified' => (!empty($mailbox['modified']) ? $mailbox['modified'] : ''),
  24. 'active' => (!empty($mailbox['active']) ? $mailbox['active'] : ''),
  25. ));
  26. exit;
  27. }
  28. }
  29. echo json_encode(array(
  30. 'success' => false
  31. ));