Skip to content

Commit

Permalink
Limit contact.username to 254 chars
Browse files Browse the repository at this point in the history
  • Loading branch information
Al2Klimov committed Jul 3, 2024
1 parent 8791c69 commit 35ecfa7
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions library/Notifications/Web/Form/ContactForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use ipl\Stdlib\Filter;
use ipl\Validator\CallbackValidator;
use ipl\Validator\EmailAddressValidator;
use ipl\Validator\StringLengthValidator;
use ipl\Web\Common\CsrfCounterMeasure;
use ipl\Web\Compat\CompatForm;

Expand Down Expand Up @@ -95,20 +96,23 @@ protected function assemble()
'username',
[
'label' => $this->translate('Username'),
'validators' => [new CallbackValidator(function ($value, $validator) {
$contact = Contact::on($this->db)->filter(Filter::equal('username', $value));
if ($this->contactId) {
$contact->filter(Filter::unequal('id', $this->contactId));
}

if ($contact->first() !== null) {
$validator->addMessage($this->translate('A contact with the same username already exists.'));

return false;
}

return true;
})]
'validators' => [
new StringLengthValidator(['max' => 254]),
new CallbackValidator(function ($value, $validator) {
$contact = Contact::on($this->db)->filter(Filter::equal('username', $value));
if ($this->contactId) {
$contact->filter(Filter::unequal('id', $this->contactId));
}

if ($contact->first() !== null) {
$validator->addMessage($this->translate('A contact with the same username already exists.'));

return false;
}

return true;
})
]
]
)->addElement(
'select',
Expand Down

0 comments on commit 35ecfa7

Please sign in to comment.