This repository has been archived on 2023-07-28. You can view files and clone it, but cannot push or open issues or pull requests.
prosody_web_admin_rest/bin/UsersAwaitingVerificationCleanUpCronJob.php
Alexander Schäferdiek 74a2bae39f - Refactor
- Bugfixes
- Add possibility to determine LogLevel and logger name in environment
2016-07-11 22:29:44 +02:00

50 lines
No EOL
1.8 KiB
PHP

<?php
use Carbon\Carbon;
require_once __DIR__ . DIRECTORY_SEPARATOR . '../vendor/autoload.php';
/*
* Bootstrap environment, configs and database
*/
$env = BootstrapHelper::bootEnvironment();
$config = Config::$CONFIG;
$db = BootstrapHelper::bootDatabase();
$translator = BootstrapHelper::bootTranslator();
$logger = BootstrapHelper::bootLogger();
// handle all users awaiting verification and notify them
$users = UserAwaitingVerification::all();
$now = Carbon::now();
$now->modify('+' . getenv('verification_cleanup_time'));
foreach ($users as $user) {
$createdAt = DateHelper::convertToCarbon($user->created_at);
if (!empty($createdAt)) {
if ($createdAt->lt($now)) {
$mailer = new PHPMailer();
$mailer->CharSet = 'UTF-8';
$mailer->ContentType = 'text/plain';
$mailer->isSMTP();
$mailer->SMTPSecure = getenv('mail_secure');
$mailer->SMTPAuth = getenv('mail_auth');
$mailer->Host = getenv('mail_host');
$mailer->Port = getenv('mail_port');
$mailer->Username = getenv('mail_username');
$mailer->Password = getenv('mail_password');
$mailer->From = getenv('mail_from');
$mailer->FromName = getenv('mail_from_name');
$mailer->addAddress($user->email);
$mailer->Subject = $translator->trans('cleanup.mail.subject', ['%server%' => getenv('site_xmpp_server_displayname')]);
$mailer->Body = $translator->trans('cleanup.mail.body', ['%username%' => $user->username, '%server%' => getenv('site_xmpp_server_displayname')]);
$mailer->send();
$logger->info($translator->trans('log.verification.cleanup', ['%username%' => $user->username]));
$user->delete();
}
}
}