Add deluser
This commit is contained in:
parent
1d09938686
commit
6af4afc6ce
1 changed files with 49 additions and 0 deletions
49
deluser
Normal file
49
deluser
Normal file
|
@ -0,0 +1,49 @@
|
|||
#!perl
|
||||
|
||||
use List::Util qw(any);
|
||||
|
||||
HELP1 "deluser <name>" => "Delete an account";
|
||||
|
||||
my $contra = "+donations";
|
||||
|
||||
sub command :Tab(deluser) ($self, $cart, $command, @) {
|
||||
$command eq 'deluser' or return NEXT;
|
||||
|
||||
$cart->{_deluser} = 1;
|
||||
|
||||
# Ensure a transaction is triggered by adding one item to the cart.
|
||||
$cart->add(0, "Forfeit remaining balance");
|
||||
|
||||
print(
|
||||
"\n",
|
||||
">>> YOU ARE ABOUT TO FORFEIT YOUR BALANCE AND DELETE YOUR ACCOUNT! <<<\n",
|
||||
"\n",
|
||||
"Type your name to finish.\n"
|
||||
);
|
||||
|
||||
return ACCEPT;
|
||||
}
|
||||
|
||||
sub hook_checkout_prepare($class, $cart, $account, $transaction_id, @) {
|
||||
return if not defined $cart->{_deluser};
|
||||
|
||||
my $amount = RevBank::Accounts::balance($account);
|
||||
|
||||
return ABORT, "Can not delete an account with a negative balance."
|
||||
if ($amount < 0);
|
||||
|
||||
$cart
|
||||
->add(-$amount, "Forfeit remaining balance")
|
||||
->add_contra($contra, +$amount, "Delete account \$you");
|
||||
|
||||
# Not having this bare return here results in "returned an unsupported value". The returned
|
||||
# value seems to be a cart entry? Why?
|
||||
return;
|
||||
}
|
||||
|
||||
sub hook_checkout_done($class, $cart, $account, $transaction_id, @) {
|
||||
return if not defined $cart->{_deluser};
|
||||
|
||||
RevBank::Accounts::delete($account);
|
||||
print "\nAccount $account deleted.\n";
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue