Skip to content

Commit f94e980

Browse files
authored
Merge pull request #411 from rowan04/410-remove-hardwired-email-addresses
Add config calls so email addresses aren't hardwired into code
2 parents 4abbd12 + ce53f7a commit f94e980

File tree

5 files changed

+47
-7
lines changed

5 files changed

+47
-7
lines changed

config/local_info.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
<!-- If page_banner is not empty the text is used to create a page banner strip -->
1414
<page_banner></page_banner>
1515

16+
<!-- Email addresses to send from and reply to -->
17+
<email_from>no-reply@localhost</email_from>
18+
<email_to>gocdb-admins@localhost</email_to>
19+
1620
<!-- Specify the URL and description of the Acceptable Use Policy -->
1721
<aup>AUP location</aup>
1822
<aup_title>AUP title</aup_title>

lib/Gocdb_Services/Config.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,4 +542,18 @@ public function getPageBanner()
542542

543543
return $bannerText;
544544
}
545+
546+
public function getEmailFrom()
547+
{
548+
$emailFrom = $this->GetLocalInfoXML()->email_from;
549+
550+
return $emailFrom;
551+
}
552+
553+
public function getEmailTo()
554+
{
555+
$emailTo = $this->GetlocalInfoXML()->email_to;
556+
557+
return $emailTo;
558+
}
545559
}

lib/Gocdb_Services/LinkIdentity.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ public function getRequestByConfirmationCode($code) {
243243
*/
244244
private function composeEmail($primaryIdString, $currentIdString, $primaryAuthType, $currentAuthType, $isLinking, $isRegistered, $isPrimary, $link=null) {
245245

246+
$configService = \Factory::getConfigService();
247+
246248
$subject = "Validation of " . ($isLinking ? "linking" : "recovering") . " your GOCDB account";
247249

248250
$body = "Dear GOCDB User,"
@@ -274,7 +276,8 @@ private function composeEmail($primaryIdString, $currentIdString, $primaryAuthTy
274276
. "\n\n$link";
275277
}
276278

277-
$body .= "\n\nIf you did not create this request, please immediately contact [email protected]";
279+
$emailSendTo = $configService->getEmailTo();
280+
$body .= "\n\nIf you did not create this request, please immediately contact " . $emailSendTo;
278281

279282
return array('subject'=>$subject, 'body'=>$body);
280283
}
@@ -293,6 +296,8 @@ private function composeEmail($primaryIdString, $currentIdString, $primaryAuthTy
293296
*/
294297
private function sendConfirmationEmails($primaryUser, $currentUser, $code, $primaryIdString, $currentIdString, $primaryAuthType, $currentAuthType, $isLinking, $isRegistered) {
295298

299+
$configService = \Factory::getConfigService();
300+
296301
// Create link to be clicked in email
297302
$portalUrl = \Factory::getConfigService()->GetPortalURL();
298303
$link = $portalUrl."/index.php?Page_Type=User_Validate_Identity_Link&c=" . $code;
@@ -304,7 +309,8 @@ private function sendConfirmationEmails($primaryUser, $currentUser, $code, $prim
304309
$primaryBody = $composedPrimaryEmail['body'];
305310

306311
// If "sendmail_from" is set in php.ini, use second line ($headers = '';):
307-
$headers = "From: GOCDB <[email protected]>";
312+
$emailSentFrom = $configService->getEmailFrom();
313+
$headers = "From: GOCDB <" . $emailSentFrom . ">";
308314

309315
// Mail command returns boolean. False if message not accepted for delivery.
310316
if (!mail($primaryUser->getEmail(), $primarySubject, $primaryBody, $headers)) {
@@ -414,4 +420,4 @@ public function confirmIdentityLinking($code, $currentIdString) {
414420

415421
return $request;
416422
}
417-
}
423+
}

lib/Gocdb_Services/NotificationService.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ private function sendEmail($roleRequested, $requestingUser, $entityName, $approv
113113
$roleRequested->getOwnedEntity()->getName()
114114
);
115115

116+
$configService = \Factory::getConfigService();
117+
116118
$body = sprintf(
117119
implode("\n", array(
118120
'Dear %1$s,',
@@ -123,17 +125,23 @@ private function sendEmail($roleRequested, $requestingUser, $entityName, $approv
123125
' %6$s/index.php?Page_Type=Role_Requests',
124126
'',
125127
'Note: This role could already have been approved or denied by another GOCDB User',
128+
'',
129+
'Please do not reply to this email. If you would like to get in touch with the ' .
130+
'GOCDB admins please send an email to: %7$s',
126131
)),
127132
$approvingUser->getForename(),
128133
$requestingUser->getForename(),
129134
$requestingUser->getSurname(),
130135
$roleRequested->getRoleType()->getName(),
131136
$roleRequested->getOwnedEntity()->getName(),
132-
$this->getWebPortalURL()
137+
$this->getWebPortalURL(),
138+
$configService->getEmailTo()
133139
);
134140

135141
$emailAddress = $approvingUser->getEmail();
136-
$headers = "From: GOCDB <[email protected]>";
142+
143+
$emailSentFrom = $configService->getEmailFrom();
144+
$headers = "From: GOCDB <" . $emailSentFrom . ">";
137145

138146
\Factory::getEmailService()->send($emailAddress, $subject, $body, $headers);
139147
}

resources/RemoveInactiveUsersRunner.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,14 @@ function sendWarningEmail($user, $elapsedMonths, $deletionThreshold)
176176
{
177177
$emailAddress = $user->getEmail();
178178

179+
$configService = \Factory::getConfigService();
180+
181+
$emailSentFrom = $configService->getEmailFrom();
182+
183+
$emailSendTo = $configService->getEmailTo();
184+
179185
// Email content
180-
$headers = "From: GOCDB <[email protected]>";
186+
$headers = "From: GOCDB <" . $emailSentFrom . ">";
181187
$subject = "GOCDB: User account deletion notice";
182188

183189
$body = "Dear ". $user->getForename() .",\n\n" .
@@ -202,7 +208,9 @@ function sendWarningEmail($user, $elapsedMonths, $deletionThreshold)
202208
$body .= "\n";
203209
$body .= "You can prevent the deletion of this account by visiting the " .
204210
"GOCDB portal while authenticated with one of the above " .
205-
"identifiers.\n";
211+
"identifiers.\n\n";
212+
$body .= "Please do not reply to this email. If you would like to get in touch " .
213+
"with the GOCDB admins please send an email to: " . $emailSendTo . "\n";
206214

207215

208216
// Handle all mail related printing/debugging

0 commit comments

Comments
 (0)