forked from CakeDC/users
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsersMailer.php
More file actions
81 lines (76 loc) · 2.67 KB
/
Copy pathUsersMailer.php
File metadata and controls
81 lines (76 loc) · 2.67 KB
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
75
76
77
78
79
80
81
<?php
/**
* Copyright 2010 - 2017, Cake Development Corporation (https://www.cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2010 - 2017, Cake Development Corporation (https://www.cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace CakeDC\Users\Mailer;
use Cake\Datasource\EntityInterface;
use Cake\Mailer\Mailer;
/**
* User Mailer
*
*/
class UsersMailer extends Mailer
{
/**
* Send the templated email to the user
*
* @param EntityInterface $user User entity
* @return void
*/
protected function validation(EntityInterface $user)
{
$firstName = isset($user['first_name'])? $user['first_name'] . ', ' : '';
// un-hide the token to be able to send it in the email content
$user->setHidden(['password', 'token_expires', 'api_token']);
$subject = __d('CakeDC/Users', 'Your account validation link');
$this
->setTo($user['email'])
->setSubject($firstName . $subject)
->setViewVars($user->toArray())
->setTemplate('CakeDC/Users.validation');
}
/**
* Send the reset password email to the user
*
* @param EntityInterface $user User entity
*
* @return void
*/
protected function resetPassword(EntityInterface $user)
{
$firstName = isset($user['first_name'])? $user['first_name'] . ', ' : '';
$subject = __d('CakeDC/Users', '{0}Your reset password link', $firstName);
// un-hide the token to be able to send it in the email content
$user->setHidden(['password', 'token_expires', 'api_token']);
$this
->setTo($user['email'])
->setSubject($subject)
->setViewVars($user->toArray())
->setTemplate('CakeDC/Users.resetPassword');
}
/**
* Send account validation email to the user
*
* @param EntityInterface $user User entity
* @param EntityInterface $socialAccount SocialAccount entity
*
* @return void
*/
protected function socialAccountValidation(EntityInterface $user, EntityInterface $socialAccount)
{
$firstName = isset($user['first_name'])? $user['first_name'] . ', ' : '';
// note: we control the space after the username in the previous line
$subject = __d('CakeDC/Users', '{0}Your social account validation link', $firstName);
$this
->setTo($user['email'])
->setSubject($subject)
->setViewVars(compact('user', 'socialAccount'))
->setTemplate('CakeDC/Users.socialAccountValidation');
}
}