8
0
Fork 0

Add deluser

This commit is contained in:
polyfloyd 2025-06-19 15:22:53 +02:00
parent 1d09938686
commit 6af4afc6ce

49
deluser Normal file
View 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";
}