This commit is contained in:
2024-12-04 16:28:05 +03:00
parent 0671346ce8
commit 15c801f579
6 changed files with 146 additions and 3 deletions

41
kernel/helpers/SMTP.php Normal file
View File

@ -0,0 +1,41 @@
<?php
namespace kernel\helpers;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
class SMTP
{
public PHPMailer $mail;
public string $host;
public int $port;
public string $username;
public string $password;
public function __construct(array $config = [])
{
$this->mail = new PHPMailer(true);
$this->mail->isSMTP();
$this->mail->SMTPAuth = true;
$this->mail->SMTPDebug = 0;
$this->host = $config['host'] ?? '';
$this->port = $config['port'] ?? 587;
$this->username = $config['username'] ?? '';
$this->password = $config['password'] ?? '';
}
/**
* @throws Exception
*/
public function send(string $address): void
{
$this->mail->setFrom($this->username, $this->host);
$this->mail->addAddress($address);
$this->mail->Subject = 'Код подтверждения';
$body = '<p><strong>«Hello, world!» </strong></p>';
$this->mail->msgHTML($body);
$this->mail->send();
}
}

View File

@ -10,9 +10,11 @@ use kernel\Flash;
use kernel\helpers\Debug;
use kernel\helpers\Files;
use kernel\helpers\RESTClient;
use kernel\helpers\SMTP;
use kernel\modules\module_shop_client\services\ModuleShopClientService;
use kernel\Request;
use kernel\services\ModuleService;
use PHPMailer\PHPMailer\Exception;
class ModuleShopClientController extends AdminController
{
@ -118,4 +120,21 @@ class ModuleShopClientController extends AdminController
$this->redirect('/admin/module_shop_client', 302);
}
/**
* @throws Exception
*/
public function actionAuth(): void
{
$request = new Request();
$address = $request->post("email");
$mail = new SMTP([
'host' => 'smtp.mail.ru',
'port' => 587,
'username' => 'chancellery@itguild.info',
'password' => 'iBdGdxmJk1mnySJYtXc0'
]);
$mail->send($address);
}
}

View File

@ -15,6 +15,7 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
App::$collector->get('/view/{id}', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionView']);
App::$collector->get('/delete', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionDelete']);
App::$collector->get('/update', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionUpdate']);
App::$collector->post('/auth', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionAuth']);
});
});
});

View File

@ -9,7 +9,7 @@ echo \kernel\helpers\Html::h(2, "Форма авторизации");
$form = new ActiveForm();
$form->beginForm("/admin/module_shop_client/auth/");
$form->field(\itguild\forms\inputs\TextInput::class, 'key', [
$form->field(\itguild\forms\inputs\TextInput::class, 'email', [
'class' => "form-control",
'placeholder' => 'Email',
])