Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
Refactor email into a module and add support for Google App Engine an…
Browse files Browse the repository at this point in the history
…d SendGrid
  • Loading branch information
Jamie Snape committed Nov 6, 2014
1 parent fbc2347 commit 237785c
Show file tree
Hide file tree
Showing 34 changed files with 1,176 additions and 203 deletions.
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,36 @@
},
"require": {
"php": ">=5.3.23",
"ext-gd": "*",
"ext-json": "*",
"francodacosta/phMagick": "0.4.*@dev",
"leafo/scssphp": "~0.1.1",
"maennchen/zipstream-php": "~0.2.2",
"michelf/php-markdown": "~1.4.1",
"monolog/monolog": "~1.11.0",
"pear-pear.php.net/XML_Serializer": "~0.20.2",
"reprovinci/solr-php-client": "~1.0.3",
"sendgrid/sendgrid": "~2.1.1",
"zendframework/zendframework1": "~1.12.9"
},
"require-dev": {
"fabpot/php-cs-fixer": "~0.5.7",
"phpcheckstyle/phpcheckstyle": "V0.14.1",
"phpunit/dbunit": "~1.3.1",
"phpunit/phpunit": "~3.7.38",
"satooshi/php-coveralls": "~0.6.1"
"satooshi/php-coveralls": "~0.6.1",
"sensiolabs/security-checker": "~2.0.0"
},
"suggest": {
"ext-curl": "*",
"ext-imagick": "*",
"ext-ldap": "*",
"ext-memcached": "*",
"ext-zip": "*"
},
"autoload": {
"psr-0": {
"Midas_": "library",
"REST_": "library"
}
},
Expand Down
2 changes: 0 additions & 2 deletions core/configs/application.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ md5sum.path =
defaultassetstore.id =
; default timezone
default.timezone = America/New_York
; processing onthefly or cron
processing = onthefly
; default license
defaultlicense = 1
; enable dynamic help
Expand Down
21 changes: 7 additions & 14 deletions core/controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ public function indexAction()
$formArray['lang']->setValue($config->global->application->lang);
$formArray['name']->setValue($config->global->application->name);
$formArray['timezone']->setValue($config->global->default->timezone);
$formArray['smtpserver']->setValue($config->global->smtpserver);
$formArray['smtpuser']->setValue($config->global->smtpuser);
$formArray['smtppassword']->setValue($config->global->smtppassword);
$formArray['smtpfromaddress']->setValue($config->global->smtpfromaddress);

if (isset($config->global->closeregistration)) {
$formArray['closeregistration']->setValue($config->global->closeregistration);
}
Expand All @@ -100,9 +97,6 @@ public function indexAction()
if (isset($config->global->logtrace)) {
$formArray['logtrace']->setValue($config->global->logtrace);
}
if (isset($config->global->verifyemail)) {
$formArray['verifyemail']->setValue($config->global->verifyemail);
}
$this->view->configForm = $formArray;

$this->view->selectedLicense = $config->global->defaultlicense;
Expand Down Expand Up @@ -131,12 +125,7 @@ public function indexAction()
$config->global->closeregistration = $this->getParam('closeregistration');
$config->global->logtrace = $this->getParam('logtrace');
$config->global->httpproxy = $this->getParam('httpProxy');
$config->global->smtpserver = $this->getParam('smtpserver');
$config->global->smtpuser = $this->getParam('smtpuser');
$config->global->smtppassword = $this->getParam('smtppassword');
$config->global->smtpfromaddress = $this->getParam('smtpfromaddress');
$config->global->gravatar = $this->getParam('gravatar');
$config->global->verifyemail = $this->getParam('verifyemail');

$writer = new Zend_Config_Writer_Ini();
$writer->setConfig($config);
Expand Down Expand Up @@ -220,9 +209,13 @@ public function indexAction()
$adapter = Zend_Registry::get('configDatabase')->database->adapter;
foreach ($allModules as $key => $module) {
if (file_exists(BASE_PATH."/modules/".$key."/controllers/ConfigController.php")) {
$allModules[$key]->configPage = true;
$allModules[$key]->configPage = 'config';
} elseif (file_exists(BASE_PATH."/privateModules/".$key."/controllers/ConfigController.php")) {
$allModules[$key]->configPage = true;
$allModules[$key]->configPage = 'config';
} elseif (file_exists(BASE_PATH."/modules/".$key."/controllers/AdminController.php")) {
$allModules[$key]->configPage = 'admin';
} elseif (file_exists(BASE_PATH."/privateModules/".$key."/controllers/AdminController.php")) {
$allModules[$key]->configPage = 'admin';
} else {
$allModules[$key]->configPage = false;
}
Expand Down
58 changes: 31 additions & 27 deletions core/controllers/CommunityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,22 +544,23 @@ public function sendinvitationAction()

$url = $this->getServerURL().$this->view->webroot;
$subject = 'Community Invitation';
$body = $this->userSession->Dao->getFullName().' has invited you to join the <b>'.$community->getName(
).'</b> community on Midas Platform.<br/><br/>'.'<a href="'.$url.'/user/emailregister?email='.$email.'&authKey='.$newuserinvite->getAuthKey(
).'">Click here</a> to complete your user registration '.'if you wish to join.';
if (UtilityComponent::sendEmail($email, $subject, $body)) {
$this->getLogger()->debug(
'User '.$this->userSession->Dao->getEmail().' emailed '.$email.' to join '.$community->getName(
).' ('.$group->getName().' group)'
);
$body = $this->userSession->Dao->getFullName().' has invited you to join the <b>'.$community->getName().'</b> community on Midas Platform.<br/><br/>'.'<a href="'.$url.'/user/emailregister?email='.$email.'&authKey='.$newuserinvite->getAuthKey().'">Click here</a> to complete your user registration '.'if you wish to join.';

$result = Zend_Registry::get('notifier')->callback(
'CALLBACK_CORE_SEND_MAIL_MESSAGE',
array(
'to' => $email,
'subject' => $subject,
'html' => $body,
'event' => 'community_invite',
)
);

if ($result) {
echo JsonComponent::encode(array(true, 'Invitation sent to '.$email));
} else {
$this->getLogger()->warn(
'Failed sending register/community invitation email to '.$email.' for community '.$community->getName(
)
);
echo JsonComponent::encode(array(true, 'Invitation not sent'));
}

echo JsonComponent::encode(array(true, 'Invitation sent to '.$email));
}
} else {
throw new Zend_Exception('Must pass userId or email parameter');
Expand All @@ -586,23 +587,26 @@ private function _sendUserInvitation($userDao, $groupDao)
array(false, $userDao->getFullName().$this->t(' is already invited to this community.'))
);
} else {
$email = $userDao->getEmail();
$url = $this->getServerURL().$this->view->webroot;
$subject = 'Community Invitation';
$body = 'You have been invited to join the <b>'.$community->getName(
).'</b> community at '.$url.'.<br/><br/>'.'<a href="'.$url.'/community/'.$community->getKey(
).'">'.'Click here</a> to see the community, and click the "Join the community" button '.'if you wish to join.';
if (UtilityComponent::sendEmail($userDao->getEmail(), $subject, $body)
) {
$this->getLogger()->debug(
'User '.$this->userSession->Dao->getEmail().' invited user '.$userDao->getEmail(
).' to '.$community->getName().' ('.$groupDao->getName().' group)'
);
$body = 'You have been invited to join the <b>'.$community->getName().'</b> community at '.$url.'.<br/><br/>'.'<a href="'.$url.'/community/'.$community->getKey().'">'.'Click here</a> to see the community, and click the "Join the community" button '.'if you wish to join.';

$result = Zend_Registry::get('notifier')->callback(
'CALLBACK_CORE_SEND_MAIL_MESSAGE',
array(
'to' => $email,
'subject' => $subject,
'html' => $body,
'event' => 'community_invite',
)
);

if ($result) {
echo JsonComponent::encode(array(true, 'Invitation sent to '.$email));
} else {
$this->getLogger()->warn(
'Failed sending community invitation email to '.$email.' for community '.$community->getName()
);
echo JsonComponent::encode(array(true, 'Invitation not sent'));
}
echo JsonComponent::encode(array(true, $userDao->getFullName().' '.$this->t('has been invited')));
}
}

Expand Down
80 changes: 60 additions & 20 deletions core/controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class UserController extends AppController
'Group',
'Item',
'Community',
'Setting',
);
public $_daos = array('User', 'Folder', 'Folderpolicygroup', 'Folderpolicyuser', 'Group');
public $_components = array('Breadcrumb', 'Date', 'Filter', 'Sortdao');
Expand Down Expand Up @@ -112,20 +113,29 @@ public function recoverpasswordAction()
$pass = UtilityComponent::generateRandomString(10);
$this->User->changePassword($user, $pass);

// Send the email
$url = $this->getServerURL().$this->view->webroot;

$subject = "Password Request";
$body = "You have requested a new password for Midas Platform.<br>";
$body .= "Please go to this page to log into Midas Platform and change your password:<br>";
$body .= "<a href=\"".$url."\">".$url."</a><br>";
$body .= "Your new password is: ".$pass."<br>";
$body = "You have requested a new password for Midas Platform.<br />";
$body .= "Please go to this page to log into Midas Platform and change your password:<br />";
$body .= "<a href=\"".$url."\">".$url."</a><br />";
$body .= "Your new password is: ".$pass."<br />";

$result = Zend_Registry::get('notifier')->callback(
'CALLBACK_CORE_SEND_MAIL_MESSAGE',
array(
'to' => $email,
'subject' => $subject,
'html' => $body,
'event' => 'user_reset_password',
)
);

if (UtilityComponent::sendEmail($email, $subject, $body)) {
if ($result) {
$this->User->save($user);
echo JsonComponent::encode(array(true, $this->t('Sent email to').' '.$email));
echo JsonComponent::encode(array(true, 'Password request sent.'));
} else {
echo JsonComponent::encode(array(false, 'Could not send email'));
echo JsonComponent::encode(array(false, 'Could not send password request.'));
}
}
}
Expand Down Expand Up @@ -231,10 +241,9 @@ public function ajaxregisterAction()
}

$email = strtolower(trim($form->getValue('email')));
if ($adminCreate || !isset(Zend_Registry::get('configGlobal')->verifyemail) || Zend_Registry::get(
'configGlobal'
)->verifyemail != '1'
) {
$addressVerification = $this->Setting->getValueByName('address_verification', 'mail');

if ($adminCreate || $addressVerification != '1') {
$newUser = $this->User->createUser(
$email,
$form->getValue('password1'),
Expand All @@ -246,14 +255,24 @@ public function ajaxregisterAction()
$subject = 'User Registration';
$url = $this->getServerURL().$this->view->webroot;
$body = "An administrator has created a user account for you at the following Midas Platform instance:<br/><br/>";
$body .= '<a href="'.$url.'">'.$url.'</a><br/><br/>';
$body .= '<a href="'.$url.'">'.$url.'</a><br /><br />';

if (!$nopass) {
$body .= "Log in using this email address (".$email.") and your initial password:<br/><br/>";
$body .= '<b>'.$form->getValue('password1').'</b><br/><br/>';
}

if (UtilityComponent::sendEmail($email, $subject, $body)) {
$result = Zend_Registry::get('notifier')->callback(
'CALLBACK_CORE_SEND_MAIL_MESSAGE',
array(
'to' => $email,
'subject' => $subject,
'html' => $body,
'event' => 'user_create',
)
);

if ($result) {
echo JsonComponent::encode(array('status' => 'ok', 'message' => 'User created successfully'));
} else {
echo JsonComponent::encode(
Expand Down Expand Up @@ -286,7 +305,18 @@ public function ajaxregisterAction()
$body = "You have created an account on Midas Platform.<br/><br/>";
$body .= '<a href="'.$url.'">Click here</a> to verify your email and complete registration.<br/><br/>';
$body .= 'If you did not initiate this registration, please disregard this email.<br/><br/>';
if (UtilityComponent::sendEmail($email, $subject, $body)) {

$result = Zend_Registry::get('notifier')->callback(
'CALLBACK_CORE_SEND_MAIL_MESSAGE',
array(
'to' => $email,
'subject' => $subject,
'html' => $body,
'event' => 'user_verify',
)
);

if ($result) {
echo JsonComponent::encode(array('status' => 'ok', 'message' => 'Verification email sent'));
} else {
echo JsonComponent::encode(
Expand Down Expand Up @@ -314,10 +344,9 @@ public function registerAction()
throw new Zend_Exception("User already exists.");
}

if (!isset(Zend_Registry::get('configGlobal')->verifyemail) || Zend_Registry::get(
'configGlobal'
)->verifyemail != '1'
) {
$addressVerification = $this->Setting->getValueByName('address_verification', 'mail');

if ($addressVerification != '1') {
if (!headers_sent()) {
session_start();
}
Expand Down Expand Up @@ -345,7 +374,18 @@ public function registerAction()
$body = "You have created an account on Midas Platform.<br/><br/>";
$body .= '<a href="'.$url.'">Click here</a> to verify your email and complete registration.<br/><br/>';
$body .= 'If you did not initiate this registration, please disregard this email.<br/><br/>';
if (UtilityComponent::sendEmail($email, $subject, $body)) {

$result = Zend_Registry::get('notifier')->callback(
'CALLBACK_CORE_SEND_MAIL_MESSAGE',
array(
'to' => $email,
'subject' => $subject,
'html' => $body,
'event' => 'user_verify',
)
);

if ($result) {
$this->redirect('/user/emailsent');
}
}
Expand Down
Loading

0 comments on commit 237785c

Please sign in to comment.