[ADDED] Validate all users option
This commit is contained in:
parent
54a1452d45
commit
1550553a6d
37
scripts/validate_users.php
Normal file → Executable file
37
scripts/validate_users.php
Normal file → Executable file
@ -7,8 +7,10 @@
|
|||||||
|
|
||||||
// Include all settings and classes
|
// Include all settings and classes
|
||||||
require_once('shared.inc.php');
|
require_once('shared.inc.php');
|
||||||
|
|
||||||
$timeLimitInDays = 90;
|
$options = getopt("d:a");
|
||||||
|
isset($options['d']) ? $timeLimitInDays = (int)$options['d'] : $timeLimitInDays = 90;
|
||||||
|
isset($options['a']) ? $allUsers = true : $allUsers = false;
|
||||||
$notifyStaleUsers = False;
|
$notifyStaleUsers = False;
|
||||||
|
|
||||||
// Fetch all users
|
// Fetch all users
|
||||||
@ -19,9 +21,8 @@
|
|||||||
|
|
||||||
$currentTime = time();
|
$currentTime = time();
|
||||||
$totalSavings = 0;
|
$totalSavings = 0;
|
||||||
|
|
||||||
foreach ($users as $user)
|
foreach ($users as $user) {
|
||||||
{
|
|
||||||
$id = $user['id'];
|
$id = $user['id'];
|
||||||
$isAdmin = $user['is_admin'];
|
$isAdmin = $user['is_admin'];
|
||||||
$username = $user['username'];
|
$username = $user['username'];
|
||||||
@ -29,32 +30,32 @@
|
|||||||
$lastLogin = $user['last_login'];
|
$lastLogin = $user['last_login'];
|
||||||
$coinAddress = $user['coin_address'];
|
$coinAddress = $user['coin_address'];
|
||||||
$mailAddress = $user['email'];
|
$mailAddress = $user['email'];
|
||||||
|
|
||||||
$everLoggedIn = !empty($lastLogin);
|
$everLoggedIn = !empty($lastLogin);
|
||||||
$timeDelta = $currentTime - $lastLogin;
|
$timeDelta = $currentTime - $lastLogin;
|
||||||
$lastLoginInDays = round(abs($timeDelta)/60/60/24, 0);
|
$lastLoginInDays = round(abs($timeDelta)/60/60/24, 0);
|
||||||
|
|
||||||
if($lastLoginInDays < $timeLimitInDays)
|
if(!$allUsers && $lastLoginInDays < $timeLimitInDays)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// get transactions summary for the user
|
// get transactions summary for the user
|
||||||
$summary = $transaction->getTransactionSummary($id);
|
$summary = $transaction->getTransactionSummary($id);
|
||||||
$transactions_exists = !empty($summary);
|
$transactions_exists = !empty($summary);
|
||||||
|
|
||||||
// get balances
|
// get balances
|
||||||
$balances = $transaction->getBalance($id);
|
$balances = $transaction->getBalance($id);
|
||||||
$confirmedBalance = $balances['confirmed'];
|
$confirmedBalance = $balances['confirmed'];
|
||||||
$totalSavings += $confirmedBalance;
|
$totalSavings += $confirmedBalance;
|
||||||
|
|
||||||
$staleAccount = $everLoggedIn == false && $transactions_exists == false;
|
$staleAccount = $everLoggedIn == false && $transactions_exists == false;
|
||||||
|
|
||||||
if ($notifyStaleUsers) {
|
if ($notifyStaleUsers) {
|
||||||
$subject = "Account at " . $setting->getValue('website_name') . "!";
|
$subject = "Account at " . $setting->getValue('website_name') . "!";
|
||||||
$body = "Hi ". $username .",\n\nWe have discovered \
|
$body = "Hi ". $username .",\n\nWe have discovered \
|
||||||
your username as inactive. Your last login is older than 90 days, \
|
your username as inactive. Your last login is older than 90 days, \
|
||||||
please reactivate your Account if you want to mine again, \
|
please reactivate your Account if you want to mine again, \
|
||||||
else it will be deleted in 30 days.\n\nBalance left: ". $confirmedBalance . " " . $config['currency'] . "\n\nCheers";
|
else it will be deleted in 30 days.\n\nBalance left: ". $confirmedBalance . " " . $config['currency'] . "\n\nCheers";
|
||||||
|
|
||||||
if (mail($mailAddress, $subject, $body)) {
|
if (mail($mailAddress, $subject, $body)) {
|
||||||
echo("Email successfully sent!");
|
echo("Email successfully sent!");
|
||||||
} else {
|
} else {
|
||||||
@ -62,11 +63,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf($mask, $id, $username, $mailAddress,
|
printf($mask, $id, $username, $mailAddress,
|
||||||
$loggedIp, strftime("%Y-%m-%d %H:%M:%S", $lastLogin), $lastLoginInDays, $everLoggedIn ? 'yes' : 'no',
|
$loggedIp, strftime("%Y-%m-%d %H:%M:%S", $lastLogin), $lastLoginInDays, $everLoggedIn ? 'yes' : 'no',
|
||||||
$transactions_exists ? 'yes' : 'no', round($confirmedBalance,8),
|
$transactions_exists ? 'yes' : 'no', round($confirmedBalance,8),
|
||||||
$staleAccount ? 'yes' : 'no' );
|
$staleAccount ? 'yes' : 'no' );
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Total balance of stale accounts: $totalSavings" . PHP_EOL;
|
echo "Total balance of stale accounts: $totalSavings" . PHP_EOL;
|
||||||
?>
|
?>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user