Throw an exception when login is canceled by an app

remotes/origin/create-share-target-reuse
Robin Appelman 11 years ago
parent 8a9acc5083
commit 8eda661761
  1. 25
      lib/base.php
  2. 12
      lib/private/user/loginexception.php
  3. 7
      lib/private/user/session.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);
}
/**

@ -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 {
}

@ -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;
}

Loading…
Cancel
Save