]> source.dussan.org Git - nextcloud-server.git/commitdiff
Throw an exception when login is canceled by an app
authorRobin Appelman <icewind@owncloud.com>
Thu, 22 Jan 2015 13:13:17 +0000 (14:13 +0100)
committerRobin Appelman <icewind@owncloud.com>
Thu, 22 Jan 2015 13:13:17 +0000 (14:13 +0100)
lib/base.php
lib/private/user/loginexception.php [new file with mode: 0644]
lib/private/user/session.php

index 34fa178ebf7260b5a262ce1086c23d72dda41bf9..6ac38ac86d53b3e8ab762799b994a83ee99e4617 100644 (file)
@@ -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 (file)
index 0000000..571f66b
--- /dev/null
@@ -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 {
+}
index cad6e225b037932728907d69b052ff6b432f7d95..ffb26776f97dee788dec7184992533eee750c3c5 100644 (file)
@@ -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;
                                }