Skip to content

Commit ff33ebe

Browse files
committed
[smarcet] - #12953
* updated all members related emails ( reverification, registration) to be sent to proper recipient
1 parent 29121df commit ff33ebe

5 files changed

Lines changed: 41 additions & 19 deletions

File tree

change_password/code/model/PasswordManager.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function __construct(ITransactionManager $tx_manager)
2727
{
2828
$this->tx_manager = $tx_manager;
2929
}
30+
3031
/**
3132
* @param int $member_id
3233
* @param string $token
@@ -35,8 +36,7 @@ public function __construct(ITransactionManager $tx_manager)
3536
*/
3637
public function verifyToken($member_id, $token)
3738
{
38-
return $this->tx_manager->transaction(function() use($member_id, $token)
39-
{
39+
return $this->tx_manager->transaction(function () use ($member_id, $token) {
4040
if (is_null($member_id) || $member_id == 0 || empty($token)) {
4141
throw new InvalidPasswordResetLinkException;
4242
}
@@ -64,8 +64,7 @@ public function verifyToken($member_id, $token)
6464
*/
6565
public function changePassword($token, $password, $password_confirmation)
6666
{
67-
return $this->tx_manager->transaction(function() use($token, $password, $password_confirmation)
68-
{
67+
return $this->tx_manager->transaction(function () use ($token, $password, $password_confirmation) {
6968
$member = Member::currentUser();
7069
if (!$member) {
7170
if (empty($token)) {
@@ -91,8 +90,11 @@ public function changePassword($token, $password, $password_confirmation)
9190
$member->generateAutologinTokenAndStoreHash();
9291

9392
//send confirmation email
94-
$email = EmailFactory::getInstance()->buildEmail(CHANGE_PASSWORD_EMAIL_FROM, $member->Email,
95-
CHANGE_PASSWORD_EMAIL_SUBJECT);
93+
$email = EmailFactory::getInstance()->buildEmailIgnoringEnv(CHANGE_PASSWORD_EMAIL_FROM,
94+
$member->Email,
95+
CHANGE_PASSWORD_EMAIL_SUBJECT
96+
);
97+
9698
$email->setTemplate('ChangedPasswordEmail');
9799
$email->populateTemplate(array('MemberName' => $member->getFullName()));
98100
$email->send();

change_password/code/ui/CustomLostPasswordForm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function forgotPassword($data) {
7777
if(is_null($e))
7878
throw new Exception(sprintf('Email Template %s does not exists on DB!', MEMBER_FORGOT_PASSWORD_EMAIL_TEMPLATE_ID));
7979

80-
$e = EmailFactory::getInstance()->buildEmail("noreply@openstack.org", $member->Email);
80+
$e = EmailFactory::getInstance()->buildEmailIgnoringEnv("noreply@openstack.org", $member->Email);
8181

8282
$e->setUserTemplate(MEMBER_FORGOT_PASSWORD_EMAIL_TEMPLATE_ID)->populateTemplate(
8383
[

openstack/code/utils/email/EmailFactory.php

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@ final class EmailFactory
2424
*/
2525
private static $instance;
2626

27-
private function __construct()
28-
{
29-
}
27+
private function __construct(){}
3028

31-
private function __clone()
32-
{
33-
}
29+
private function __clone(){}
3430

3531
/**
3632
* @return EmailFactory
@@ -44,6 +40,7 @@ public static function getInstance()
4440
return self::$instance;
4541
}
4642

43+
4744
/**
4845
* @param null $from
4946
* @param null $to
@@ -54,22 +51,47 @@ public static function getInstance()
5451
* @param null $bcc
5552
* @return Email
5653
*/
57-
public function buildEmail(
54+
public function buildEmailIgnoringEnv
55+
(
5856
$from = null,
5957
$to = null,
6058
$subject = null,
6159
$body = null,
6260
$bounceHandlerURL = null,
6361
$cc = null,
6462
$bcc = null
63+
)
64+
{
65+
return $this->buildEmail($from, $to, $subject, $body, $bounceHandlerURL, $cc, $bcc, true);
66+
}
67+
/**
68+
* @param null $from
69+
* @param null $to
70+
* @param null $subject
71+
* @param null $body
72+
* @param null $bounceHandlerURL
73+
* @param null $cc
74+
* @param null $bcc
75+
* @param bool $ignore_env
76+
* @return Email
77+
*/
78+
public function buildEmail(
79+
$from = null,
80+
$to = null,
81+
$subject = null,
82+
$body = null,
83+
$bounceHandlerURL = null,
84+
$cc = null,
85+
$bcc = null,
86+
$ignore_env = false
6587
) {
6688
$env = 'dev';
6789
if (defined('SS_ENVIRONMENT_TYPE')) {
6890
$env = SS_ENVIRONMENT_TYPE;
6991
}
7092

7193
$email = Email::create();
72-
if ($env == 'dev') {
94+
if ($env == 'dev' && !$ignore_env) {
7395
$to = defined('DEV_EMAIL_TO') ? DEV_EMAIL_TO : Config::inst()->get('Email', 'admin_email');
7496
}
7597

registration/code/infrastructure/services/MemberRegistrationSenderService.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@ public function send($subject)
3030
}
3131

3232
$from = null;
33-
$email = EmailFactory::getInstance()->buildEmail($from, $subject->Email);
33+
$email = EmailFactory::getInstance()->buildEmailIgnoringEnv($from, $subject->Email);
3434

3535
$token = $subject->generateEmailVerificationToken();
3636

37-
38-
3937
$email->setUserTemplate(MEMBER_REGISTRATION_VERIFICATION_EMAIL_TEMPLATE_ID)->populateTemplate(
4038
array
4139
(

registration/code/infrastructure/services/MemberRegistrationVerifiedSenderService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function send($subject)
3030
}
3131

3232
$from = null;
33-
$email = EmailFactory::getInstance()->buildEmail($from, $subject->Email);
33+
$email = EmailFactory::getInstance()->buildEmailIgnoringEnv($from, $subject->Email);
3434
$email->setUserTemplate(MEMBER_REGISTRATION_VERIFIED_EMAIL_TEMPLATE_ID)->populateTemplate(
3535
array
3636
(

0 commit comments

Comments
 (0)