mirror of
https://github.com/elyby/accounts.git
synced 2024-11-30 02:32:26 +05:30
Обновлена версия Email Renderer
Добавлен компонент для настройки Email Renderer Добавлен роут в nginx для отображения картинок из Email Renderer
This commit is contained in:
parent
97e8e0d48e
commit
b67a1879fe
@ -12,7 +12,6 @@ use common\models\EmailActivation;
|
|||||||
use common\models\UsernameHistory;
|
use common\models\UsernameHistory;
|
||||||
use common\validators\LanguageValidator;
|
use common\validators\LanguageValidator;
|
||||||
use common\validators\PasswordValidate;
|
use common\validators\PasswordValidate;
|
||||||
use Ely\Email\Renderer;
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Ramsey\Uuid\Uuid;
|
use Ramsey\Uuid\Uuid;
|
||||||
use Yii;
|
use Yii;
|
||||||
@ -141,7 +140,7 @@ class RegistrationForm extends ApiForm {
|
|||||||
throw new InvalidConfigException('Please specify fromEmail app in app params');
|
throw new InvalidConfigException('Please specify fromEmail app in app params');
|
||||||
}
|
}
|
||||||
|
|
||||||
$htmlBody = (new Renderer())->getTemplate('register')
|
$htmlBody = Yii::$app->emailRenderer->getTemplate('register')
|
||||||
->setLocale($account->lang)
|
->setLocale($account->lang)
|
||||||
->setParams([
|
->setParams([
|
||||||
'username' => $account->username,
|
'username' => $account->username,
|
||||||
|
@ -20,6 +20,7 @@ class Yii extends \yii\BaseYii {
|
|||||||
* @property \yii\redis\Connection $redis
|
* @property \yii\redis\Connection $redis
|
||||||
* @property \common\components\RabbitMQ\Component $amqp
|
* @property \common\components\RabbitMQ\Component $amqp
|
||||||
* @property \GuzzleHttp\Client $guzzle
|
* @property \GuzzleHttp\Client $guzzle
|
||||||
|
* @property \common\components\EmailRenderer $emailRenderer
|
||||||
*/
|
*/
|
||||||
abstract class BaseApplication extends yii\base\Application {
|
abstract class BaseApplication extends yii\base\Application {
|
||||||
}
|
}
|
||||||
|
71
common/components/EmailRenderer.php
Normal file
71
common/components/EmailRenderer.php
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
namespace common\components;
|
||||||
|
|
||||||
|
use Ely\Email\Renderer;
|
||||||
|
use Ely\Email\TemplateBuilder;
|
||||||
|
use Yii;
|
||||||
|
use yii\base\Component;
|
||||||
|
use yii\base\InvalidConfigException;
|
||||||
|
|
||||||
|
class EmailRenderer extends Component {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string базовый путь после хоста. Должен начинаться слешем и заканчиваться без него.
|
||||||
|
* Например "/email-images"
|
||||||
|
*/
|
||||||
|
public $basePath = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Renderer
|
||||||
|
*/
|
||||||
|
private $renderer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_baseDomain;
|
||||||
|
|
||||||
|
public function __construct(array $config = []) {
|
||||||
|
parent::__construct($config);
|
||||||
|
|
||||||
|
if ($this->_baseDomain === null) {
|
||||||
|
$this->_baseDomain = Yii::$app->request->getHostInfo();
|
||||||
|
if ($this->_baseDomain === null) {
|
||||||
|
throw new InvalidConfigException('Cannot automatically obtain base domain');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->renderer = new Renderer($this->buildBasePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBaseDomain(string $baseDomain) {
|
||||||
|
$this->_baseDomain = $baseDomain;
|
||||||
|
$this->renderer->setBaseDomain($this->buildBasePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBaseDomain() : string {
|
||||||
|
return $this->_baseDomain;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $templateName
|
||||||
|
* @return TemplateBuilder
|
||||||
|
*/
|
||||||
|
public function getTemplate(string $templateName) : TemplateBuilder {
|
||||||
|
return $this->renderer->getTemplate($templateName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param TemplateBuilder $template
|
||||||
|
* @throws \Ely\Email\RendererException
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function render(TemplateBuilder $template) : string {
|
||||||
|
return $this->renderer->render($template);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildBasePath() : string {
|
||||||
|
return $this->_baseDomain . $this->basePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -41,6 +41,10 @@ return [
|
|||||||
'guzzle' => [
|
'guzzle' => [
|
||||||
'class' => GuzzleHttp\Client::class,
|
'class' => GuzzleHttp\Client::class,
|
||||||
],
|
],
|
||||||
|
'emailRenderer' => [
|
||||||
|
'class' => common\components\EmailRenderer::class,
|
||||||
|
'basePath' => '/images/emails',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'aliases' => [
|
'aliases' => [
|
||||||
'@bower' => '@vendor/bower-asset',
|
'@bower' => '@vendor/bower-asset',
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
"ely/yii2-tempmail-validator": "~1.0.0",
|
"ely/yii2-tempmail-validator": "~1.0.0",
|
||||||
"emarref/jwt": "~1.0.3",
|
"emarref/jwt": "~1.0.3",
|
||||||
"ely/amqp-controller": "^0.1.0",
|
"ely/amqp-controller": "^0.1.0",
|
||||||
"ely/email-renderer": "dev-master#4a751652b5a325d44d3bc79a464dda9232486cbc"
|
"ely/email-renderer": "dev-master#8c975737c6681af4bbd161ff27fe6326d39ba9d6"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"yiisoft/yii2-codeception": "*",
|
"yiisoft/yii2-codeception": "*",
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
|
|
||||||
set $root_path '/var/www/html';
|
|
||||||
set $api_path '${root_path}/api/web';
|
|
||||||
set $frontend_path '${root_path}/frontend/dist';
|
|
||||||
|
|
||||||
root $root_path;
|
root $root_path;
|
||||||
charset utf-8;
|
charset utf-8;
|
||||||
client_max_body_size 2M;
|
index index.html;
|
||||||
etag on;
|
etag on;
|
||||||
|
|
||||||
|
# Это можно раскоментить для целей отладки
|
||||||
|
# rewrite_log on;
|
||||||
|
# error_log /var/log/nginx/error.log debug;
|
||||||
|
|
||||||
|
set $root_path '/var/www/html';
|
||||||
|
set $frontend_path '${root_path}/frontend/dist';
|
||||||
|
|
||||||
set $request_url $request_uri;
|
set $request_url $request_uri;
|
||||||
set $host_with_uri '${host}${request_uri}';
|
set $host_with_uri '${host}${request_uri}';
|
||||||
|
|
||||||
rewrite_log on;
|
|
||||||
error_log /var/log/nginx/error.log debug;
|
|
||||||
|
|
||||||
if ($host_with_uri ~ '^${AUTHSERVER_HOST}/auth') {
|
if ($host_with_uri ~ '^${AUTHSERVER_HOST}/auth') {
|
||||||
set $request_url '/api/authserver${request_uri}';
|
set $request_url '/api/authserver${request_uri}';
|
||||||
rewrite ^/auth /api/authserver$uri last;
|
rewrite ^/auth /api/authserver$uri last;
|
||||||
@ -33,7 +33,6 @@ server {
|
|||||||
|
|
||||||
location / {
|
location / {
|
||||||
alias $frontend_path;
|
alias $frontend_path;
|
||||||
index index.html;
|
|
||||||
try_files $uri /index.html =404;
|
try_files $uri /index.html =404;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,9 +56,20 @@ server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Раздача статики для frontend с указанием max-кэша. Сброс будет по #hash после ребилда webpackом
|
# Раздача статики для frontend с указанием max-кэша. Сброс будет по #hash после ребилда webpackом
|
||||||
location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|json|css|zip|rar|eot|ttf|woff|ico) {
|
location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|json|css|zip|rar|eot|ttf|woff|ico)$ {
|
||||||
root $frontend_path;
|
root $frontend_path;
|
||||||
expires max;
|
expires max;
|
||||||
|
etag off;
|
||||||
access_log off;
|
access_log off;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Запросы к статике для email, их нужно запустить внутрь vendor
|
||||||
|
location ^~ /images/emails/assets {
|
||||||
|
rewrite ^/images/emails/assets/(.+)$ /vendor/ely/emails-renderer/dist/assets/$1 last;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ^~ /vendor/ely/emails-renderer/dist/assets {
|
||||||
|
alias '${root_path}/vendor/ely/email-renderer/dist/assets';
|
||||||
|
try_files $uri =404;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user