Validate SIP username

Mantis: 3891
agranig/peering-route
Gerhard Jungwirth 12 years ago
parent ff16940a13
commit ccd46c145e

@ -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<Sipwise::Provisioning::check_localpart>.
=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:

@ -8,6 +8,7 @@ use HTML::FormHandler::Widget::Block::Bootstrap;
use NGCP::Panel::Field::Domain; use NGCP::Panel::Field::Domain;
use NGCP::Panel::Field::PosInteger; use NGCP::Panel::Field::PosInteger;
use NGCP::Panel::Field::Identifier;
has '+widget_wrapper' => ( default => 'Bootstrap' ); has '+widget_wrapper' => ( default => 'Bootstrap' );
has_field 'submitid' => ( type => 'Hidden' ); has_field 'submitid' => ( type => 'Hidden' );
@ -77,7 +78,7 @@ has_field 'e164.sn' => (
); );
has_field 'username' => ( has_field 'username' => (
type => 'Text', type => '+NGCP::Panel::Field::Identifier',
label => 'SIP Username', label => 'SIP Username',
required => 1, required => 1,
noupdate => 1, noupdate => 1,

@ -9,6 +9,7 @@ use HTML::FormHandler::Widget::Block::Bootstrap;
use NGCP::Panel::Field::Domain; use NGCP::Panel::Field::Domain;
use NGCP::Panel::Field::CustomerContract; use NGCP::Panel::Field::CustomerContract;
use NGCP::Panel::Field::PosInteger; use NGCP::Panel::Field::PosInteger;
use NGCP::Panel::Field::Identifier;
has '+widget_wrapper' => ( default => 'Bootstrap' ); has '+widget_wrapper' => ( default => 'Bootstrap' );
has_field 'submitid' => ( type => 'Hidden' ); has_field 'submitid' => ( type => 'Hidden' );
@ -85,7 +86,7 @@ has_field 'e164.sn' => (
); );
has_field 'username' => ( has_field 'username' => (
type => 'Text', type => '+NGCP::Panel::Field::Identifier',
label => 'SIP Username', label => 'SIP Username',
required => 1, required => 1,
noupdate => 1, noupdate => 1,

Loading…
Cancel
Save