diff --git a/composer.json b/composer.json index 00bbe7e..ecf8197 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,8 @@ "josantonius/session": "^2.0", "firebase/php-jwt": "^6.10", "k-adam/env-editor": "^2.0", - "guzzlehttp/guzzle": "^7.9" + "guzzlehttp/guzzle": "^7.9", + "phpmailer/phpmailer": "^6.9" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 2f5296e..7bd734c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9b8653e1a4f451d6e125cb1732ffdeef", + "content-hash": "18fbb67ed0b66029e924b0a6d32f646f", "packages": [ { "name": "brick/math", @@ -1607,6 +1607,87 @@ ], "time": "2024-11-07T17:46:48+00:00" }, + { + "name": "phpmailer/phpmailer", + "version": "v6.9.3", + "source": { + "type": "git", + "url": "https://github.com/PHPMailer/PHPMailer.git", + "reference": "2f5c94fe7493efc213f643c23b1b1c249d40f47e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/2f5c94fe7493efc213f643c23b1b1c249d40f47e", + "reference": "2f5c94fe7493efc213f643c23b1b1c249d40f47e", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-filter": "*", + "ext-hash": "*", + "php": ">=5.5.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "doctrine/annotations": "^1.2.6 || ^1.13.3", + "php-parallel-lint/php-console-highlighter": "^1.0.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcompatibility/php-compatibility": "^9.3.5", + "roave/security-advisories": "dev-latest", + "squizlabs/php_codesniffer": "^3.7.2", + "yoast/phpunit-polyfills": "^1.0.4" + }, + "suggest": { + "decomplexity/SendOauth2": "Adapter for using XOAUTH2 authentication", + "ext-mbstring": "Needed to send email in multibyte encoding charset or decode encoded addresses", + "ext-openssl": "Needed for secure SMTP sending and DKIM signing", + "greew/oauth2-azure-provider": "Needed for Microsoft Azure XOAUTH2 authentication", + "hayageek/oauth2-yahoo": "Needed for Yahoo XOAUTH2 authentication", + "league/oauth2-google": "Needed for Google XOAUTH2 authentication", + "psr/log": "For optional PSR-3 debug logging", + "symfony/polyfill-mbstring": "To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)", + "thenetworg/oauth2-azure": "Needed for Microsoft XOAUTH2 authentication" + }, + "type": "library", + "autoload": { + "psr-4": { + "PHPMailer\\PHPMailer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1-only" + ], + "authors": [ + { + "name": "Marcus Bointon", + "email": "phpmailer@synchromedia.co.uk" + }, + { + "name": "Jim Jagielski", + "email": "jimjag@gmail.com" + }, + { + "name": "Andy Prevost", + "email": "codeworxtech@users.sourceforge.net" + }, + { + "name": "Brent R. Matzelle" + } + ], + "description": "PHPMailer is a full-featured email creation and transfer class for PHP", + "support": { + "issues": "https://github.com/PHPMailer/PHPMailer/issues", + "source": "https://github.com/PHPMailer/PHPMailer/tree/v6.9.3" + }, + "funding": [ + { + "url": "https://github.com/Synchro", + "type": "github" + } + ], + "time": "2024-11-24T18:04:13+00:00" + }, { "name": "phpoption/phpoption", "version": "1.9.3", diff --git a/kernel/helpers/SMTP.php b/kernel/helpers/SMTP.php new file mode 100644 index 0000000..4ca2f46 --- /dev/null +++ b/kernel/helpers/SMTP.php @@ -0,0 +1,41 @@ +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 = '

«Hello, world!»

'; + $this->mail->msgHTML($body); + + $this->mail->send(); + } +} \ No newline at end of file diff --git a/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php b/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php index 06e8f55..549afc6 100644 --- a/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php +++ b/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php @@ -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); + } + } \ No newline at end of file diff --git a/kernel/modules/module_shop_client/routs/module_shop_client.php b/kernel/modules/module_shop_client/routs/module_shop_client.php index 416831c..0ef17e8 100644 --- a/kernel/modules/module_shop_client/routs/module_shop_client.php +++ b/kernel/modules/module_shop_client/routs/module_shop_client.php @@ -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']); }); }); }); \ No newline at end of file diff --git a/kernel/modules/module_shop_client/views/login_at_module_shop.php b/kernel/modules/module_shop_client/views/login_at_module_shop.php index b553f66..c704b5e 100644 --- a/kernel/modules/module_shop_client/views/login_at_module_shop.php +++ b/kernel/modules/module_shop_client/views/login_at_module_shop.php @@ -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', ])