Browse Source

Returning result and redirect url from verifyPassword. Signed-off-by: Peter Edens <petere@conceiva.com>

pull/1020/head
Peter Edens 7 years ago
parent
commit
12e82507db
  1. 32
      lib/Controller/PageController.php
  2. 22
      lib/Room.php

32
lib/Controller/PageController.php

@ -147,10 +147,22 @@ class PageController extends Controller {
}
if ($requirePassword) {
if ($password !== '' && $room->verifyPassword($password)) {
$passwordVerification = [
'result' => false,
'url' => ''
];
$passwordVerification = $room->verifyPassword($password);
if ($passwordVerification['result']) {
$this->session->setPasswordForRoom($token, $token);
} else {
return new TemplateResponse($this->appName, 'authenticate', [], 'guest');
if ($passwordVerification['url'] == '') {
return new TemplateResponse($this->appName, 'authenticate', [], 'guest');
}
else {
return new RedirectResponse($passwordVerification['url']);
}
}
}
}
@ -194,10 +206,22 @@ class PageController extends Controller {
$this->session->removePasswordForRoom($token);
if ($room->hasPassword()) {
if ($password !== '' && $room->verifyPassword($password)) {
$passwordVerification = [
'result' => false,
'url' => ''
];
$passwordVerification = $room->verifyPassword($password);
if ($passwordVerification['result']) {
$this->session->setPasswordForRoom($token, $token);
} else {
return new TemplateResponse($this->appName, 'authenticate', [], 'guest');
if ($passwordVerification['url'] == '') {
return new TemplateResponse($this->appName, 'authenticate', [], 'guest');
}
else {
return new RedirectResponse($passwordVerification['url']);
}
}
}

22
lib/Room.php

@ -516,7 +516,7 @@ class Room {
$result = $query->execute();
if ($result === 0) {
if (!$passedPasswordProtection && !$this->verifyPassword($password)) {
if (!$passedPasswordProtection && !$this->verifyPassword($password)['result']) {
throw new InvalidPasswordException();
}
@ -574,8 +574,8 @@ class Room {
*/
public function joinRoomGuest($password, $passedPasswordProtection = false) {
$this->dispatcher->dispatch(self::class . '::preJoinRoomGuest', new GenericEvent($this));
if (!$passedPasswordProtection && !$this->verifyPassword($password)) {
if (!$passedPasswordProtection && !$this->verifyPassword($password)['result']) {
throw new InvalidPasswordException();
}
@ -595,6 +595,7 @@ class Room {
return $sessionId;
}
/**
* @param string $sessionId
* @param bool $active
@ -633,7 +634,20 @@ class Room {
* @return bool
*/
public function verifyPassword($password) {
return !$this->hasPassword() || $this->hasher->verify($password, $this->password);
$event = new GenericEvent($this, [
'password' => $password
]);
$this->dispatcher->dispatch(self::class . '::verifyPassword', $event);
if ($event->hasArgument('result')) {
$result = $event->getArgument('result');
return $result;
}
$passwordVerification = [
'result' => !$this->hasPassword() || $this->hasher->verify($password, $this->password),
'url' => ''
];
return $passwordVerification;
}
/**

Loading…
Cancel
Save