some
This commit is contained in:
		| @@ -1,3 +1,5 @@ | |||||||
|  | APP_NAME="It Guild Micro Framework" | ||||||
|  |  | ||||||
| DB_HOST=localhost | DB_HOST=localhost | ||||||
| DB_USER=user | DB_USER=user | ||||||
| DB_DRIVER=mysql | DB_DRIVER=mysql | ||||||
| @@ -10,6 +12,11 @@ DB_PREFIX='' | |||||||
| VIEWS_PATH=/views | VIEWS_PATH=/views | ||||||
| VIEWS_CACHE_PATH=/views_cache | VIEWS_CACHE_PATH=/views_cache | ||||||
|  |  | ||||||
|  | MAIL_SMTP_HOST=smtp.mail.ru | ||||||
|  | MAIL_SMTP_PORT=587 | ||||||
|  | MAIL_SMTP_USERNAME=username@mail.ru | ||||||
|  | MAIL_SMTP_PASSWORD=somepassword | ||||||
|  |  | ||||||
| MODULE_SHOP_URL='http://igfs.loc' | MODULE_SHOP_URL='http://igfs.loc' | ||||||
| MODULE_SHOP_TOKEN='your token' | MODULE_SHOP_TOKEN='your token' | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,6 +1,7 @@ | |||||||
| <?php | <?php | ||||||
|  |  | ||||||
| $secure_config = [ | $secure_config = [ | ||||||
|  |     'web_auth_type' => 'login_password', // login_password, email_code | ||||||
|     'token_type' => 'JWT', // random_bytes, md5, crypt, hash, JWT |     'token_type' => 'JWT', // random_bytes, md5, crypt, hash, JWT | ||||||
|     'token_expired_time' => "+30 days", // +1 day |     'token_expired_time' => "+30 days", // +1 day | ||||||
| ]; | ]; | ||||||
|   | |||||||
							
								
								
									
										50
									
								
								kernel/Mailing.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								kernel/Mailing.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,50 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace kernel; | ||||||
|  |  | ||||||
|  | use kernel\helpers\Debug; | ||||||
|  | use kernel\helpers\SMTP; | ||||||
|  | use PHPMailer\PHPMailer\Exception; | ||||||
|  |  | ||||||
|  | class Mailing | ||||||
|  | { | ||||||
|  |     protected SMTP $SMTP; | ||||||
|  |  | ||||||
|  |     protected CgView $cgView; | ||||||
|  |     protected array $data; | ||||||
|  |  | ||||||
|  |     public function __construct(array $data = []) | ||||||
|  |     { | ||||||
|  |         $this->cgView = new CgView(); | ||||||
|  |         $this->cgView->viewPath = KERNEL_DIR . "/views/mailing/"; | ||||||
|  |  | ||||||
|  |         $this->data = $data; | ||||||
|  |  | ||||||
|  |         $this->SMTP = new SMTP(); | ||||||
|  |  | ||||||
|  |         $this->init(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @throws Exception | ||||||
|  |      */ | ||||||
|  |     public function send_html(string $tpl, array $tplParams, array $mailParams): ?false | ||||||
|  |     { | ||||||
|  |         $mailParams['body'] = $this->cgView->fetch($tpl, $tplParams); | ||||||
|  |         return $this->SMTP->send_html($mailParams); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public function run() | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static function create(array $data = []): static | ||||||
|  |     { | ||||||
|  |         return new static($data); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     protected function init() | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -8,28 +8,31 @@ use PHPMailer\PHPMailer\PHPMailer; | |||||||
| class SMTP | class SMTP | ||||||
| { | { | ||||||
|     public PHPMailer $mail; |     public PHPMailer $mail; | ||||||
|     public function __construct(array $config = []) |     public function __construct() | ||||||
|     { |     { | ||||||
|         $this->mail = new PHPMailer(true); |         $this->mail = new PHPMailer(true); | ||||||
|         $this->mail->CharSet = 'UTF-8'; |         $this->mail->CharSet = 'UTF-8'; | ||||||
|         $this->mail->isSMTP(); |         $this->mail->isSMTP(); | ||||||
|         $this->mail->SMTPAuth = true; |         $this->mail->SMTPAuth = true; | ||||||
|         $this->mail->SMTPDebug = 0; |         $this->mail->SMTPDebug = 0; | ||||||
|         $this->mail->Host = $config['host'] ?? ''; |         $this->mail->Host = $_ENV['MAIL_SMTP_HOST']; | ||||||
|         $this->mail->Port = $config['port'] ?? 587; |         $this->mail->Port = $_ENV['MAIL_SMTP_PORT']; | ||||||
|         $this->mail->Username = $config['username'] ?? ''; |         $this->mail->Username = $_ENV['MAIL_SMTP_USERNAME']; | ||||||
|         $this->mail->Password = $config['password'] ?? ''; |         $this->mail->Password = $_ENV['MAIL_SMTP_PASSWORD']; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @throws Exception |      * @throws Exception | ||||||
|      */ |      */ | ||||||
|     public function send(string $address): void |     public function send_html(array $params) | ||||||
|     { |     { | ||||||
|         $this->mail->setFrom($this->mail->Username, $this->mail->Host); |         if (!isset($params['address'])){ | ||||||
|         $this->mail->addAddress($address); |             return false; | ||||||
|         $this->mail->Subject = 'Код подтверждения'; |         } | ||||||
|         $body = '<p><strong>«Hello, world!» </strong></p>'; |         $this->mail->setFrom($this->mail->Username, $params['from_name'] ?? $this->mail->Host); | ||||||
|  |         $this->mail->addAddress($params['address']); | ||||||
|  |         $this->mail->Subject = $params['subject'] ?? 'Без темы'; | ||||||
|  |         $body = $params['body'] ?? 'Нет информации'; | ||||||
|         $this->mail->msgHTML($body); |         $this->mail->msgHTML($body); | ||||||
|  |  | ||||||
|         $this->mail->send(); |         $this->mail->send(); | ||||||
|   | |||||||
| @@ -11,6 +11,7 @@ use kernel\helpers\Debug; | |||||||
| use kernel\helpers\Files; | use kernel\helpers\Files; | ||||||
| use kernel\helpers\RESTClient; | use kernel\helpers\RESTClient; | ||||||
| use kernel\helpers\SMTP; | use kernel\helpers\SMTP; | ||||||
|  | use kernel\Mailing; | ||||||
| use kernel\modules\module_shop_client\services\ModuleShopClientService; | use kernel\modules\module_shop_client\services\ModuleShopClientService; | ||||||
| use kernel\Request; | use kernel\Request; | ||||||
| use kernel\services\ModuleService; | use kernel\services\ModuleService; | ||||||
| @@ -127,14 +128,13 @@ class ModuleShopClientController extends AdminController | |||||||
|     { |     { | ||||||
|         $request = new Request(); |         $request = new Request(); | ||||||
|         $address = $request->post("email"); |         $address = $request->post("email"); | ||||||
|         $mail = new SMTP([ |  | ||||||
|             'host' => 'smtp.mail.ru', |         $mailing = new Mailing(); | ||||||
|             'port' => 587, |         $mailing->send_html("login_by_code.php", ['code' => mt_rand(100000, 999999)], [ | ||||||
|             'username' => 'chancellery@itguild.info', |             'address' => $address, | ||||||
|             'password' => 'iBdGdxmJk1mnySJYtXc0' |             'subject' => "Код авторизации", | ||||||
|  |             "from_name" => $_ENV['APP_NAME'] | ||||||
|         ]); |         ]); | ||||||
|  |  | ||||||
|         $mail->send($address); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
							
								
								
									
										12
									
								
								kernel/views/mailing/login_by_code.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								kernel/views/mailing/login_by_code.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | |||||||
|  | <?php | ||||||
|  | /** | ||||||
|  |  * @var int $code | ||||||
|  |  */ | ||||||
|  | ?> | ||||||
|  |  | ||||||
|  | <p> | ||||||
|  |     Код подтверждения: <?= $code ?> | ||||||
|  | </p> | ||||||
|  | <p> | ||||||
|  |     Если вы не запрашивали код, проигнорируйте данное письмо. | ||||||
|  | </p> | ||||||
		Reference in New Issue
	
	Block a user