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

Commit 237785c

Browse files
author
Jamie Snape
committed
Refactor email into a module and add support for Google App Engine and SendGrid
1 parent fbc2347 commit 237785c

File tree

34 files changed

+1176
-203
lines changed

34 files changed

+1176
-203
lines changed

composer.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,36 @@
1212
},
1313
"require": {
1414
"php": ">=5.3.23",
15+
"ext-gd": "*",
1516
"ext-json": "*",
1617
"francodacosta/phMagick": "0.4.*@dev",
1718
"leafo/scssphp": "~0.1.1",
1819
"maennchen/zipstream-php": "~0.2.2",
1920
"michelf/php-markdown": "~1.4.1",
21+
"monolog/monolog": "~1.11.0",
2022
"pear-pear.php.net/XML_Serializer": "~0.20.2",
2123
"reprovinci/solr-php-client": "~1.0.3",
24+
"sendgrid/sendgrid": "~2.1.1",
2225
"zendframework/zendframework1": "~1.12.9"
2326
},
2427
"require-dev": {
28+
"fabpot/php-cs-fixer": "~0.5.7",
2529
"phpcheckstyle/phpcheckstyle": "V0.14.1",
2630
"phpunit/dbunit": "~1.3.1",
2731
"phpunit/phpunit": "~3.7.38",
28-
"satooshi/php-coveralls": "~0.6.1"
32+
"satooshi/php-coveralls": "~0.6.1",
33+
"sensiolabs/security-checker": "~2.0.0"
2934
},
3035
"suggest": {
3136
"ext-curl": "*",
37+
"ext-imagick": "*",
3238
"ext-ldap": "*",
3339
"ext-memcached": "*",
3440
"ext-zip": "*"
3541
},
3642
"autoload": {
3743
"psr-0": {
44+
"Midas_": "library",
3845
"REST_": "library"
3946
}
4047
},

core/configs/application.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ md5sum.path =
1515
defaultassetstore.id =
1616
; default timezone
1717
default.timezone = America/New_York
18-
; processing onthefly or cron
19-
processing = onthefly
2018
; default license
2119
defaultlicense = 1
2220
; enable dynamic help

core/controllers/AdminController.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,7 @@ public function indexAction()
8181
$formArray['lang']->setValue($config->global->application->lang);
8282
$formArray['name']->setValue($config->global->application->name);
8383
$formArray['timezone']->setValue($config->global->default->timezone);
84-
$formArray['smtpserver']->setValue($config->global->smtpserver);
85-
$formArray['smtpuser']->setValue($config->global->smtpuser);
86-
$formArray['smtppassword']->setValue($config->global->smtppassword);
87-
$formArray['smtpfromaddress']->setValue($config->global->smtpfromaddress);
84+
8885
if (isset($config->global->closeregistration)) {
8986
$formArray['closeregistration']->setValue($config->global->closeregistration);
9087
}
@@ -100,9 +97,6 @@ public function indexAction()
10097
if (isset($config->global->logtrace)) {
10198
$formArray['logtrace']->setValue($config->global->logtrace);
10299
}
103-
if (isset($config->global->verifyemail)) {
104-
$formArray['verifyemail']->setValue($config->global->verifyemail);
105-
}
106100
$this->view->configForm = $formArray;
107101

108102
$this->view->selectedLicense = $config->global->defaultlicense;
@@ -131,12 +125,7 @@ public function indexAction()
131125
$config->global->closeregistration = $this->getParam('closeregistration');
132126
$config->global->logtrace = $this->getParam('logtrace');
133127
$config->global->httpproxy = $this->getParam('httpProxy');
134-
$config->global->smtpserver = $this->getParam('smtpserver');
135-
$config->global->smtpuser = $this->getParam('smtpuser');
136-
$config->global->smtppassword = $this->getParam('smtppassword');
137-
$config->global->smtpfromaddress = $this->getParam('smtpfromaddress');
138128
$config->global->gravatar = $this->getParam('gravatar');
139-
$config->global->verifyemail = $this->getParam('verifyemail');
140129

141130
$writer = new Zend_Config_Writer_Ini();
142131
$writer->setConfig($config);
@@ -220,9 +209,13 @@ public function indexAction()
220209
$adapter = Zend_Registry::get('configDatabase')->database->adapter;
221210
foreach ($allModules as $key => $module) {
222211
if (file_exists(BASE_PATH."/modules/".$key."/controllers/ConfigController.php")) {
223-
$allModules[$key]->configPage = true;
212+
$allModules[$key]->configPage = 'config';
224213
} elseif (file_exists(BASE_PATH."/privateModules/".$key."/controllers/ConfigController.php")) {
225-
$allModules[$key]->configPage = true;
214+
$allModules[$key]->configPage = 'config';
215+
} elseif (file_exists(BASE_PATH."/modules/".$key."/controllers/AdminController.php")) {
216+
$allModules[$key]->configPage = 'admin';
217+
} elseif (file_exists(BASE_PATH."/privateModules/".$key."/controllers/AdminController.php")) {
218+
$allModules[$key]->configPage = 'admin';
226219
} else {
227220
$allModules[$key]->configPage = false;
228221
}

core/controllers/CommunityController.php

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -544,22 +544,23 @@ public function sendinvitationAction()
544544

545545
$url = $this->getServerURL().$this->view->webroot;
546546
$subject = 'Community Invitation';
547-
$body = $this->userSession->Dao->getFullName().' has invited you to join the <b>'.$community->getName(
548-
).'</b> community on Midas Platform.<br/><br/>'.'<a href="'.$url.'/user/emailregister?email='.$email.'&authKey='.$newuserinvite->getAuthKey(
549-
).'">Click here</a> to complete your user registration '.'if you wish to join.';
550-
if (UtilityComponent::sendEmail($email, $subject, $body)) {
551-
$this->getLogger()->debug(
552-
'User '.$this->userSession->Dao->getEmail().' emailed '.$email.' to join '.$community->getName(
553-
).' ('.$group->getName().' group)'
554-
);
547+
$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.';
548+
549+
$result = Zend_Registry::get('notifier')->callback(
550+
'CALLBACK_CORE_SEND_MAIL_MESSAGE',
551+
array(
552+
'to' => $email,
553+
'subject' => $subject,
554+
'html' => $body,
555+
'event' => 'community_invite',
556+
)
557+
);
558+
559+
if ($result) {
560+
echo JsonComponent::encode(array(true, 'Invitation sent to '.$email));
555561
} else {
556-
$this->getLogger()->warn(
557-
'Failed sending register/community invitation email to '.$email.' for community '.$community->getName(
558-
)
559-
);
562+
echo JsonComponent::encode(array(true, 'Invitation not sent'));
560563
}
561-
562-
echo JsonComponent::encode(array(true, 'Invitation sent to '.$email));
563564
}
564565
} else {
565566
throw new Zend_Exception('Must pass userId or email parameter');
@@ -586,23 +587,26 @@ private function _sendUserInvitation($userDao, $groupDao)
586587
array(false, $userDao->getFullName().$this->t(' is already invited to this community.'))
587588
);
588589
} else {
590+
$email = $userDao->getEmail();
589591
$url = $this->getServerURL().$this->view->webroot;
590592
$subject = 'Community Invitation';
591-
$body = 'You have been invited to join the <b>'.$community->getName(
592-
).'</b> community at '.$url.'.<br/><br/>'.'<a href="'.$url.'/community/'.$community->getKey(
593-
).'">'.'Click here</a> to see the community, and click the "Join the community" button '.'if you wish to join.';
594-
if (UtilityComponent::sendEmail($userDao->getEmail(), $subject, $body)
595-
) {
596-
$this->getLogger()->debug(
597-
'User '.$this->userSession->Dao->getEmail().' invited user '.$userDao->getEmail(
598-
).' to '.$community->getName().' ('.$groupDao->getName().' group)'
599-
);
593+
$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.';
594+
595+
$result = Zend_Registry::get('notifier')->callback(
596+
'CALLBACK_CORE_SEND_MAIL_MESSAGE',
597+
array(
598+
'to' => $email,
599+
'subject' => $subject,
600+
'html' => $body,
601+
'event' => 'community_invite',
602+
)
603+
);
604+
605+
if ($result) {
606+
echo JsonComponent::encode(array(true, 'Invitation sent to '.$email));
600607
} else {
601-
$this->getLogger()->warn(
602-
'Failed sending community invitation email to '.$email.' for community '.$community->getName()
603-
);
608+
echo JsonComponent::encode(array(true, 'Invitation not sent'));
604609
}
605-
echo JsonComponent::encode(array(true, $userDao->getFullName().' '.$this->t('has been invited')));
606610
}
607611
}
608612

core/controllers/UserController.php

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class UserController extends AppController
3535
'Group',
3636
'Item',
3737
'Community',
38+
'Setting',
3839
);
3940
public $_daos = array('User', 'Folder', 'Folderpolicygroup', 'Folderpolicyuser', 'Group');
4041
public $_components = array('Breadcrumb', 'Date', 'Filter', 'Sortdao');
@@ -112,20 +113,29 @@ public function recoverpasswordAction()
112113
$pass = UtilityComponent::generateRandomString(10);
113114
$this->User->changePassword($user, $pass);
114115

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

118118
$subject = "Password Request";
119-
$body = "You have requested a new password for Midas Platform.<br>";
120-
$body .= "Please go to this page to log into Midas Platform and change your password:<br>";
121-
$body .= "<a href=\"".$url."\">".$url."</a><br>";
122-
$body .= "Your new password is: ".$pass."<br>";
119+
$body = "You have requested a new password for Midas Platform.<br />";
120+
$body .= "Please go to this page to log into Midas Platform and change your password:<br />";
121+
$body .= "<a href=\"".$url."\">".$url."</a><br />";
122+
$body .= "Your new password is: ".$pass."<br />";
123+
124+
$result = Zend_Registry::get('notifier')->callback(
125+
'CALLBACK_CORE_SEND_MAIL_MESSAGE',
126+
array(
127+
'to' => $email,
128+
'subject' => $subject,
129+
'html' => $body,
130+
'event' => 'user_reset_password',
131+
)
132+
);
123133

124-
if (UtilityComponent::sendEmail($email, $subject, $body)) {
134+
if ($result) {
125135
$this->User->save($user);
126-
echo JsonComponent::encode(array(true, $this->t('Sent email to').' '.$email));
136+
echo JsonComponent::encode(array(true, 'Password request sent.'));
127137
} else {
128-
echo JsonComponent::encode(array(false, 'Could not send email'));
138+
echo JsonComponent::encode(array(false, 'Could not send password request.'));
129139
}
130140
}
131141
}
@@ -231,10 +241,9 @@ public function ajaxregisterAction()
231241
}
232242

233243
$email = strtolower(trim($form->getValue('email')));
234-
if ($adminCreate || !isset(Zend_Registry::get('configGlobal')->verifyemail) || Zend_Registry::get(
235-
'configGlobal'
236-
)->verifyemail != '1'
237-
) {
244+
$addressVerification = $this->Setting->getValueByName('address_verification', 'mail');
245+
246+
if ($adminCreate || $addressVerification != '1') {
238247
$newUser = $this->User->createUser(
239248
$email,
240249
$form->getValue('password1'),
@@ -246,14 +255,24 @@ public function ajaxregisterAction()
246255
$subject = 'User Registration';
247256
$url = $this->getServerURL().$this->view->webroot;
248257
$body = "An administrator has created a user account for you at the following Midas Platform instance:<br/><br/>";
249-
$body .= '<a href="'.$url.'">'.$url.'</a><br/><br/>';
258+
$body .= '<a href="'.$url.'">'.$url.'</a><br /><br />';
250259

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

256-
if (UtilityComponent::sendEmail($email, $subject, $body)) {
265+
$result = Zend_Registry::get('notifier')->callback(
266+
'CALLBACK_CORE_SEND_MAIL_MESSAGE',
267+
array(
268+
'to' => $email,
269+
'subject' => $subject,
270+
'html' => $body,
271+
'event' => 'user_create',
272+
)
273+
);
274+
275+
if ($result) {
257276
echo JsonComponent::encode(array('status' => 'ok', 'message' => 'User created successfully'));
258277
} else {
259278
echo JsonComponent::encode(
@@ -286,7 +305,18 @@ public function ajaxregisterAction()
286305
$body = "You have created an account on Midas Platform.<br/><br/>";
287306
$body .= '<a href="'.$url.'">Click here</a> to verify your email and complete registration.<br/><br/>';
288307
$body .= 'If you did not initiate this registration, please disregard this email.<br/><br/>';
289-
if (UtilityComponent::sendEmail($email, $subject, $body)) {
308+
309+
$result = Zend_Registry::get('notifier')->callback(
310+
'CALLBACK_CORE_SEND_MAIL_MESSAGE',
311+
array(
312+
'to' => $email,
313+
'subject' => $subject,
314+
'html' => $body,
315+
'event' => 'user_verify',
316+
)
317+
);
318+
319+
if ($result) {
290320
echo JsonComponent::encode(array('status' => 'ok', 'message' => 'Verification email sent'));
291321
} else {
292322
echo JsonComponent::encode(
@@ -314,10 +344,9 @@ public function registerAction()
314344
throw new Zend_Exception("User already exists.");
315345
}
316346

317-
if (!isset(Zend_Registry::get('configGlobal')->verifyemail) || Zend_Registry::get(
318-
'configGlobal'
319-
)->verifyemail != '1'
320-
) {
347+
$addressVerification = $this->Setting->getValueByName('address_verification', 'mail');
348+
349+
if ($addressVerification != '1') {
321350
if (!headers_sent()) {
322351
session_start();
323352
}
@@ -345,7 +374,18 @@ public function registerAction()
345374
$body = "You have created an account on Midas Platform.<br/><br/>";
346375
$body .= '<a href="'.$url.'">Click here</a> to verify your email and complete registration.<br/><br/>';
347376
$body .= 'If you did not initiate this registration, please disregard this email.<br/><br/>';
348-
if (UtilityComponent::sendEmail($email, $subject, $body)) {
377+
378+
$result = Zend_Registry::get('notifier')->callback(
379+
'CALLBACK_CORE_SEND_MAIL_MESSAGE',
380+
array(
381+
'to' => $email,
382+
'subject' => $subject,
383+
'html' => $body,
384+
'event' => 'user_verify',
385+
)
386+
);
387+
388+
if ($result) {
349389
$this->redirect('/user/emailsent');
350390
}
351391
}

0 commit comments

Comments
 (0)