v6.1.1: Feature: warning messages for invalid accounts
This commit is contained in:
parent
33b08f99ea
commit
f2d09b4da5
5 changed files with 36 additions and 19 deletions
|
@ -13,7 +13,20 @@ my $filename = "revbank.accounts";
|
|||
|
||||
sub _read() {
|
||||
my @users;
|
||||
/\S/ and push @users, [split " "] for slurp $filename;
|
||||
for my $line (slurp $filename) {
|
||||
$line =~ /\S/ or next;
|
||||
# Not using RevBank::Prompt::split_input to keep parsing by external
|
||||
# scripts simple, since so many such scripts exist.
|
||||
|
||||
my @split = split " ", $line;
|
||||
|
||||
if ($split[1] =~ /^!/) {
|
||||
# Special case: use rest of the line (see POD).
|
||||
@split = split " ", $line, 2;
|
||||
}
|
||||
|
||||
push @users, \@split;
|
||||
}
|
||||
|
||||
my %users;
|
||||
for (@users) {
|
||||
|
@ -103,24 +116,31 @@ sub parse_user($username, $allow_invalid = 0) {
|
|||
|
||||
my $users = _read();
|
||||
|
||||
exists $users->{ lc $username }
|
||||
or return undef;
|
||||
my $user = $users->{ lc $username } or return undef;
|
||||
|
||||
if ($user->[1] =~ /^!(.*)/) {
|
||||
warn "$username: Invalid account ($1).\n";
|
||||
}
|
||||
|
||||
$allow_invalid or defined balance($username)
|
||||
or return undef;
|
||||
|
||||
return $users->{ lc $username }->[0];
|
||||
return $user->[0];
|
||||
}
|
||||
|
||||
sub assert_user($username) {
|
||||
my $users = _read();
|
||||
|
||||
return exists $users->{ lc $username }
|
||||
? $users->{ lc $username }->[0]
|
||||
: (is_hidden($username)
|
||||
? create($username)
|
||||
: Carp::croak("No such user ($username)")
|
||||
);
|
||||
my $user = $users->{ lc $username };
|
||||
|
||||
if ($user) {
|
||||
Carp::croak("Account $username can't be used") if not balance $username;
|
||||
return $user->[0];
|
||||
}
|
||||
|
||||
return create $username if is_hidden $username;
|
||||
|
||||
Carp::croak("No such user ($username)")
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -80,6 +80,10 @@ Every account name must be unique. A file with duplicate names is not valid and
|
|||
|
||||
The account balance is a number with two decimal digits. Positive numbers may have a C<+> sign. Negative number have a C<-> sign.
|
||||
|
||||
If the value in this field is not a valid number, the account is treated as non-existent by most of RevBank, while still being unavailable for C<adduser>.
|
||||
|
||||
If the value begins with a C<!> character, the I<rest of the line> is taken as a description of why the account name is not available and printed as a warning when the account name is used.
|
||||
|
||||
=item * Last use timestamp
|
||||
|
||||
Local datetime of the last update of this account.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue