From ccd46c145e4ec98c7d4612d60ed5c30e802c75a5 Mon Sep 17 00:00:00 2001 From: Gerhard Jungwirth Date: Mon, 23 Sep 2013 13:13:52 +0200 Subject: [PATCH] Validate SIP username Mantis: 3891 --- lib/NGCP/Panel/Field/Identifier.pm | 47 ++++++++++++++++++++++ lib/NGCP/Panel/Form/Customer/Subscriber.pm | 3 +- lib/NGCP/Panel/Form/Subscriber.pm | 3 +- 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 lib/NGCP/Panel/Field/Identifier.pm diff --git a/lib/NGCP/Panel/Field/Identifier.pm b/lib/NGCP/Panel/Field/Identifier.pm new file mode 100644 index 0000000000..3cda1e447b --- /dev/null +++ b/lib/NGCP/Panel/Field/Identifier.pm @@ -0,0 +1,47 @@ +package NGCP::Panel::Field::Identifier; +use HTML::FormHandler::Moose; +extends 'HTML::FormHandler::Field::Text'; + +sub validate { + my ( $self ) = @_; + return $self->add_error("Cannot contain spaces.") + if ( $self->value =~ m/ / ); + return $self->add_error("Invalid identifier (dots not allowed at this position).") + if ( $self->value =~ m/^\./ or + $self->value =~ m/\.$/ or + $self->value =~ m/\.\./ ); + return $self->add_error("Contains invalid symbols.") + unless ( $self->value =~ m/^[[:lower:][:digit:]=+,;_.~'()-]+$/ ); + return 0; +} + +1; + +=head1 NAME + +NGCP::Panel::Field::Identifier + +=head1 DESCRIPTION + +This accepts a value which contains any number of alphanumeric characters. +Its main use is for SIP usernames of subscribers. + +Alphanumeric lowercase characters plus the following symbols +are allowed: C<=+,;_.~'()-> Spaces are not allowed. Dots can not stand at +the beginning or end of the identifier and two or more dots can not be in +a row. + +This definition has been taken from L. + +=head1 AUTHOR + +Gerhard Jungwirth + +=head1 LICENSE + +This library is free software. You can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +# vim: set tabstop=4 expandtab: diff --git a/lib/NGCP/Panel/Form/Customer/Subscriber.pm b/lib/NGCP/Panel/Form/Customer/Subscriber.pm index 6f74bdc6ea..2cdfa34fbe 100644 --- a/lib/NGCP/Panel/Form/Customer/Subscriber.pm +++ b/lib/NGCP/Panel/Form/Customer/Subscriber.pm @@ -8,6 +8,7 @@ use HTML::FormHandler::Widget::Block::Bootstrap; use NGCP::Panel::Field::Domain; use NGCP::Panel::Field::PosInteger; +use NGCP::Panel::Field::Identifier; has '+widget_wrapper' => ( default => 'Bootstrap' ); has_field 'submitid' => ( type => 'Hidden' ); @@ -77,7 +78,7 @@ has_field 'e164.sn' => ( ); has_field 'username' => ( - type => 'Text', + type => '+NGCP::Panel::Field::Identifier', label => 'SIP Username', required => 1, noupdate => 1, diff --git a/lib/NGCP/Panel/Form/Subscriber.pm b/lib/NGCP/Panel/Form/Subscriber.pm index 514c32f378..8e3cec5db9 100644 --- a/lib/NGCP/Panel/Form/Subscriber.pm +++ b/lib/NGCP/Panel/Form/Subscriber.pm @@ -9,6 +9,7 @@ use HTML::FormHandler::Widget::Block::Bootstrap; use NGCP::Panel::Field::Domain; use NGCP::Panel::Field::CustomerContract; use NGCP::Panel::Field::PosInteger; +use NGCP::Panel::Field::Identifier; has '+widget_wrapper' => ( default => 'Bootstrap' ); has_field 'submitid' => ( type => 'Hidden' ); @@ -85,7 +86,7 @@ has_field 'e164.sn' => ( ); has_field 'username' => ( - type => 'Text', + type => '+NGCP::Panel::Field::Identifier', label => 'SIP Username', required => 1, noupdate => 1,