diff options
author | Robin Appelman <icewind@owncloud.com> | 2015-01-22 14:13:17 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2015-01-22 14:13:17 +0100 |
commit | 8eda6617618e0a1f650afc4e6766e799b4e62b82 (patch) | |
tree | 775a1d6a785a17b25a2f0f89b3beaa7883303d00 | |
parent | 8a9acc5083c02a8b636e9d78e800aacb2a1782bf (diff) | |
download | nextcloud-server-8eda6617618e0a1f650afc4e6766e799b4e62b82.tar.gz nextcloud-server-8eda6617618e0a1f650afc4e6766e799b4e62b82.zip |
Throw an exception when login is canceled by an app
-rw-r--r-- | lib/base.php | 25 | ||||
-rw-r--r-- | lib/private/user/loginexception.php | 12 | ||||
-rw-r--r-- | lib/private/user/session.php | 7 |
3 files changed, 33 insertions, 11 deletions
diff --git a/lib/base.php b/lib/base.php index 34fa178ebf7..6ac38ac86d5 100644 --- a/lib/base.php +++ b/lib/base.php @@ -844,19 +844,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 cad6e225b03..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 $this->isLoggedIn(); + if ($this->isLoggedIn()) { + return true; + } else { + throw new LoginException('Login canceled by app'); + } } else { return false; } |