revbank/plugins/adduser
Juerd Waalboer f6f5d66bdc adduser: improve error message for large numeric input
Old message was not as intended:

> Name for the new account: 123123123123
> That's way too much money. Enter 'abort' to abort.

Fixed:

> Name for the new account: 123123123123
Sorry, that's too numeric to be a user name. Enter 'abort' to abort.
2024-08-28 03:35:19 +02:00

40 lines
1.1 KiB
Perl

#!perl
use List::Util qw(any);
HELP1 "adduser <name>" => "Create an account";
sub command :Tab(adduser) ($self, $cart, $command, @) {
$command eq 'adduser' or return NEXT;
if ($cart->size) {
return ABORT, "Create the account *before* scanning things.";
}
return "Name for the new account", \&username;
}
sub username($self, $cart, $name, @) {
return REJECT, "Sorry, only A-Z a-z 0-9 _ - + / ^ * [] {} are allowed."
if $name !~ /^[A-Za-z0-9_\-+\/\^*\[\]{}-]+\z/;
return REJECT, "Sorry, - + / ^ * are not allowed as the first character."
if $name =~ /^[-+*\/\^]/;
return REJECT, "Sorry, that's too numeric to be a user name."
if defined RevBank::Amount->parse_string($name);
return REJECT, "That name is not available."
if defined parse_user($name, 1);
for my $plugin (RevBank::Plugins->new) {
my $id = $plugin->id;
return REJECT, "That name would clash with the '$id' plugin."
if any sub { $_ eq $name }, $plugin->Tab('command');
}
RevBank::Users::create( $name );
return ACCEPT;
}