diff --git a/application/forms/DeleteSourceForm.php b/application/forms/DeleteSourceForm.php index f8dab03f0..4c7ba9b62 100644 --- a/application/forms/DeleteSourceForm.php +++ b/application/forms/DeleteSourceForm.php @@ -112,7 +112,7 @@ public function removeSource(Connection $db): void $db->update( 'source', - ['changed_at' => (int) (new DateTime())->format("Uv"), 'deleted' => 'y'], + ['changed_at' => (int) (new DateTime())->format("Uv"), 'deleted' => 'y', 'listener_username' => null], ['id = ?' => $this->source->id] ); } diff --git a/application/forms/SourceForm.php b/application/forms/SourceForm.php index a2dab60cb..565797f51 100644 --- a/application/forms/SourceForm.php +++ b/application/forms/SourceForm.php @@ -71,6 +71,30 @@ protected function assemble(): void 'disabledOptions' => [''] ] ); + + $this->addElement( + 'text', + 'listener_username', + [ + 'required' => true, + 'label' => $this->translate('Username'), + 'validators' => [new CallbackValidator( + function ($value, CallbackValidator $validator) { + // Username must be unique + $source = Source::on($this->db) + ->filter(Filter::equal('listener_username', $value)) + ->first(); + if ($source !== null) { + $validator->addMessage($this->translate('This username is already in use.')); + return false; + } + + return true; + } + )] + ] + ); + $this->addElement( 'password', 'listener_password', @@ -217,7 +241,8 @@ private function fetchDbValues(): array return [ 'name' => $source->name, - 'type' => $source->type + 'type' => $source->type, + 'listener_username' => $source->listener_username ]; } } diff --git a/library/Notifications/Model/Source.php b/library/Notifications/Model/Source.php index cc4f939c5..1dc16b355 100644 --- a/library/Notifications/Model/Source.php +++ b/library/Notifications/Model/Source.php @@ -21,6 +21,7 @@ * @property int $id The primary key * @property string $type Type identifier * @property string $name The user-defined name + * @property ?string $listener_username The username for HTTP authentication * @property ?string $listener_password_hash * @property DateTime $changed_at * @property bool $deleted @@ -48,6 +49,7 @@ public function getColumns(): array return [ 'type', 'name', + 'listener_username', 'listener_password_hash', 'changed_at', 'deleted' @@ -57,9 +59,10 @@ public function getColumns(): array public function getColumnDefinitions(): array { return [ - 'type' => t('Type'), - 'name' => t('Name'), - 'changed_at' => t('Changed At') + 'type' => t('Type'), + 'name' => t('Name'), + 'listener_username' => t('Username'), + 'changed_at' => t('Changed At') ]; }