40 lines
1,002 B
Perl
40 lines
1,002 B
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, whitespace is not allowed."
|
|
if $name =~ /\s/;
|
|
|
|
return REJECT, "Sorry, invalid first character."
|
|
if $name =~ /^[-+*]/;
|
|
|
|
return REJECT, "That's too numeric to be a user name."
|
|
if defined parse_amount($name);
|
|
|
|
return REJECT, "That name already exists."
|
|
if defined parse_user($name);
|
|
|
|
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;
|
|
}
|