Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2022-04-29 12:47:53 +0300
committerJoas Schilling <coding@schilljs.com>2022-04-30 14:09:32 +0300
commite8cf4671684ea6f3d5762dce8d4f34da982d5fb2 (patch)
tree2a50e3f269376727f4d56d4c93a93a027fadaf8f /lib
parent01fb3a6c834d548916032a8441e563b8eb18e147 (diff)
Move Room::verifyPassword() to the RoomService
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Command/Room/TRoomCommand.php2
-rw-r--r--lib/Controller/PageController.php8
-rw-r--r--lib/Controller/RoomController.php6
-rw-r--r--lib/Room.php22
-rw-r--r--lib/Service/ParticipantService.php10
-rw-r--r--lib/Service/RoomService.php24
6 files changed, 39 insertions, 33 deletions
diff --git a/lib/Command/Room/TRoomCommand.php b/lib/Command/Room/TRoomCommand.php
index b878fbb2e..154d32edf 100644
--- a/lib/Command/Room/TRoomCommand.php
+++ b/lib/Command/Room/TRoomCommand.php
@@ -175,7 +175,7 @@ trait TRoomCommand {
* @throws InvalidArgumentException
*/
protected function setRoomPassword(Room $room, string $password): void {
- if ($room->hasPassword() ? $room->verifyPassword($password)['result'] : ($password === '')) {
+ if ($room->hasPassword() ? $this->roomService->verifyPassword($room, $password)['result'] : ($password === '')) {
return;
}
diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php
index 9b3bfa440..2ee61ccc3 100644
--- a/lib/Controller/PageController.php
+++ b/lib/Controller/PageController.php
@@ -31,6 +31,7 @@ use OCA\Talk\Config;
use OCA\Talk\Manager;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\RoomService;
use OCA\Talk\TalkSession;
use OCA\Talk\TInitialState;
use OCA\Viewer\Event\LoadViewer;
@@ -66,6 +67,7 @@ class PageController extends Controller {
private IUserSession $userSession;
private LoggerInterface $logger;
private Manager $manager;
+ private RoomService $roomService;
private IURLGenerator $url;
private INotificationManager $notificationManager;
private IAppManager $appManager;
@@ -80,6 +82,7 @@ class PageController extends Controller {
?string $UserId,
LoggerInterface $logger,
Manager $manager,
+ RoomService $roomService,
IURLGenerator $url,
INotificationManager $notificationManager,
IAppManager $appManager,
@@ -96,6 +99,7 @@ class PageController extends Controller {
$this->userId = $UserId;
$this->logger = $logger;
$this->manager = $manager;
+ $this->roomService = $roomService;
$this->url = $url;
$this->notificationManager = $notificationManager;
$this->appManager = $appManager;
@@ -214,7 +218,7 @@ class PageController extends Controller {
if ($requirePassword) {
$password = $password !== '' ? $password : (string) $this->talkSession->getPasswordForRoom($token);
- $passwordVerification = $room->verifyPassword($password);
+ $passwordVerification = $this->roomService->verifyPassword($room, $password);
if ($passwordVerification['result']) {
$this->talkSession->renewSessionId();
@@ -289,7 +293,7 @@ class PageController extends Controller {
if ($room->hasPassword()) {
$password = $password !== '' ? $password : (string) $this->talkSession->getPasswordForRoom($token);
- $passwordVerification = $room->verifyPassword($password);
+ $passwordVerification = $this->roomService->verifyPassword($room, $password);
if ($passwordVerification['result']) {
$this->talkSession->renewSessionId();
$this->talkSession->setPasswordForRoom($token, $password);
diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php
index 216f4644d..94e56b157 100644
--- a/lib/Controller/RoomController.php
+++ b/lib/Controller/RoomController.php
@@ -1372,12 +1372,12 @@ class RoomController extends AEnvironmentAwareController {
$user = $this->userManager->get($this->userId);
try {
- $result = $room->verifyPassword((string) $this->session->getPasswordForRoom($token));
+ $result = $this->roomService->verifyPassword($room, (string) $this->session->getPasswordForRoom($token));
if ($user instanceof IUser) {
- $participant = $this->participantService->joinRoom($room, $user, $password, $result['result']);
+ $participant = $this->participantService->joinRoom($this->roomService, $room, $user, $password, $result['result']);
$this->participantService->generatePinForParticipant($room, $participant);
} else {
- $participant = $this->participantService->joinRoomAsNewGuest($room, $password, $result['result'], $previousParticipant);
+ $participant = $this->participantService->joinRoomAsNewGuest($this->roomService, $room, $password, $result['result'], $previousParticipant);
}
} catch (InvalidPasswordException $e) {
return new DataResponse([], Http::STATUS_FORBIDDEN);
diff --git a/lib/Room.php b/lib/Room.php
index a8beaf51c..923821324 100644
--- a/lib/Room.php
+++ b/lib/Room.php
@@ -31,7 +31,6 @@ use OCA\Talk\Events\ModifyLobbyEvent;
use OCA\Talk\Events\ModifyRoomEvent;
use OCA\Talk\Events\RoomEvent;
use OCA\Talk\Events\SignalingRoomPropertiesEvent;
-use OCA\Talk\Events\VerifyRoomPasswordEvent;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Model\SelectHelper;
@@ -1018,25 +1017,4 @@ class Room {
return true;
}
-
- /**
- * @param string $password
- * @return array
- */
- public function verifyPassword(string $password): array {
- $event = new VerifyRoomPasswordEvent($this, $password);
- $this->dispatcher->dispatch(self::EVENT_PASSWORD_VERIFY, $event);
-
- if ($event->isPasswordValid() !== null) {
- return [
- 'result' => $event->isPasswordValid(),
- 'url' => $event->getRedirectUrl(),
- ];
- }
-
- return [
- 'result' => !$this->hasPassword() || $this->hasher->verify($password, $this->password),
- 'url' => '',
- ];
- }
}
diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php
index b0a829f5c..045a5f769 100644
--- a/lib/Service/ParticipantService.php
+++ b/lib/Service/ParticipantService.php
@@ -234,6 +234,7 @@ class ParticipantService {
}
/**
+ * @param RoomService $roomService
* @param Room $room
* @param IUser $user
* @param string $password
@@ -242,7 +243,7 @@ class ParticipantService {
* @throws InvalidPasswordException
* @throws UnauthorizedException
*/
- public function joinRoom(Room $room, IUser $user, string $password, bool $passedPasswordProtection = false): Participant {
+ public function joinRoom(RoomService $roomService, Room $room, IUser $user, string $password, bool $passedPasswordProtection = false): Participant {
$event = new JoinRoomUserEvent($room, $user, $password, $passedPasswordProtection);
$this->dispatcher->dispatch(Room::EVENT_BEFORE_ROOM_CONNECT, $event);
@@ -258,7 +259,7 @@ class ParticipantService {
$manager = \OC::$server->get(Manager::class);
$isListableByUser = $manager->isRoomListableByUser($room, $user->getUID());
- if (!$isListableByUser && !$event->getPassedPasswordProtection() && !$room->verifyPassword($password)['result']) {
+ if (!$isListableByUser && !$event->getPassedPasswordProtection() && !$roomService->verifyPassword($room, $password)['result']) {
throw new InvalidPasswordException('Provided password is invalid');
}
@@ -295,6 +296,7 @@ class ParticipantService {
}
/**
+ * @param RoomService $roomService
* @param Room $room
* @param string $password
* @param bool $passedPasswordProtection
@@ -303,7 +305,7 @@ class ParticipantService {
* @throws InvalidPasswordException
* @throws UnauthorizedException
*/
- public function joinRoomAsNewGuest(Room $room, string $password, bool $passedPasswordProtection = false, ?Participant $previousParticipant = null): Participant {
+ public function joinRoomAsNewGuest(RoomService $roomService, Room $room, string $password, bool $passedPasswordProtection = false, ?Participant $previousParticipant = null): Participant {
$event = new JoinRoomGuestEvent($room, $password, $passedPasswordProtection);
$this->dispatcher->dispatch(Room::EVENT_BEFORE_GUEST_CONNECT, $event);
@@ -311,7 +313,7 @@ class ParticipantService {
throw new UnauthorizedException('Participant is not allowed to join');
}
- if (!$event->getPassedPasswordProtection() && !$room->verifyPassword($password)['result']) {
+ if (!$event->getPassedPasswordProtection() && !$roomService->verifyPassword($room, $password)['result']) {
throw new InvalidPasswordException();
}
diff --git a/lib/Service/RoomService.php b/lib/Service/RoomService.php
index b8263d76b..4805a33d8 100644
--- a/lib/Service/RoomService.php
+++ b/lib/Service/RoomService.php
@@ -25,6 +25,7 @@ namespace OCA\Talk\Service;
use InvalidArgumentException;
use OCA\Talk\Events\ModifyRoomEvent;
+use OCA\Talk\Events\VerifyRoomPasswordEvent;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
use OCA\Talk\Model\Attendee;
@@ -32,21 +33,25 @@ use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUser;
+use OCP\Security\IHasher;
use OCP\Share\IManager as IShareManager;
class RoomService {
protected Manager $manager;
protected ParticipantService $participantService;
protected IShareManager $shareManager;
- private IEventDispatcher $dispatcher;
+ protected IHasher $hasher;
+ protected IEventDispatcher $dispatcher;
public function __construct(Manager $manager,
ParticipantService $participantService,
IShareManager $shareManager,
+ IHasher $hasher,
IEventDispatcher $dispatcher) {
$this->manager = $manager;
$this->participantService = $participantService;
$this->shareManager = $shareManager;
+ $this->hasher = $hasher;
$this->dispatcher = $dispatcher;
}
@@ -195,4 +200,21 @@ class RoomService {
return true;
}
+
+ public function verifyPassword(Room $room, string $password): array {
+ $event = new VerifyRoomPasswordEvent($room, $password);
+ $this->dispatcher->dispatch(Room::EVENT_PASSWORD_VERIFY, $event);
+
+ if ($event->isPasswordValid() !== null) {
+ return [
+ 'result' => $event->isPasswordValid(),
+ 'url' => $event->getRedirectUrl(),
+ ];
+ }
+
+ return [
+ 'result' => !$room->hasPassword() || $this->hasher->verify($password, $room->getPassword()),
+ 'url' => '',
+ ];
+ }
}