OCSController.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. *
  4. * @author Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @license GNU AGPL version 3 or any later version
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. namespace OC\Core\Controller;
  23. use OC\CapabilitiesManager;
  24. use OCP\AppFramework\Http\DataResponse;
  25. use OCP\IRequest;
  26. use OCP\IUserSession;
  27. class OCSController extends \OCP\AppFramework\OCSController {
  28. /** @var CapabilitiesManager */
  29. private $capabilitiesManager;
  30. /** @var IUserSession */
  31. private $userSession;
  32. /**
  33. * OCSController constructor.
  34. *
  35. * @param string $appName
  36. * @param IRequest $request
  37. * @param CapabilitiesManager $capabilitiesManager
  38. * @param IUserSession $userSession
  39. */
  40. public function __construct($appName,
  41. IRequest $request,
  42. CapabilitiesManager $capabilitiesManager,
  43. IUserSession $userSession) {
  44. parent::__construct($appName, $request);
  45. $this->capabilitiesManager = $capabilitiesManager;
  46. $this->userSession = $userSession;
  47. }
  48. /**
  49. * @PublicPage
  50. *
  51. * @return DataResponse
  52. */
  53. public function getConfig() {
  54. $data = [
  55. 'version' => '1.7',
  56. 'website' => 'Nextcloud',
  57. 'host' => $this->request->getServerHost(),
  58. 'contact' => '',
  59. 'ssl' => 'false',
  60. ];
  61. return new DataResponse($data);
  62. }
  63. /**
  64. * @NoAdminRequired
  65. * @return DataResponse
  66. */
  67. public function getCapabilities() {
  68. $result = [];
  69. list($major, $minor, $micro) = \OCP\Util::getVersion();
  70. $result['version'] = array(
  71. 'major' => $major,
  72. 'minor' => $minor,
  73. 'micro' => $micro,
  74. 'string' => \OC_Util::getVersionString(),
  75. 'edition' => \OC_Util::getEditionString(),
  76. );
  77. $result['capabilities'] = $this->capabilitiesManager->getCapabilities();
  78. return new DataResponse($result);
  79. }
  80. /**
  81. * @NoAdminRequired
  82. * @return DataResponse
  83. */
  84. public function getCurrentUser() {
  85. $userObject = $this->userSession->getUser();
  86. $data = [
  87. 'id' => $userObject->getUID(),
  88. 'display-name' => $userObject->getDisplayName(),
  89. 'email' => $userObject->getEMailAddress(),
  90. ];
  91. return new DataResponse($data);
  92. }
  93. }