This repository has been archived by the owner on Feb 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
mailer.php
74 lines (67 loc) · 2.08 KB
/
mailer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
* Warden: User authorization & authentication library for FuelPHP.
*
* @package Warden
* @subpackage Warden
* @version 1.1
* @author Andrew Wayne <lifeandcoding@gmail.com>
* @license MIT License
* @copyright (c) 2011 - 2012 Andrew Wayne
*/
namespace Warden;
/**
* Warden_Mailer
*
* @package Warden
* @subpackage Warden
*/
class Warden_Mailer
{
public static function __callStatic($method, $arguments)
{
$name = str_replace(array('send_', '_instructions'), '', $method);
return static::_send_instructions($name, $arguments[0]);
}
/**
* Sends the instructions to a user's email address.
*
* @return bool
*/
private static function _send_instructions($name, Model_User $user)
{
$config_key = null;
switch ($name) {
case 'confirmation':
$config_key = 'confirmable';
break;
case 'reset_password':
$config_key = 'recoverable';
break;
case 'unlock':
$config_key = 'lockable';
break;
default:
throw new \InvalidArgumentException("Invalid instruction: $name");
}
$mail = \Email::forge();
$mail->from(\Config::get('email.defaults.from.email'), \Config::get('email.defaults.from.name'));
$mail->to($user->email);
$mail->subject(__("warden.mailer.subject.$name"));
$token_name = "{$name}_token";
$mail->html_body(\View::forge("warden/mailer/{$name}_instructions", array(
'username' => $user->username,
'uri' => \Uri::create(':url/:token', array(
'url' => rtrim(\Config::get("warden.{$config_key}.url"), '/'),
'token' => $user->{$token_name}
))
)));
$mail->priority(\Email::P_HIGH);
try {
return $mail->send();
} catch (\EmailSendingFailedException $ex) {
logger(\Fuel::L_ERROR, "Warden_Mailer failed to send {$name} instructions.");
return false;
}
}
}