airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From machris...@apache.org
Subject [airavata-php-gateway] branch develop updated: AIRAVATA-2509 Email verification: gateway specific FROM and SUBJECT details
Date Tue, 14 Aug 2018 20:18:04 GMT
This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/airavata-php-gateway.git


The following commit(s) were added to refs/heads/develop by this push:
     new 5c3b4e1  AIRAVATA-2509 Email verification: gateway specific FROM and SUBJECT details
     new 8dc639e  Merge branch 'AIRAVATA-2509-account-confirmation-emails-not-making-it-to-users'
into develop
5c3b4e1 is described below

commit 5c3b4e193de013d0c18345ead7b88d65efa48ace
Author: Marcus Christie <machrist@iu.edu>
AuthorDate: Tue Aug 14 16:17:28 2018 -0400

    AIRAVATA-2509 Email verification: gateway specific FROM and SUBJECT details
---
 app/config/email_templates.json       | 20 +++-----
 app/controllers/AccountController.php |  4 +-
 app/controllers/AdminController.php   |  4 +-
 app/libraries/EmailUtilities.php      | 88 ++++++++++++++++++++++++++---------
 4 files changed, 80 insertions(+), 36 deletions(-)

diff --git a/app/config/email_templates.json b/app/config/email_templates.json
index 4a4f8d8..16dccac 100644
--- a/app/config/email_templates.json
+++ b/app/config/email_templates.json
@@ -1,12 +1,11 @@
 {
   "account_verification" : {
-    "subject" : "Verify Your Email Account",
+    "subject" : "$firstName $lastName ($username), Please Verify Your Email Account in $portalTitle",
     "body" : [
-      "<div>",
           "<p>",
               "Dear $firstName $lastName,<br/>",
 
-              "Someone has created a account with this email address. If this was you,",
+              "Someone has created an account with this email address. If this was you,",
               " click the link below to verify your email address<br/>",
 
               "<a href=\"$url\">$url</a><br/>",
@@ -14,15 +13,13 @@
               "This link will expire within $validTime minutes.<br/>",
 
               "If you didn't create this account, just ignore this message.",
-          "</p>",
-      "</div>"
+          "</p>"
     ]
   },
 
   "email_update_verification" : {
-    "subject" : "Verify Your Email Account",
+    "subject" : "$firstName $lastName ($username), Please Verify Your Email Account in $portalTitle",
     "body" : [
-      "<div>",
           "<p>",
               "Dear $firstName $lastName,<br/>",
 
@@ -32,15 +29,13 @@
               "<a href=\"$url\">$url</a><br/>",
 
               "This link will expire within $validTime minutes.<br/>",
-          "</p>",
-      "</div>"
+          "</p>"
     ]
   },
 
   "password_reset" : {
-    "subject" : "Password Reset Request",
+    "subject" : "Password Reset Request for $firstName $lastName ($username)",
     "body" : [
-      "<div>",
           "<p>",
               "Dear $firstName $lastName,<br/>",
 
@@ -52,8 +47,7 @@
               "This link will expire within $validTime minutes.<br/>",
 
               "If you didn't request a password reset, just ignore this message.",
-          "</p>",
-      "</div>"
+          "</p>"
     ]
   },
 
diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php
index f61486b..6377c5d 100644
--- a/app/controllers/AccountController.php
+++ b/app/controllers/AccountController.php
@@ -431,7 +431,9 @@ class AccountController extends BaseController
         $mail->Port = intval(Config::get('pga_config.portal')['portal-smtp-server-port']);
 
         $mail->From = Config::get('pga_config.portal')['portal-email-username'];
-        $mail->FromName = "Airavata PHP Gateway";
+        $gatewayURL = $_SERVER['SERVER_NAME'];
+        $portalTitle = Config::get('pga_config.portal')['portal-title'];
+        $mail->FromName = "$portalTitle ($gatewayURL)";
 
         $recipients = Config::get('pga_config.portal')['admin-emails'];
         foreach($recipients as $recipient){
diff --git a/app/controllers/AdminController.php b/app/controllers/AdminController.php
index e69c527..df4d71e 100644
--- a/app/controllers/AdminController.php
+++ b/app/controllers/AdminController.php
@@ -368,7 +368,9 @@ class AdminController extends BaseController {
 		$mail->Port = intval(Config::get('pga_config.portal')['portal-smtp-server-port']);
 
 		$mail->From = Config::get('pga_config.portal')['portal-email-username'];
-		$mail->FromName = "Gateway Portal: " . $_SERVER['SERVER_NAME'];
+        $gatewayURL = $_SERVER['SERVER_NAME'];
+        $portalTitle = Config::get('pga_config.portal')['portal-title'];
+        $mail->FromName = "$portalTitle ($gatewayURL)";
 
 		foreach($recipients as $recipient){
 			$mail->addAddress($recipient);
diff --git a/app/libraries/EmailUtilities.php b/app/libraries/EmailUtilities.php
index ff9ce9e..49d7058 100644
--- a/app/libraries/EmailUtilities.php
+++ b/app/libraries/EmailUtilities.php
@@ -14,10 +14,15 @@ class EmailUtilities
         $subject = $emailTemplates->account_verification->subject;
         $body = trim(implode($emailTemplates->account_verification->body));
 
-        $body = str_replace("\$url", URL::to('/') . '/confirm-user-registration?username='
. $username . '&code=' . $code, $body);
-        $body = str_replace("\$firstName", $firstName, $body);
-        $body = str_replace("\$lastName", $lastName, $body);
-        $body = str_replace("\$validTime", $validTime, $body);
+        $vars = [
+            "url" => URL::to('/') . '/confirm-user-registration?username=' . $username
. '&code=' . $code,
+            "firstName" => $firstName,
+            "lastName" => $lastName,
+            "validTime" => $validTime,
+            "username" => $username,
+        ];
+        $subject = EmailUtilities::replaceAll($vars, $subject);
+        $body = EmailUtilities::replaceAll($vars, $body);
 
         $recipient = array();
         $recipient['firstName'] = $firstName;
@@ -47,10 +52,15 @@ class EmailUtilities
         $subject = $emailTemplates->email_update_verification->subject;
         $body = trim(implode($emailTemplates->email_update_verification->body));
 
-        $body = str_replace("\$url", URL::to('/') . '/user-profile-confirm-email?username='
. $username . '&code=' . $code, $body);
-        $body = str_replace("\$firstName", $firstName, $body);
-        $body = str_replace("\$lastName", $lastName, $body);
-        $body = str_replace("\$validTime", $validTime, $body);
+        $vars = [
+            "url" => URL::to('/') . '/user-profile-confirm-email?username=' . $username
. '&code=' . $code,
+            "firstName" => $firstName,
+            "lastName" => $lastName,
+            "validTime" => $validTime,
+            "username" => $username,
+        ];
+        $subject = EmailUtilities::replaceAll($vars, $subject);
+        $body = EmailUtilities::replaceAll($vars, $body);
 
         $recipient = array();
         $recipient['firstName'] = $firstName;
@@ -81,10 +91,15 @@ class EmailUtilities
         $subject = $emailTemplates->password_reset->subject;
         $body = trim(implode($emailTemplates->password_reset->body));
 
-        $body = str_replace("\$url", URL::to('/'). '/reset-password?username=' . urlencode($username)
. '&code='.urlencode($code), $body);
-        $body = str_replace("\$firstName", $firstName, $body);
-        $body = str_replace("\$lastName", $lastName, $body);
-        $body = str_replace("\$validTime", $validTime, $body);
+        $vars = [
+            "url" => URL::to('/'). '/reset-password?username=' . urlencode($username)
. '&code='.urlencode($code),
+            "firstName" => $firstName,
+            "lastName" => $lastName,
+            "validTime" => $validTime,
+            "username" => $username,
+        ];
+        $subject = EmailUtilities::replaceAll($vars, $subject);
+        $body = EmailUtilities::replaceAll($vars, $body);
 
         $recipient = array();
         $recipient['firstName'] = $firstName;
@@ -111,10 +126,14 @@ class EmailUtilities
         $subject = $emailTemplates->gateway_request->subject;
         $body = trim(implode($emailTemplates->gateway_request->body));
 
-        $body = str_replace("\$url", URL::to('/') . '/admin/dashboard/gateway', $body);
-        $body = str_replace("\$firstName", $firstName, $body);
-        $body = str_replace("\$lastName", $lastName, $body);
-        $body = str_replace("\$gatewayName", $gatewayName, $body);
+        $vars = [
+            "url" => URL::to('/') . '/admin/dashboard/gateway',
+            "firstName" => $firstName,
+            "lastName" => $lastName,
+            "gatewayName" => $gatewayName,
+        ];
+        $subject = EmailUtilities::replaceAll($vars, $subject);
+        $body = EmailUtilities::replaceAll($vars, $body);
 
         $recipients = array();
         foreach($emails as $email) {
@@ -133,8 +152,12 @@ class EmailUtilities
         $subject = $emailTemplates->update_to_user->subject;
         $body = trim(implode($emailTemplates->update_to_user->body));
 
-        $body = str_replace("\$url", URL::to('/') . '/admin/dashboard', $body);
-        $body = str_replace("\$gatewayId", $gatewayId, $body);
+        $vars = [
+            "url" => URL::to('/') . '/admin/dashboard',
+            "gatewayId" => $gatewayId,
+        ];
+        $subject = EmailUtilities::replaceAll($vars, $subject);
+        $body = EmailUtilities::replaceAll($vars, $body);
 
         $recipient = array();
         $recipient['email'] = $email;
@@ -150,8 +173,12 @@ class EmailUtilities
         $subject = $emailTemplates->update_to_admin->subject;
         $body = trim(implode($emailTemplates->update_to_admin->body));
 
-        $body = str_replace("\$url", URL::to('/') . '/admin/dashboard/gateway', $body);
-        $body = str_replace("\$gatewayId", $gatewayId, $body);
+        $vars = [
+            "url" => URL::to('/') . '/admin/dashboard/gateway',
+            "gatewayId" => $gatewayId,
+        ];
+        $subject = EmailUtilities::replaceAll($vars, $subject);
+        $body = EmailUtilities::replaceAll($vars, $body);
 
         $recipients = array();
         foreach($emails as $email) {
@@ -182,7 +209,9 @@ class EmailUtilities
         $mail->Port = intval(Config::get('pga_config.portal')['portal-smtp-server-port']);
 
         $mail->From = Config::get('pga_config.portal')['portal-email-username'];
-        $mail->FromName = "Airavata PHP Gateway";
+        $gatewayURL = $_SERVER['SERVER_NAME'];
+        $portalTitle = Config::get('pga_config.portal')['portal-title'];
+        $mail->FromName = "$portalTitle ($gatewayURL)";
 
         $mail->Encoding    = '8bit';
         $mail->ContentType = 'text/html; charset=utf-8\r\n';
@@ -200,4 +229,21 @@ class EmailUtilities
         $mail->Body = html_entity_decode($body);
         $mail->send();
     }
+
+    /**
+     * Replace all vars in the given string. Default vars available are
+     * "$gatewayURL" and "$portalTitle".
+     */
+    private static function replaceAll($vars, $string) {
+        $default_vars = [
+            "gatewayURL" => $_SERVER['SERVER_NAME'],
+            "portalTitle" => Config::get('pga_config.portal')['portal-title'],
+        ];
+        $final_vars = array_merge($default_vars, $vars);
+        $result = $string;
+        foreach($final_vars as $var_key => $var_value) {
+            $result = str_replace("\$" . $var_key, $var_value, $result);
+        }
+        return $result;
+    }
 }
\ No newline at end of file


Mime
View raw message