Added e-mail.

This commit is contained in:
flash 2018-07-18 02:44:51 +02:00
parent d0d8d82f60
commit e1ab3bf84c
4 changed files with 179 additions and 18 deletions

92
composer.lock generated
View file

@ -430,16 +430,16 @@
},
{
"name": "swiftmailer/swiftmailer",
"version": "v6.1.1",
"version": "v6.1.2",
"source": {
"type": "git",
"url": "https://github.com/swiftmailer/swiftmailer.git",
"reference": "aa899fef280b1c1aec8d5d4ac069af7f80c89a23"
"reference": "7d760881d266d63c5e7a1155cbcf2ac656a31ca8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/aa899fef280b1c1aec8d5d4ac069af7f80c89a23",
"reference": "aa899fef280b1c1aec8d5d4ac069af7f80c89a23",
"url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/7d760881d266d63c5e7a1155cbcf2ac656a31ca8",
"reference": "7d760881d266d63c5e7a1155cbcf2ac656a31ca8",
"shasum": ""
},
"require": {
@ -485,7 +485,62 @@
"mail",
"mailer"
],
"time": "2018-07-04T11:12:44+00:00"
"time": "2018-07-13T07:04:35+00:00"
},
{
"name": "symfony/polyfill-ctype",
"version": "v1.8.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git",
"reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/7cc359f1b7b80fc25ed7796be7d96adc9b354bae",
"reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.8-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Ctype\\": ""
},
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
},
{
"name": "Gert de Pagter",
"email": "BackEndTea@gmail.com"
}
],
"description": "Symfony polyfill for ctype functions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"ctype",
"polyfill",
"portable"
],
"time": "2018-04-30T19:57:29+00:00"
},
{
"name": "symfony/polyfill-mbstring",
@ -673,20 +728,21 @@
},
{
"name": "twig/twig",
"version": "v2.4.8",
"version": "v2.5.0",
"source": {
"type": "git",
"url": "https://github.com/twigphp/Twig.git",
"reference": "7b604c89da162034bdf4bb66310f358d313dd16d"
"reference": "6a5f676b77a90823c2d4eaf76137b771adf31323"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/7b604c89da162034bdf4bb66310f358d313dd16d",
"reference": "7b604c89da162034bdf4bb66310f358d313dd16d",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/6a5f676b77a90823c2d4eaf76137b771adf31323",
"reference": "6a5f676b77a90823c2d4eaf76137b771adf31323",
"shasum": ""
},
"require": {
"php": "^7.0",
"symfony/polyfill-ctype": "^1.8",
"symfony/polyfill-mbstring": "~1.0"
},
"require-dev": {
@ -697,7 +753,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.4-dev"
"dev-master": "2.5-dev"
}
},
"autoload": {
@ -726,16 +782,16 @@
},
{
"name": "Twig Team",
"homepage": "http://twig.sensiolabs.org/contributors",
"homepage": "https://twig.symfony.com/contributors",
"role": "Contributors"
}
],
"description": "Twig, the flexible, fast, and secure template language for PHP",
"homepage": "http://twig.sensiolabs.org",
"homepage": "https://twig.symfony.com",
"keywords": [
"templating"
],
"time": "2018-04-02T09:24:19+00:00"
"time": "2018-07-13T07:18:09+00:00"
}
],
"packages-dev": [
@ -1493,16 +1549,16 @@
},
{
"name": "phpunit/phpunit-mock-objects",
"version": "5.0.7",
"version": "5.0.8",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
"reference": "3eaf040f20154d27d6da59ca2c6e28ac8fd56dce"
"reference": "6f9a3c8bf34188a2b53ce2ae7a126089c53e0a9f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/3eaf040f20154d27d6da59ca2c6e28ac8fd56dce",
"reference": "3eaf040f20154d27d6da59ca2c6e28ac8fd56dce",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/6f9a3c8bf34188a2b53ce2ae7a126089c53e0a9f",
"reference": "6f9a3c8bf34188a2b53ce2ae7a126089c53e0a9f",
"shasum": ""
},
"require": {
@ -1548,7 +1604,7 @@
"mock",
"xunit"
],
"time": "2018-05-29T13:50:43+00:00"
"time": "2018-07-13T03:27:23+00:00"
},
{
"name": "sebastian/code-unit-reverse-lookup",

View file

@ -11,11 +11,34 @@ database = database
charset = utf8mb4
collation = utf8mb4_bin
[Cache]
host = 127.0.0.1
prefix = msz:
[Auth]
prevent_registration = false
[Site]
name = Misuzu
description = Describe your description.
twitter = flashiinet
url = http://misuzu.localhost/
;external_logo = https://static.flash.moe/images/flashii-logo-v2.png
;social_media = https://twitter.com/flashiinet,https://www.youtube.com/user/flashiinet,https://plus.google.com/u/0/111396468161662583486
;embed_linked_data = false
[GeoIP]
database_path=/path/to/GeoLite2-Country.mmdb
[Mail]
method = null
; method = sendmail
; command = /usr/sbin/sendmail -bs
; method = smtp
; host = smtp.misuzu.localhost
; port = 25
; encryption = tls
; username = sys@misuzu.localhost
; password = flashwaveiscool78

View file

@ -1,9 +1,18 @@
<?php
use Misuzu\Application;
use Misuzu\Cache;
use Misuzu\Database;
require_once __DIR__ . '/../misuzu.php';
/*if ($app->getUserId() === 1) {
$sMessage = new Swift_Message('Test e-mail!');
$sMessage->setFrom(['sys@flashii.net' => 'Flashii.net']);
$sMessage->setTo(['julianvdg@gmail.com' => 'flash']);
$sMessage->setBody('Misuzu and SwiftMailer are cool and cute.');
var_dump(Application::mailer()->send($sMessage));
}*/
$config = $app->getConfig();
$tpl = $app->getTemplating();

View file

@ -8,6 +8,10 @@ use Misuzu\IO\DirectoryDoesNotExistException;
use Misuzu\Users\Session;
use UnexpectedValueException;
use InvalidArgumentException;
use Swift_Mailer;
use Swift_NullTransport;
use Swift_SmtpTransport;
use Swift_SendmailTransport;
/**
* Handles the set up procedures.
@ -28,6 +32,12 @@ class Application extends ApplicationBase
'mysql-main',
];
private const MAIL_TRANSPORT = [
'null' => Swift_NullTransport::class,
'smtp' => Swift_SmtpTransport::class,
'sendmail' => Swift_SendmailTransport::class,
];
/**
* Active Session ID.
* @var int
@ -52,6 +62,8 @@ class Application extends ApplicationBase
*/
private $templatingInstance = null;
private $mailerInstance = null;
/**
* Constructor, called by ApplicationBase::start() which also passes the arguments through.
* @param null|string $configFile
@ -296,4 +308,65 @@ class Application extends ApplicationBase
return $this->templatingInstance;
}
public function startMailer(): void
{
if (!empty($this->mailerInstance)) {
return;
}
if ($this->configInstance->contains('Mail')) {
$method = strtolower($this->configInstance->get('Mail', 'method'));
}
if (empty($method) || !array_key_exists($method, self::MAIL_TRANSPORT)) {
$method = 'null';
}
$class = self::MAIL_TRANSPORT[$method];
$transport = new $class;
switch ($method) {
case 'sendmail':
if ($this->configInstance->contains('Mail', 'command')) {
$transport->setCommand(
$this->configInstance->get('Mail', 'command')
);
}
break;
case 'smtp':
$transport->setHost($this->configInstance->get('Mail', 'host'));
$transport->setPort($this->configInstance->get('Mail', 'port', 'int', 25));
if ($this->configInstance->contains('Mail', 'encryption')) {
$transport->setEncryption($this->configInstance->get('Mail', 'encryption'));
}
if ($this->configInstance->contains('Mail', 'username')) {
$transport->setUsername($this->configInstance->get('Mail', 'username'));
}
if ($this->configInstance->contains('Mail', 'password')) {
$transport->setPassword($this->configInstance->get('Mail', 'password'));
}
break;
}
$this->mailerInstance = new Swift_Mailer($transport);
}
public function getMailer(): Swift_Mailer
{
if (empty($this->mailerInstance)) {
$this->startMailer();
}
return $this->mailerInstance;
}
public static function mailer(): Swift_Mailer
{
return self::getInstance()->getMailer();
}
}