Expose password confirmation capabilities in the user backendtags/v15.0.0beta1
@@ -391,6 +391,7 @@ return array( | |||
'OCP\\User\\Backend\\ICreateUserBackend' => $baseDir . '/lib/public/User/Backend/ICreateUserBackend.php', | |||
'OCP\\User\\Backend\\IGetDisplayNameBackend' => $baseDir . '/lib/public/User/Backend/IGetDisplayNameBackend.php', | |||
'OCP\\User\\Backend\\IGetHomeBackend' => $baseDir . '/lib/public/User/Backend/IGetHomeBackend.php', | |||
'OCP\\User\\Backend\\IPasswordConfirmationBackend' => $baseDir . '/lib/public/User/Backend/IPasswordConfirmationBackend.php', | |||
'OCP\\User\\Backend\\IProvideAvatarBackend' => $baseDir . '/lib/public/User/Backend/IProvideAvatarBackend.php', | |||
'OCP\\User\\Backend\\ISetDisplayNameBackend' => $baseDir . '/lib/public/User/Backend/ISetDisplayNameBackend.php', | |||
'OCP\\User\\Backend\\ISetPasswordBackend' => $baseDir . '/lib/public/User/Backend/ISetPasswordBackend.php', |
@@ -421,6 +421,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c | |||
'OCP\\User\\Backend\\ICreateUserBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ICreateUserBackend.php', | |||
'OCP\\User\\Backend\\IGetDisplayNameBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IGetDisplayNameBackend.php', | |||
'OCP\\User\\Backend\\IGetHomeBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IGetHomeBackend.php', | |||
'OCP\\User\\Backend\\IPasswordConfirmationBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IPasswordConfirmationBackend.php', | |||
'OCP\\User\\Backend\\IProvideAvatarBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IProvideAvatarBackend.php', | |||
'OCP\\User\\Backend\\ISetDisplayNameBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ISetDisplayNameBackend.php', | |||
'OCP\\User\\Backend\\ISetPasswordBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ISetPasswordBackend.php', |
@@ -29,6 +29,7 @@ use OCP\AppFramework\Middleware; | |||
use OCP\AppFramework\Utility\ITimeFactory; | |||
use OCP\ISession; | |||
use OCP\IUserSession; | |||
use OCP\User\Backend\IPasswordConfirmationBackend; | |||
class PasswordConfirmationMiddleware extends Middleware { | |||
/** @var ControllerMethodReflector */ | |||
@@ -70,6 +71,13 @@ class PasswordConfirmationMiddleware extends Middleware { | |||
$user = $this->userSession->getUser(); | |||
$backendClassName = ''; | |||
if ($user !== null) { | |||
$backend = $user->getBackend(); | |||
if ($backend instanceof IPasswordConfirmationBackend) { | |||
if (!$backend->canConfirmPassword($user->getUID())) { | |||
return; | |||
} | |||
} | |||
$backendClassName = $user->getBackendClassName(); | |||
} | |||
@@ -37,6 +37,7 @@ use OCP\IL10N; | |||
use OCP\ISession; | |||
use OCP\IURLGenerator; | |||
use OCP\IUser; | |||
use OCP\User\Backend\IPasswordConfirmationBackend; | |||
class JSConfigHelper { | |||
@@ -109,12 +110,18 @@ class JSConfigHelper { | |||
public function getConfig() { | |||
$userBackendAllowsPasswordConfirmation = true; | |||
if ($this->currentUser !== null) { | |||
$uid = $this->currentUser->getUID(); | |||
$userBackend = $this->currentUser->getBackendClassName(); | |||
$backend = $this->currentUser->getBackend(); | |||
if ($backend instanceof IPasswordConfirmationBackend) { | |||
$userBackendAllowsPasswordConfirmation = $backend->canConfirmPassword($uid); | |||
} else if (isset($this->excludedUserBackEnds[$this->currentUser->getBackendClassName()])) { | |||
$userBackendAllowsPasswordConfirmation = false; | |||
} | |||
} else { | |||
$uid = null; | |||
$userBackend = ''; | |||
} | |||
// Get the config | |||
@@ -161,7 +168,7 @@ class JSConfigHelper { | |||
$array = [ | |||
"oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false', | |||
"oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false', | |||
"backendAllowsPasswordConfirmation" => !isset($this->excludedUserBackEnds[$userBackend]) ? 'true' : 'false', | |||
"backendAllowsPasswordConfirmation" => $userBackendAllowsPasswordConfirmation ? 'true' : 'false', | |||
"oc_dataURL" => is_string($dataLocation) ? "\"".$dataLocation."\"" : 'false', | |||
"oc_webroot" => "\"".\OC::$WEBROOT."\"", | |||
"oc_appswebroots" => str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution |
@@ -302,6 +302,10 @@ class User implements IUser { | |||
return get_class($this->backend); | |||
} | |||
public function getBackend() { | |||
return $this->backend; | |||
} | |||
/** | |||
* check if the backend allows the user to change his avatar on Personal page | |||
* |
@@ -108,6 +108,13 @@ interface IUser { | |||
*/ | |||
public function getBackendClassName(); | |||
/** | |||
* Get the backend for the current user object | |||
* | |||
* @since 15.0.0 | |||
*/ | |||
public function getBackend(); | |||
/** | |||
* check if the backend allows the user to change his avatar on Personal page | |||
* |
@@ -0,0 +1,36 @@ | |||
<?php | |||
declare(strict_types=1); | |||
/** | |||
* @copyright Copyright (c) 2018, Roeland Jago Douma <roeland@famdouma.nl> | |||
* | |||
* @author Roeland Jago Douma <roeland@famdouma.nl> | |||
* | |||
* @license GNU AGPL version 3 or any later version | |||
* | |||
* This program is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU Affero General Public License as | |||
* published by the Free Software Foundation, either version 3 of the | |||
* License, or (at your option) any later version. | |||
* | |||
* 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 | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
* | |||
*/ | |||
namespace OCP\User\Backend; | |||
/** | |||
* @since 15.0.0 | |||
*/ | |||
interface IPasswordConfirmationBackend { | |||
/** | |||
* @since 15.0.0 | |||
*/ | |||
public function canConfirmPassword(string $uid): bool; | |||
} |