Test out existing email functionality

This commit is contained in:
Duncan Sommerville 2015-07-22 11:19:37 -04:00
parent 1816be156f
commit a1a2bf9368
3 changed files with 39 additions and 96 deletions

View File

@ -140,43 +140,43 @@ class LoginController extends Zend_Controller_Action
Application_Model_Locale::configureLocalization($request->getcookie('airtime_locale', $stationLocale));
if (!Application_Model_Preference::GetEnableSystemEmail()) {
$this->_redirect('login');
} else {
//uses separate layout without a navigation.
$this->_helper->layout->setLayout('login');
// if (!Application_Model_Preference::GetEnableSystemEmail()) {
// $this->_redirect('login');
// } else {
//uses separate layout without a navigation.
$this->_helper->layout->setLayout('login');
$form = new Application_Form_PasswordRestore();
$form = new Application_Form_PasswordRestore();
$request = $this->getRequest();
if ($request->isPost() && $form->isValid($request->getPost())) {
if (is_null($form->username->getValue()) || $form->username->getValue() == '') {
$user = CcSubjsQuery::create()
->filterByDbEmail($form->email->getValue())
->findOne();
} else {
$user = CcSubjsQuery::create()
->filterByDbEmail($form->email->getValue())
->filterByDbLogin($form->username->getValue())
->findOne();
}
if (!empty($user)) {
$auth = new Application_Model_Auth();
$success = $auth->sendPasswordRestoreLink($user, $this->view);
if ($success) {
$this->_helper->redirector('password-restore-after', 'login');
} else {
$form->email->addError($this->view->translate(_("Email could not be sent. Check your mail server settings and ensure it has been configured properly.")));
}
} else {
$form->email->addError($this->view->translate(_("Given email not found.")));
}
$request = $this->getRequest();
if ($request->isPost() && $form->isValid($request->getPost())) {
if (is_null($form->username->getValue()) || $form->username->getValue() == '') {
$user = CcSubjsQuery::create()
->filterByDbEmail($form->email->getValue())
->findOne();
} else {
$user = CcSubjsQuery::create()
->filterByDbEmail($form->email->getValue())
->filterByDbLogin($form->username->getValue())
->findOne();
}
$this->view->form = $form;
if (!empty($user)) {
$auth = new Application_Model_Auth();
$success = $auth->sendPasswordRestoreLink($user, $this->view);
if ($success) {
$this->_helper->redirector('password-restore-after', 'login');
} else {
$form->email->addError($this->view->translate(_("Email could not be sent. Check your mail server settings and ensure it has been configured properly.")));
}
} else {
$form->email->addError($this->view->translate(_("Given email not found.")));
}
}
$this->view->form = $form;
// }
}
public function passwordRestoreAfterAction()

View File

@ -12,65 +12,8 @@ class Application_Model_Email
*/
public static function send($subject, $message, $tos, $from = null)
{
$mailServerConfigured = Application_Model_Preference::GetMailServerConfigured() == true ? true : false;
$mailServerRequiresAuth = Application_Model_Preference::GetMailServerRequiresAuth() == true ? true : false;
$success = true;
if ($mailServerConfigured) {
$mailServer = Application_Model_Preference::GetMailServer();
$mailServerPort = Application_Model_Preference::GetMailServerPort();
if (!empty($mailServerPort)) {
$port = $mailServerPort;
}
if ($mailServerRequiresAuth) {
$username = Application_Model_Preference::GetMailServerEmailAddress();
$password = Application_Model_Preference::GetMailServerPassword();
$config = array(
'auth' => 'login',
'ssl' => 'ssl',
'username' => $username,
'password' => $password
);
} else {
$config = array(
'ssl' => 'tls'
);
}
if (isset($port)) {
$config['port'] = $port;
}
$transport = new Zend_Mail_Transport_Smtp($mailServer, $config);
}
$mail = new Zend_Mail('utf-8');
$mail->setSubject($subject);
$mail->setBodyText($message);
foreach ((array) $tos as $to) {
$mail->addTo($to);
}
if ($mailServerConfigured) {
$mail->setFrom(isset($from) ? $from : Application_Model_Preference::GetMailServerEmailAddress());
try {
$mail->send($transport);
} catch (Exception $e) {
$success = false;
}
} else {
$mail->setFrom(isset($from) ? $from : Application_Model_Preference::GetSystemEmail());
try {
$mail->send();
} catch (Exception $e) {
$success = false;
}
}
return $success;
return mail($tos, $subject, $message);
}
}

View File

@ -30,12 +30,12 @@
<?php echo $this->element->getElement('csrf') ?>
<?php if (Application_Model_Preference::GetEnableSystemEmail()): ?>
<dt id="reset-label" class="hidden">&nbsp;</dt>
<dd id="reset-element" class="text-right">
<a href="<?php echo $this->baseUrl('login/password-restore'); ?>" class="link reset"><?php echo _("Reset password") ?></a>
</dd>
<?php endif; ?>
<!-- --><?php //if (Application_Model_Preference::GetEnableSystemEmail()): ?>
<dt id="reset-label" class="hidden">&nbsp;</dt>
<dd id="reset-element" class="text-right">
<a href="<?php echo $this->baseUrl('login/password-restore'); ?>" class="link reset"><?php echo _("Reset password") ?></a>
</dd>
<!-- --><?php //endif; ?>
<?php echo $this->element->getElement('captcha') ?>
<dt id="submit-label">&nbsp;</dt>
<dd id="submit-element">