Skip to content

Commit ef0e48a

Browse files
committed
dispatch BeforeUserLoggedInEvent
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent 6cfd53a commit ef0e48a

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

lib/private/legacy/OC_User.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
use OCP\EventDispatcher\IEventDispatcher;
4141
use OCP\ILogger;
4242
use OCP\IUserManager;
43+
use OCP\User\Events\BeforeUserLoggedInEvent;
4344
use OCP\User\Events\UserLoggedInEvent;
4445

4546
/**
@@ -166,12 +167,16 @@ public static function setupBackends() {
166167
public static function loginWithApache(\OCP\Authentication\IApacheBackend $backend) {
167168
$uid = $backend->getCurrentUserId();
168169
$run = true;
169-
OC_Hook::emit("OC_User", "pre_login", ["run" => &$run, "uid" => $uid, 'backend' => $backend]);
170+
// OC_Hook::emit("OC_User", "pre_login", ["run" => &$run, "uid" => $uid, 'backend' => $backend]);
170171

171172
if ($uid) {
172173
if (self::getUser() !== $uid) {
173174
self::setUserId($uid);
174175
$userSession = \OC::$server->getUserSession();
176+
177+
/** @var IEventDispatcher $dispatcher */
178+
$dispatcher = \OC::$server->get(IEventDispatcher::class);
179+
175180
if ($userSession->getUser() && !$userSession->getUser()->isEnabled()) {
176181
$message = \OC::$server->getL10N('lib')->t('User disabled');
177182
throw new LoginException($message);
@@ -182,6 +187,10 @@ public static function loginWithApache(\OCP\Authentication\IApacheBackend $backe
182187
if ($backend instanceof \OCP\Authentication\IProvideUserSecretBackend) {
183188
$password = $backend->getCurrentUserSecret();
184189
}
190+
191+
/** @var IEventDispatcher $dispatcher */
192+
$dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password, $backend));
193+
185194
$userSession->createSessionToken($request, $uid, $uid, $password);
186195
$userSession->createRememberMeToken($userSession->getUser());
187196
// setup the filesystem
@@ -199,8 +208,6 @@ public static function loginWithApache(\OCP\Authentication\IApacheBackend $backe
199208
'isTokenLogin' => false,
200209
]
201210
);
202-
/** @var IEventDispatcher $dispatcher */
203-
$dispatcher = \OC::$server->get(IEventDispatcher::class);
204211
$dispatcher->dispatchTyped(new UserLoggedInEvent(
205212
\OC::$server->get(IUserManager::class)->get($uid),
206213
$uid,

lib/public/User/Events/BeforeUserLoggedInEvent.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,28 @@
2424
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2525
*
2626
*/
27+
2728
namespace OCP\User\Events;
2829

30+
use OCP\Authentication\IApacheBackend;
2931
use OCP\EventDispatcher\Event;
3032

3133
/**
3234
* @since 18.0.0
3335
*/
3436
class BeforeUserLoggedInEvent extends Event {
35-
/** @var string */
36-
private $username;
37-
38-
/** @var string */
39-
private $password;
37+
private string $username;
38+
private string $password;
39+
private ?IApacheBackend $backend;
4040

4141
/**
4242
* @since 18.0.0
4343
*/
44-
public function __construct(string $username, string $password) {
44+
public function __construct(string $username, string $password, ?IApacheBackend $backend = null) {
4545
parent::__construct();
4646
$this->username = $username;
4747
$this->password = $password;
48+
$this->backend = $backend;
4849
}
4950

5051
/**
@@ -62,4 +63,14 @@ public function getUsername(): string {
6263
public function getPassword(): string {
6364
return $this->password;
6465
}
66+
67+
/**
68+
* return backend if available (or null)
69+
*
70+
* @return IApacheBackend|null
71+
* @since 26.0.0
72+
*/
73+
public function getBackend(): ?IApacheBackend {
74+
return $this->backend;
75+
}
6576
}

0 commit comments

Comments
 (0)