diff --git a/core/Application.php b/core/Application.php
index 30376ee4f2..805208d469 100644
--- a/core/Application.php
+++ b/core/Application.php
@@ -28,6 +28,7 @@ namespace OC\Core;
use OC\AppFramework\Utility\SimpleContainer;
use OC\AppFramework\Utility\TimeFactory;
+use OC\Core\Controller\LoginController;
use \OCP\AppFramework\App;
use OC\Core\Controller\LostController;
use OC\Core\Controller\UserController;
@@ -89,6 +90,16 @@ class Application extends App {
$c->query('Logger')
);
});
+ $container->registerService('LoginController', function(SimpleContainer $c) {
+ return new LoginController(
+ $c->query('AppName'),
+ $c->query('Request'),
+ $c->query('UserManager'),
+ $c->query('Config'),
+ $c->query('Session'),
+ $c->query('UserSession')
+ );
+ });
/**
* Core class wrappers
@@ -114,6 +125,9 @@ class Application extends App {
$container->registerService('AvatarManager', function(SimpleContainer $c) {
return $c->query('ServerContainer')->getAvatarManager();
});
+ $container->registerService('Session', function(SimpleContainer $c) {
+ return $c->query('ServerContainer')->getSession();
+ });
$container->registerService('UserSession', function(SimpleContainer $c) {
return $c->query('ServerContainer')->getUserSession();
});
diff --git a/core/Controller/LoginController.php b/core/Controller/LoginController.php
new file mode 100644
index 0000000000..661fb04385
--- /dev/null
+++ b/core/Controller/LoginController.php
@@ -0,0 +1,138 @@
+
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see
+ *
+ */
+
+namespace OC\Core\Controller;
+
+use OC\Setup;
+use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http\RedirectResponse;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IConfig;
+use OCP\IRequest;
+use OCP\ISession;
+use OCP\IUser;
+use OCP\IUserManager;
+use OCP\IUserSession;
+
+class LoginController extends Controller {
+ /** @var IUserManager */
+ private $userManager;
+ /** @var IConfig */
+ private $config;
+ /** @var ISession */
+ private $session;
+ /** @var IUserSession */
+ private $userSession;
+
+ /**
+ * @param string $appName
+ * @param IRequest $request
+ * @param IUserManager $userManager
+ * @param IConfig $config
+ * @param ISession $session
+ * @param IUserSession $userSession
+ */
+ function __construct($appName,
+ IRequest $request,
+ IUserManager $userManager,
+ IConfig $config,
+ ISession $session,
+ IUserSession $userSession) {
+ parent::__construct($appName, $request);
+ $this->userManager = $userManager;
+ $this->config = $config;
+ $this->session = $session;
+ $this->userSession = $userSession;
+ }
+
+ /**
+ * @PublicPage
+ * @NoCSRFRequired
+ * @UseSession
+ *
+ * @param string $user
+ * @param string $redirect_url
+ * @param string $remember_login
+ *
+ * @return TemplateResponse
+ */
+ public function showLoginForm($user,
+ $redirect_url,
+ $remember_login) {
+ if($this->userSession->isLoggedIn()) {
+ return new RedirectResponse(\OC_Util::getDefaultPageUrl());
+ }
+
+ $parameters = array();
+ $loginMessages = $this->session->get('loginMessages');
+ $errors = [];
+ $messages = [];
+ if(is_array($loginMessages)) {
+ list($errors, $messages) = $loginMessages;
+ }
+ $this->session->remove('loginMessages');
+ foreach ($errors as $value) {
+ $parameters[$value] = true;
+ }
+
+ $parameters['messages'] = $messages;
+ if (!empty($user)) {
+ $parameters['username'] = $user;
+ $parameters['user_autofocus'] = false;
+ } else {
+ $parameters['username'] = '';
+ $parameters['user_autofocus'] = true;
+ }
+ if (!empty($redirect_url)) {
+ $parameters['redirect_url'] = $redirect_url;
+ }
+
+ $parameters['canResetPassword'] = true;
+ if (!$this->config->getSystemValue('lost_password_link')) {
+ if (!empty($user)) {
+ $userObj = $this->userManager->get($user);
+ if ($userObj instanceof IUser) {
+ $parameters['canResetPassword'] = $userObj->canChangePassword();
+ }
+ }
+ }
+
+ $parameters['alt_login'] = \OC_App::getAlternativeLogIns();
+ $parameters['rememberLoginAllowed'] = \OC_Util::rememberLoginAllowed();
+ $parameters['rememberLoginState'] = !empty($remember_login) ? $remember_login : 0;
+
+ if (!empty($user)) {
+ $parameters['username'] = $user;
+ $parameters['user_autofocus'] = false;
+ } else {
+ $parameters['username'] = '';
+ $parameters['user_autofocus'] = true;
+ }
+
+ return new TemplateResponse(
+ $this->appName,
+ 'login',
+ $parameters,
+ 'guest'
+ );
+ }
+
+}
diff --git a/core/routes.php b/core/routes.php
index 8981eb618f..bcad9d0dad 100644
--- a/core/routes.php
+++ b/core/routes.php
@@ -42,6 +42,7 @@ $application->registerRoutes($this, [
['name' => 'avatar#postCroppedAvatar', 'url' => '/avatar/cropped', 'verb' => 'POST'],
['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'],
['name' => 'avatar#postAvatar', 'url' => '/avatar/', 'verb' => 'POST'],
+ ['name' => 'login#showLoginForm', 'url' => '/login', 'verb' => 'GET'],
]
]);
diff --git a/core/templates/login.php b/core/templates/login.php
index 9934d4988d..f683323337 100644
--- a/core/templates/login.php
+++ b/core/templates/login.php
@@ -9,7 +9,7 @@ script('core', [
?>
-