diff options
author | Daniel Friesel <derf@finalrewind.org> | 2021-06-13 08:48:08 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2021-06-13 08:48:08 +0200 |
commit | 1803a1723c2952723a4ec9ad67e3cd1184fcf137 (patch) | |
tree | 5d0db56f3221d04359ff57468ff1f50a0bb513cd /lib/Travelynx/Model | |
parent | bccdefbb7d3b2a92df919cea75d102f95cadf188 (diff) |
move user name validation to Users model
Diffstat (limited to 'lib/Travelynx/Model')
-rw-r--r-- | lib/Travelynx/Model/Users.pm | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/Travelynx/Model/Users.pm b/lib/Travelynx/Model/Users.pm index 8bd60f0..535b938 100644 --- a/lib/Travelynx/Model/Users.pm +++ b/lib/Travelynx/Model/Users.pm @@ -201,6 +201,32 @@ sub change_mail_with_token { return; } +sub is_name_invalid { + my ( $self, %opt ) = @_; + my $db = $opt{db} // $self->{pg}->db; + my $name = $opt{name}; + + if ( not length($name) ) { + return 'user_empty'; + } + + if ( $name !~ m{ ^ [0-9a-zA-Z_-]+ $ }x ) { + return 'user_format'; + } + + if ( + $self->user_name_exists( + db => $db, + name => $name + ) + ) + { + return 'user_collision'; + } + + return; +} + sub change_name { my ( $self, %opt ) = @_; my $db = $opt{db} // $self->{pg}->db; |