aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Authentication/Listeners/UserLoggedInListener.php
blob: a8d4baeafa1da6da8baaa29897d59c4046e809f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
namespace OC\Authentication\Listeners;

use OC\Authentication\Token\Manager;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\User\Events\PostLoginEvent;

/**
 * @template-implements IEventListener<\OCP\User\Events\PostLoginEvent>
 */
class UserLoggedInListener implements IEventListener {
	/** @var Manager */
	private $manager;

	public function __construct(Manager $manager) {
		$this->manager = $manager;
	}

	public function handle(Event $event): void {
		if (!($event instanceof PostLoginEvent)) {
			return;
		}

		// prevent setting an empty pw as result of pw-less-login
		if ($event->getPassword() === '') {
			return;
		}

		// If this is already a token login there is nothing to do
		if ($event->isTokenLogin()) {
			return;
		}

		$this->manager->updatePasswords($event->getUser()->getUID(), $event->getPassword());
	}
}