sending access granted email to the user

Project: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/commit/c20e676c
Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/c20e676c
Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/c20e676c

Branch: refs/heads/master
Commit: c20e676c011eb4b8e0560143527434ec71ee9c3a
Parents: 5847c98
Author: scnakandala <[email protected]>
Authored: Wed Mar 16 10:51:35 2016 -0400
Committer: scnakandala <[email protected]>
Committed: Wed Mar 16 10:51:35 2016 -0400

----------------------------------------------------------------------
 app/controllers/AdminController.php | 53 ++++++++++++++++++++++++++++++--
 1 file changed, 51 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/c20e676c/app/controllers/AdminController.php
----------------------------------------------------------------------
diff --git a/app/controllers/AdminController.php 
b/app/controllers/AdminController.php
index e570834..b871558 100644
--- a/app/controllers/AdminController.php
+++ b/app/controllers/AdminController.php
@@ -175,12 +175,61 @@ class AdminController extends BaseController {
        }
 
        public function updateUserRoles(){
-               if( Input::has("add"))
-                       return WSIS::updateUserRoles(Input::get("username"), 
array("new"=> Input::get("roles"), "deleted" => array() ) );
+               if( Input::has("add")){
+                       WSIS::updateUserRoles(Input::get("username"), 
array("new"=> Input::get("roles"), "deleted" => array() ) );
+                       if(in_array(Config::get(wsis::admin-role-name), 
Input::get("roles")) || in_array(Config::get(wsis::read-only-admin-role-name), 
Input::get("roles"))
+                               || in_array(Config::get(wsis::user-role-name), 
Input::get("roles"))){
+                               
$this->sendAccessGrantedEmailToTheUser(Input::get("username"));
+                       }
+               }
                else
                        return WSIS::updateUserRoles(Input::get("username"), 
array("new"=> array(), "deleted" => Input::get("roles") ) );
        }
 
+       private function sendAccessGrantedEmailToTheUser($username){
+
+               $mail = new PHPMailer;
+
+               $mail->isSMTP();
+               $mail->SMTPDebug = 3;
+               $mail->Host = 
Config::get('pga_config.portal')['portal-smtp-server-host'];
+
+               $mail->SMTPAuth = true;
+
+               $mail->Username = 
Config::get('pga_config.portal')['portal-email-username'];
+               $mail->Password = 
Config::get('pga_config.portal')['portal-email-password'];
+
+               $mail->SMTPSecure = "tls";
+               $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'];
+
+               $recipients = Config::get('pga_config.portal')['admin-emails'];
+               foreach($recipients as $recipient){
+                       $mail->addAddress($recipient);
+               }
+
+               $mail->isHTML(true);
+
+               $mail->Subject = "Your user account (".$username.") was 
authorized !";
+               $userProfile = WSIS::getUserProfile($username);
+               $wsisConfig = Config::get('pga_config.wsis');
+               if( $wsisConfig['tenant-domain'] == "")
+                       $username = $username;
+               else
+                       $username = $username . "@" . 
$wsisConfig['tenant-domain'];
+
+               $str = "Please relogin into the portal to access the portal 
features" ."<br/><br/>";
+               $str = $str . "Gateway Portal: " . $_SERVER['SERVER_NAME'] 
."<br/>";
+               $str = $str . "Username: " . $username ."<br/>";
+               $str = $str . "Name: " . $userProfile["firstname"] . " " . 
$userProfile["lastname"] . "<br/>";
+               $str = $str . "Email: " . $userProfile["email"] ;
+
+               $mail->Body = $str;
+               $mail->send();
+       }
+
     public function experimentStatistics()
     {
         if (Request::ajax()) {

Reply via email to