1
0

Application.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Björn Schießle <bjoern@schiessle.org>
  7. * @author Christoph Wurst <christoph@owncloud.com>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Robin Appelman <robin@icewind.nl>
  12. *
  13. * @license AGPL-3.0
  14. *
  15. * This code is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License, version 3,
  17. * as published by the Free Software Foundation.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License, version 3,
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>
  26. *
  27. */
  28. namespace OC\Settings;
  29. use OC\AppFramework\Utility\TimeFactory;
  30. use OC\Authentication\Token\IProvider;
  31. use OC\Server;
  32. use OC\Settings\Activity\Provider;
  33. use OC\Settings\Activity\SecurityFilter;
  34. use OC\Settings\Activity\SecurityProvider;
  35. use OC\Settings\Activity\SecuritySetting;
  36. use OC\Settings\Activity\Setting;
  37. use OC\Settings\Mailer\NewUserMailHelper;
  38. use OC\Settings\Middleware\SubadminMiddleware;
  39. use OCP\AppFramework\App;
  40. use OCP\Defaults;
  41. use OCP\IContainer;
  42. use OCP\Settings\IManager;
  43. use OCP\Util;
  44. /**
  45. * @package OC\Settings
  46. */
  47. class Application extends App {
  48. /**
  49. * @param array $urlParams
  50. */
  51. public function __construct(array $urlParams=[]){
  52. parent::__construct('settings', $urlParams);
  53. $container = $this->getContainer();
  54. // Register Middleware
  55. $container->registerAlias('SubadminMiddleware', SubadminMiddleware::class);
  56. $container->registerMiddleWare('SubadminMiddleware');
  57. /**
  58. * Core class wrappers
  59. */
  60. /** FIXME: Remove once OC_User is non-static and mockable */
  61. $container->registerService('isAdmin', function() {
  62. return \OC_User::isAdminUser(\OC_User::getUser());
  63. });
  64. /** FIXME: Remove once OC_SubAdmin is non-static and mockable */
  65. $container->registerService('isSubAdmin', function(IContainer $c) {
  66. $userObject = \OC::$server->getUserSession()->getUser();
  67. $isSubAdmin = false;
  68. if($userObject !== null) {
  69. $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
  70. }
  71. return $isSubAdmin;
  72. });
  73. $container->registerService('userCertificateManager', function(IContainer $c) {
  74. return $c->query('ServerContainer')->getCertificateManager();
  75. }, false);
  76. $container->registerService('systemCertificateManager', function (IContainer $c) {
  77. return $c->query('ServerContainer')->getCertificateManager(null);
  78. }, false);
  79. $container->registerService(IProvider::class, function (IContainer $c) {
  80. return $c->query('ServerContainer')->query(IProvider::class);
  81. });
  82. $container->registerService(IManager::class, function (IContainer $c) {
  83. return $c->query('ServerContainer')->getSettingsManager();
  84. });
  85. $container->registerService(NewUserMailHelper::class, function (IContainer $c) {
  86. /** @var Server $server */
  87. $server = $c->query('ServerContainer');
  88. /** @var Defaults $defaults */
  89. $defaults = $server->query(Defaults::class);
  90. return new NewUserMailHelper(
  91. $defaults,
  92. $server->getURLGenerator(),
  93. $server->getL10N('settings'),
  94. $server->getMailer(),
  95. $server->getSecureRandom(),
  96. new TimeFactory(),
  97. $server->getConfig(),
  98. $server->getCrypto(),
  99. Util::getDefaultEmailAddress('no-reply')
  100. );
  101. });
  102. }
  103. public function register() {
  104. $activityManager = $this->getContainer()->getServer()->getActivityManager();
  105. $activityManager->registerSetting(Setting::class); // FIXME move to info.xml
  106. $activityManager->registerProvider(Provider::class); // FIXME move to info.xml
  107. $activityManager->registerFilter(SecurityFilter::class); // FIXME move to info.xml
  108. $activityManager->registerSetting(SecuritySetting::class); // FIXME move to info.xml
  109. $activityManager->registerProvider(SecurityProvider::class); // FIXME move to info.xml
  110. Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword');
  111. Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo');
  112. }
  113. /**
  114. * @param array $parameters
  115. * @throws \InvalidArgumentException
  116. * @throws \BadMethodCallException
  117. * @throws \Exception
  118. * @throws \OCP\AppFramework\QueryException
  119. */
  120. public function onChangePassword(array $parameters) {
  121. /** @var Hooks $hooks */
  122. $hooks = $this->getContainer()->query(Hooks::class);
  123. $hooks->onChangePassword($parameters['uid']);
  124. }
  125. /**
  126. * @param array $parameters
  127. * @throws \InvalidArgumentException
  128. * @throws \BadMethodCallException
  129. * @throws \Exception
  130. * @throws \OCP\AppFramework\QueryException
  131. */
  132. public function onChangeInfo(array $parameters) {
  133. if ($parameters['feature'] !== 'eMailAddress') {
  134. return;
  135. }
  136. /** @var Hooks $hooks */
  137. $hooks = $this->getContainer()->query(Hooks::class);
  138. $hooks->onChangeEmail($parameters['user'], $parameters['old_value']);
  139. }
  140. }