Skip to content

Commit

Permalink
Merge pull request #411 from rowan04/410-remove-hardwired-email-addre…
Browse files Browse the repository at this point in the history
…sses

Add config calls so email addresses aren't hardwired into code
  • Loading branch information
gregcorbett authored Dec 12, 2022
2 parents 4abbd12 + ce53f7a commit f94e980
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
4 changes: 4 additions & 0 deletions config/local_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
<!-- If page_banner is not empty the text is used to create a page banner strip -->
<page_banner></page_banner>

<!-- Email addresses to send from and reply to -->
<email_from>no-reply@localhost</email_from>
<email_to>gocdb-admins@localhost</email_to>

<!-- Specify the URL and description of the Acceptable Use Policy -->
<aup>AUP location</aup>
<aup_title>AUP title</aup_title>
Expand Down
14 changes: 14 additions & 0 deletions lib/Gocdb_Services/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,4 +542,18 @@ public function getPageBanner()

return $bannerText;
}

public function getEmailFrom()
{
$emailFrom = $this->GetLocalInfoXML()->email_from;

return $emailFrom;
}

public function getEmailTo()
{
$emailTo = $this->GetlocalInfoXML()->email_to;

return $emailTo;
}
}
12 changes: 9 additions & 3 deletions lib/Gocdb_Services/LinkIdentity.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ public function getRequestByConfirmationCode($code) {
*/
private function composeEmail($primaryIdString, $currentIdString, $primaryAuthType, $currentAuthType, $isLinking, $isRegistered, $isPrimary, $link=null) {

$configService = \Factory::getConfigService();

$subject = "Validation of " . ($isLinking ? "linking" : "recovering") . " your GOCDB account";

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

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

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

$configService = \Factory::getConfigService();

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

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

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

return $request;
}
}
}
12 changes: 10 additions & 2 deletions lib/Gocdb_Services/NotificationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ private function sendEmail($roleRequested, $requestingUser, $entityName, $approv
$roleRequested->getOwnedEntity()->getName()
);

$configService = \Factory::getConfigService();

$body = sprintf(
implode("\n", array(
'Dear %1$s,',
Expand All @@ -123,17 +125,23 @@ private function sendEmail($roleRequested, $requestingUser, $entityName, $approv
' %6$s/index.php?Page_Type=Role_Requests',
'',
'Note: This role could already have been approved or denied by another GOCDB User',
'',
'Please do not reply to this email. If you would like to get in touch with the ' .
'GOCDB admins please send an email to: %7$s',
)),
$approvingUser->getForename(),
$requestingUser->getForename(),
$requestingUser->getSurname(),
$roleRequested->getRoleType()->getName(),
$roleRequested->getOwnedEntity()->getName(),
$this->getWebPortalURL()
$this->getWebPortalURL(),
$configService->getEmailTo()
);

$emailAddress = $approvingUser->getEmail();
$headers = "From: GOCDB <[email protected]>";

$emailSentFrom = $configService->getEmailFrom();
$headers = "From: GOCDB <" . $emailSentFrom . ">";

\Factory::getEmailService()->send($emailAddress, $subject, $body, $headers);
}
Expand Down
12 changes: 10 additions & 2 deletions resources/RemoveInactiveUsersRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,14 @@ function sendWarningEmail($user, $elapsedMonths, $deletionThreshold)
{
$emailAddress = $user->getEmail();

$configService = \Factory::getConfigService();

$emailSentFrom = $configService->getEmailFrom();

$emailSendTo = $configService->getEmailTo();

// Email content
$headers = "From: GOCDB <[email protected]>";
$headers = "From: GOCDB <" . $emailSentFrom . ">";
$subject = "GOCDB: User account deletion notice";

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


// Handle all mail related printing/debugging
Expand Down

0 comments on commit f94e980

Please sign in to comment.