-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replacing Ushahidi_Mailer with a Lumen implementation
- Add new implementation - Add illuminate/mail - Add mockery for tests - Add tests
- Loading branch information
Showing
11 changed files
with
720 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.