summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-01-22 23:34:19 +0100
committerMorris Jobke <hey@morrisjobke.de>2015-01-22 23:34:19 +0100
commit254a1fa12a4d2f1be95f2edc84f209b92e9d91d2 (patch)
tree4bb2d97bc594a447228b6d1d47cdb19702d7afa3 /lib
parent5776bfec059f4fd32977e9ddbf97ca4d652dab7a (diff)
parent8eda6617618e0a1f650afc4e6766e799b4e62b82 (diff)
downloadnextcloud-server-254a1fa12a4d2f1be95f2edc84f209b92e9d91d2.tar.gz
nextcloud-server-254a1fa12a4d2f1be95f2edc84f209b92e9d91d2.zip
Merge pull request #13314 from owncloud/login-hook-logout
Return false if the login is canceled in a hook
Diffstat (limited to 'lib')
-rw-r--r--lib/base.php25
-rw-r--r--lib/private/user/loginexception.php12
-rw-r--r--lib/private/user/session.php7
-rw-r--r--lib/private/util.php4
4 files changed, 36 insertions, 12 deletions
diff --git a/lib/base.php b/lib/base.php
index dbfe0eb2f27..558be6b570f 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -846,19 +846,24 @@ class OC {
protected static function handleLogin() {
OC_App::loadApps(array('prelogin'));
$error = array();
+ $messages = [];
- // auth possible via apache module?
- if (OC::tryApacheAuth()) {
- $error[] = 'apacheauthfailed';
- } // remember was checked after last login
- elseif (OC::tryRememberLogin()) {
- $error[] = 'invalidcookie';
- } // logon via web form
- elseif (OC::tryFormLogin()) {
- $error[] = 'invalidpassword';
+ try {
+ // auth possible via apache module?
+ if (OC::tryApacheAuth()) {
+ $error[] = 'apacheauthfailed';
+ } // remember was checked after last login
+ elseif (OC::tryRememberLogin()) {
+ $error[] = 'invalidcookie';
+ } // logon via web form
+ elseif (OC::tryFormLogin()) {
+ $error[] = 'invalidpassword';
+ }
+ } catch (\OC\User\LoginException $e) {
+ $messages[] = $e->getMessage();
}
- OC_Util::displayLoginPage(array_unique($error));
+ OC_Util::displayLoginPage(array_unique($error), $messages);
}
/**
diff --git a/lib/private/user/loginexception.php b/lib/private/user/loginexception.php
new file mode 100644
index 00000000000..571f66bd945
--- /dev/null
+++ b/lib/private/user/loginexception.php
@@ -0,0 +1,12 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\User;
+
+class LoginException extends \Exception {
+}
diff --git a/lib/private/user/session.php b/lib/private/user/session.php
index 3cd83aae52f..ffb26776f97 100644
--- a/lib/private/user/session.php
+++ b/lib/private/user/session.php
@@ -189,6 +189,7 @@ class Session implements IUserSession, Emitter {
* @param string $uid
* @param string $password
* @return boolean|null
+ * @throws LoginException
*/
public function login($uid, $password) {
$this->manager->emit('\OC\User', 'preLogin', array($uid, $password));
@@ -199,7 +200,11 @@ class Session implements IUserSession, Emitter {
$this->setUser($user);
$this->setLoginName($uid);
$this->manager->emit('\OC\User', 'postLogin', array($user, $password));
- return true;
+ if ($this->isLoggedIn()) {
+ return true;
+ } else {
+ throw new LoginException('Login canceled by app');
+ }
} else {
return false;
}
diff --git a/lib/private/util.php b/lib/private/util.php
index 3b943f046bf..e2b7eed1ba5 100644
--- a/lib/private/util.php
+++ b/lib/private/util.php
@@ -782,12 +782,14 @@ class OC_Util {
/**
* @param array $errors
+ * @param string[] $messages
*/
- public static function displayLoginPage($errors = array()) {
+ public static function displayLoginPage($errors = array(), $messages = []) {
$parameters = array();
foreach ($errors as $value) {
$parameters[$value] = true;
}
+ $parameters['messages'] = $messages;
if (!empty($_REQUEST['user'])) {
$parameters["username"] = $_REQUEST['user'];
$parameters['user_autofocus'] = false;