Skip to content

Commit

Permalink
Replacing Ushahidi_Mailer with a Lumen implementation
Browse files Browse the repository at this point in the history
- Add new implementation
- Add illuminate/mail
- Add mockery for tests
- Add tests
  • Loading branch information
rjmackay committed Jul 3, 2017
1 parent afaa304 commit 02c1eaa
Show file tree
Hide file tree
Showing 11 changed files with 720 additions and 196 deletions.
7 changes: 7 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function register()
$this->app->configure('cdn');
$this->app->configure('ratelimiter');
$this->app->configure('multisite');
$this->app->configure('mail');
$this->app->configure('ohanzee-db');

$this->configureAuraDI();
Expand Down Expand Up @@ -127,6 +128,12 @@ protected function configureAuraDI()
return '';
});

// Configure mailer
// $di->set('tool.mailer', $di->lazyNew('Ushahidi\App\Tools\LumenMailer', [
// 'mailer' => app('Illuminate\Mail\Mailer'),
// 'siteConfig' => $di->lazyGet('site.config'),
// 'clientUrl' => $di->lazyGet('clienturl')
// ]));

// @todo move to auth provider?
$di->set('session.user', function () use ($di) {
Expand Down
76 changes: 76 additions & 0 deletions app/Tools/LumenMailer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/**
* Ushahidi Mailer
*
* @author Ushahidi Team <team@ushahidi.com>
* @package Ushahidi\Application
* @copyright 2014 Ushahidi
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
*/

namespace Ushahidi\App\Tools;

use Ushahidi\Core\Tool\Mailer as MailerContract;
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Support\Str;

class LumenMailer implements MailerContract
{
public function __construct(Mailer $mailer, $siteConfig, $clientUrl)
{
$this->mailer = $mailer;
$this->siteConfig = $siteConfig;
$this->clientUrl = $clientUrl;
}

public function send($to, $type, Array $params = null)
{
$method = "send" . Str::ucfirst($type);
if (method_exists($this, $method)) {
$this->$method($to, $params);
} else {
// Exception
throw new Exception('Unsupported mail type: ' + $type);
}
}

protected function sendResetpassword($to, $params)
{
$site_name = $this->siteConfig['name'];
$site_email = $this->siteConfig['email'];
$multisite_email = config('multisite.email');

// @todo make this more robust
if ($multisite_email) {
$from_email = $multisite_email;
} elseif ($site_email) {
$from_email = $site_email;
} else {
$from_email = false;
// Get host from lumen
// $host = app()->make('request')->getHost();
// $from_email = 'noreply@' . $host;
}

$data = [
'site_name' => $site_name,
'token' => $params['token'],
'client_url' => $this->clientUrl
];

$subject = $site_name . ': Password reset';

$this->mailer->send(
'emails/forgot-password',
$data,
function ($message) use ($to, $subject, $from_email, $site_name) {
$message->to($to);
$message->subject($subject);
if ($from_email) {
$message->from($from_email, $site_name);
}
}
);
}
}
9 changes: 2 additions & 7 deletions application/classes/Ushahidi/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static function init()
* 0. Register depenendencies for injection.
*/
$di = service();

/*
// Kohana injection
// DB config
$di->set('db.config', function() use ($di) {
Expand Down Expand Up @@ -51,12 +51,7 @@ public static function init()
});
$di->set('tool.validation', $di->lazyNew('Ushahidi_ValidationEngine'));

$di->set('tool.mailer', $di->lazyNew('Ushahidi_Mailer', [
'siteConfig' => $di->lazyGet('site.config'),
'clientUrl' => $di->lazyGet('clienturl')
]));

*/
/**
* 1. Load the plugins
*/
Expand Down
1 change: 1 addition & 0 deletions bootstrap/lumen.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
|
*/

$app->register(Illuminate\Mail\MailServiceProvider::class);
$app->register(Ushahidi\App\Providers\AppServiceProvider::class);
$app->register(Ushahidi\App\Providers\AuthServiceProvider::class);
// $app->register(Ushahidi\App\Providers\EventServiceProvider::class);
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"abraham/twitteroauth": "^0.5.3",
"ohanzee/database": "dev-namespaces",
"robmorgan/phinx": "~0.8.0",
"ushahidi/shadowhand-email": "dev-master",
"symm/gisconverter": "~1.0.5",
"twilio/sdk": "3.12.*",
"vlucas/phpdotenv": "~2.2",
Expand All @@ -42,7 +41,9 @@
"ramsey/uuid": "^3.4.1",
"sentry/sentry": "~1.5",
"dusterio/lumen-passport": "^0.1.9",
"barryvdh/laravel-cors": "^0.9.2"
"barryvdh/laravel-cors": "^0.9.2",
"illuminate/mail": "5.4.*",
"mockery/mockery": "^0.9.9"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
Expand Down
Loading

0 comments on commit 02c1eaa

Please sign in to comment.