Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dispatch BeforeUserLoggedInEvent #36883

Merged
merged 1 commit into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/private/legacy/OC_User.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ILogger;
use OCP\IUserManager;
use OCP\User\Events\BeforeUserLoggedInEvent;
use OCP\User\Events\UserLoggedInEvent;

/**
Expand Down Expand Up @@ -172,6 +173,10 @@ public static function loginWithApache(\OCP\Authentication\IApacheBackend $backe
if (self::getUser() !== $uid) {
self::setUserId($uid);
$userSession = \OC::$server->getUserSession();

/** @var IEventDispatcher $dispatcher */
$dispatcher = \OC::$server->get(IEventDispatcher::class);

if ($userSession->getUser() && !$userSession->getUser()->isEnabled()) {
$message = \OC::$server->getL10N('lib')->t('User disabled');
throw new LoginException($message);
Expand All @@ -182,6 +187,10 @@ public static function loginWithApache(\OCP\Authentication\IApacheBackend $backe
if ($backend instanceof \OCP\Authentication\IProvideUserSecretBackend) {
$password = $backend->getCurrentUserSecret();
}

/** @var IEventDispatcher $dispatcher */
$dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password, $backend));

$userSession->createSessionToken($request, $uid, $uid, $password);
$userSession->createRememberMeToken($userSession->getUser());
// setup the filesystem
Expand All @@ -199,8 +208,6 @@ public static function loginWithApache(\OCP\Authentication\IApacheBackend $backe
'isTokenLogin' => false,
]
);
/** @var IEventDispatcher $dispatcher */
$dispatcher = \OC::$server->get(IEventDispatcher::class);
$dispatcher->dispatchTyped(new UserLoggedInEvent(
\OC::$server->get(IUserManager::class)->get($uid),
$uid,
Expand Down
27 changes: 20 additions & 7 deletions lib/public/User/Events/BeforeUserLoggedInEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,29 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCP\User\Events;

use OCP\Authentication\IApacheBackend;
use OCP\EventDispatcher\Event;

/**
* @since 18.0.0
*/
class BeforeUserLoggedInEvent extends Event {
/** @var string */
private $username;

/** @var string */
private $password;
private string $username;
private ?string $password;
private ?IApacheBackend $backend;

/**
* @since 18.0.0
* @since 26.0.0 password can be null
*/
public function __construct(string $username, string $password) {
public function __construct(string $username, ?string $password, ?IApacheBackend $backend = null) {
parent::__construct();
$this->username = $username;
$this->password = $password;
$this->backend = $backend;
}

/**
Expand All @@ -58,8 +60,19 @@ public function getUsername(): string {

/**
* @since 18.0.0
* @since 26.0.0 value can be null
*/
public function getPassword(): string {
public function getPassword(): ?string {
return $this->password;
}

/**
* return backend if available (or null)
*
* @return IApacheBackend|null
* @since 26.0.0
*/
public function getBackend(): ?IApacheBackend {
return $this->backend;
}
}