Application.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bernhard Posselt <dev@bernhard-posselt.com>
  6. * @author Christoph Wurst <christoph@owncloud.com>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Roeland Jago Douma <roeland@famdouma.nl>
  11. * @author Thomas Müller <thomas.mueller@tmit.eu>
  12. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  13. *
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. namespace OC\Core;
  30. use OC\AppFramework\Utility\SimpleContainer;
  31. use OC\AppFramework\Utility\TimeFactory;
  32. use OC\Core\Controller\LoginController;
  33. use OC\Core\Controller\LostController;
  34. use OC\Core\Controller\TokenController;
  35. use OC\Core\Controller\TwoFactorChallengeController;
  36. use OC\Core\Controller\UserController;
  37. use OCP\AppFramework\App;
  38. use OCP\Util;
  39. /**
  40. * Class Application
  41. *
  42. * @package OC\Core
  43. */
  44. class Application extends App {
  45. /**
  46. * @param array $urlParams
  47. */
  48. public function __construct(array $urlParams=array()){
  49. parent::__construct('core', $urlParams);
  50. $container = $this->getContainer();
  51. /**
  52. * Controllers
  53. */
  54. $container->registerService('LostController', function(SimpleContainer $c) {
  55. return new LostController(
  56. $c->query('AppName'),
  57. $c->query('Request'),
  58. $c->query('URLGenerator'),
  59. $c->query('UserManager'),
  60. $c->query('Defaults'),
  61. $c->query('L10N'),
  62. $c->query('Config'),
  63. $c->query('SecureRandom'),
  64. $c->query('DefaultEmailAddress'),
  65. $c->query('IsEncryptionEnabled'),
  66. $c->query('Mailer'),
  67. $c->query('TimeFactory')
  68. );
  69. });
  70. $container->registerService('UserController', function(SimpleContainer $c) {
  71. return new UserController(
  72. $c->query('AppName'),
  73. $c->query('Request'),
  74. $c->query('UserManager'),
  75. $c->query('Defaults')
  76. );
  77. });
  78. $container->registerService('LoginController', function(SimpleContainer $c) {
  79. return new LoginController(
  80. $c->query('AppName'),
  81. $c->query('Request'),
  82. $c->query('UserManager'),
  83. $c->query('Config'),
  84. $c->query('Session'),
  85. $c->query('UserSession'),
  86. $c->query('URLGenerator'),
  87. $c->query('TwoFactorAuthManager'),
  88. $c->query('ServerContainer')->getBruteforceThrottler()
  89. );
  90. });
  91. $container->registerService('TwoFactorChallengeController', function (SimpleContainer $c) {
  92. return new TwoFactorChallengeController(
  93. $c->query('AppName'),
  94. $c->query('Request'),
  95. $c->query('TwoFactorAuthManager'),
  96. $c->query('UserSession'),
  97. $c->query('Session'),
  98. $c->query('URLGenerator'));
  99. });
  100. $container->registerService('TokenController', function(SimpleContainer $c) {
  101. return new TokenController(
  102. $c->query('AppName'),
  103. $c->query('Request'),
  104. $c->query('UserManager'),
  105. $c->query('ServerContainer')->query('OC\Authentication\Token\IProvider'),
  106. $c->query('TwoFactorAuthManager'),
  107. $c->query('SecureRandom')
  108. );
  109. });
  110. /**
  111. * Core class wrappers
  112. */
  113. $container->registerService('IsEncryptionEnabled', function(SimpleContainer $c) {
  114. return $c->query('ServerContainer')->getEncryptionManager()->isEnabled();
  115. });
  116. $container->registerService('URLGenerator', function(SimpleContainer $c) {
  117. return $c->query('ServerContainer')->getURLGenerator();
  118. });
  119. $container->registerService('UserManager', function(SimpleContainer $c) {
  120. return $c->query('ServerContainer')->getUserManager();
  121. });
  122. $container->registerService('Config', function(SimpleContainer $c) {
  123. return $c->query('ServerContainer')->getConfig();
  124. });
  125. $container->registerService('L10N', function(SimpleContainer $c) {
  126. return $c->query('ServerContainer')->getL10N('core');
  127. });
  128. $container->registerService('SecureRandom', function(SimpleContainer $c) {
  129. return $c->query('ServerContainer')->getSecureRandom();
  130. });
  131. $container->registerService('Session', function(SimpleContainer $c) {
  132. return $c->query('ServerContainer')->getSession();
  133. });
  134. $container->registerService('UserSession', function(SimpleContainer $c) {
  135. return $c->query('ServerContainer')->getUserSession();
  136. });
  137. $container->registerService('Defaults', function(SimpleContainer $c) {
  138. return $c->query('ServerContainer')->getThemingDefaults();
  139. });
  140. $container->registerService('Mailer', function(SimpleContainer $c) {
  141. return $c->query('ServerContainer')->getMailer();
  142. });
  143. $container->registerService('TimeFactory', function(SimpleContainer $c) {
  144. return new TimeFactory();
  145. });
  146. $container->registerService('DefaultEmailAddress', function() {
  147. return Util::getDefaultEmailAddress('lostpassword-noreply');
  148. });
  149. $container->registerService('TwoFactorAuthManager', function(SimpleContainer $c) {
  150. return $c->query('ServerContainer')->getTwoFactorAuthManager();
  151. });
  152. }
  153. }