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

github.com/nextcloud/registration.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2021-04-09 16:05:59 +0300
committerJoas Schilling <coding@schilljs.com>2021-04-09 16:05:59 +0300
commit1e907c26646caa1bbbaf04cfb53b971c11b02bbe (patch)
tree98f93d9148943e2087fb6d36ba6e4a892e1e79d6 /lib/Events
parenta1ad79f4dfca068baa1187396a23757fb5d6116b (diff)
Allow apps to listen to the steps and validate the form data
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Events')
-rw-r--r--lib/Events/AFormEvent.php53
-rw-r--r--lib/Events/PassedFormEvent.php42
-rw-r--r--lib/Events/ShowFormEvent.php28
-rw-r--r--lib/Events/ValidateFormEvent.php44
4 files changed, 167 insertions, 0 deletions
diff --git a/lib/Events/AFormEvent.php b/lib/Events/AFormEvent.php
new file mode 100644
index 0000000..7566f47
--- /dev/null
+++ b/lib/Events/AFormEvent.php
@@ -0,0 +1,53 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2021 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Registration\Events;
+
+use OCP\EventDispatcher\Event;
+
+abstract class AFormEvent extends Event {
+ const STEP_EMAIL = 'email';
+ const STEP_VERIFICATION = 'verification';
+ const STEP_USER = 'user';
+
+ /** @var string */
+ protected $step;
+
+ /** @var string */
+ protected $registrationId;
+
+ public function __construct(string $step, string $registrationId = '') {
+ parent::__construct();
+ $this->step = $step;
+ $this->registrationId = $registrationId;
+ }
+
+ public function getStep(): string {
+ return $this->step;
+ }
+
+ public function getRegistrationIdentifier(): string {
+ return $this->registrationId;
+ }
+}
diff --git a/lib/Events/PassedFormEvent.php b/lib/Events/PassedFormEvent.php
new file mode 100644
index 0000000..0fead42
--- /dev/null
+++ b/lib/Events/PassedFormEvent.php
@@ -0,0 +1,42 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2021 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Registration\Events;
+
+use OCP\IUser;
+
+class PassedFormEvent extends AFormEvent {
+
+ /** @var IUser|null */
+ protected $user;
+
+ public function __construct(string $step, string $registrationId = '', ?IUser $user = null) {
+ parent::__construct($step, $registrationId);
+ $this->user = $user;
+ }
+
+ public function getUser(): ?IUser {
+ return $this->user;
+ }
+}
diff --git a/lib/Events/ShowFormEvent.php b/lib/Events/ShowFormEvent.php
new file mode 100644
index 0000000..764f381
--- /dev/null
+++ b/lib/Events/ShowFormEvent.php
@@ -0,0 +1,28 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2021 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Registration\Events;
+
+class ShowFormEvent extends AFormEvent {
+}
diff --git a/lib/Events/ValidateFormEvent.php b/lib/Events/ValidateFormEvent.php
new file mode 100644
index 0000000..217c551
--- /dev/null
+++ b/lib/Events/ValidateFormEvent.php
@@ -0,0 +1,44 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2021 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Registration\Events;
+
+class ValidateFormEvent extends AFormEvent {
+
+ /** @var string[] */
+ protected $errors;
+
+ public function __construct(string $step, string $registrationId = '') {
+ parent::__construct($step, $registrationId);
+ $this->errors = [];
+ }
+
+ public function addError(string $error): void {
+ $this->errors[] = $error;
+ }
+
+ public function getErrors(): array {
+ return $this->errors;
+ }
+}