コード例 #1
0
ファイル: Sendgrid.php プロジェクト: sakibanda/emarketing
 /**
  * Check login data and return true on success
  * or string with error message
  * 
  * @param string $username
  * @param string $password
  * @return string|true
  */
 public function testAuth($username, $password)
 {
     $connection = new Zend_Mail_Protocol_Smtp_Auth_Login(self::HOST, self::PORT, array('username' => $username, 'password' => $password, 'port' => self::PORT, 'ssl' => self::SSL));
     try {
         $connection->connect();
         $connection->helo(Mage::app()->getRequest()->getServer('SERVER_ADDR'));
         $connection->disconnect();
         return true;
     } catch (Exception $e) {
         return $e->getMessage();
     }
 }
コード例 #2
0
 /**
  * Performs an authentication attempt
  *
  * @throws Zend_Auth_Adapter_Exception If authentication cannot be performed
  * @return Zend_Auth_Result
  */
 public function authenticate()
 {
     $config = new Zend_Config_Ini('../config/zportal.ini', 'mail');
     $mailConfig = array('auth' => 'login', 'username' => $this->name, 'password' => $this->password);
     $login = new Zend_Mail_Protocol_Smtp_Auth_Login($config->mail->get('server'), null, $mailConfig);
     $login->connect();
     try {
         $login->helo("localhost");
     } catch (Exception $e) {
         // unauth user
         $result = Zend_Auth_Result::FAILURE;
         $identity = $this->name;
         $message = 'Authentication failed. Please check your login details or call system admin.';
         return new Zend_Auth_Result($result, $identity, array($message));
     }
     // create result array
     $users = new Users();
     $email = strtolower($this->name . "@zend.com");
     $user = $users->getByEmail($email);
     // if first time visit
     if (!$user) {
         // add record to users
         $users->addUser(array('email' => $email, 'role' => 'member'));
         $user = $users->getByEmail($email);
         // send welcome page
         $bodyHtml = 'Dear User<br>Welcome to ZPortal.<br>';
         $config = new Zend_Config_Ini('../config/zportal.ini', 'mail');
         $transport = new Zend_Mail_Transport_Smtp($config->mail->get('server'), $mailConfig);
         $mail = new Zend_Mail();
         $mail->setBodyText("See html attachment");
         $mail->setBodyHtml($bodyHtml, 'UTF-8', Zend_Mime::ENCODING_BASE64);
         $mail->setFrom('*****@*****.**', 'ZPortal');
         $mail->addTo($email, $email);
         $mail->setSubject('Welcome to ZPortal');
         $mail->send($transport);
     }
     $result = Zend_Auth_Result::SUCCESS;
     $identity = $user;
     $message = '';
     return new Zend_Auth_Result($result, $identity, array($message));
 }
コード例 #3
0
 public function testconnectionAction()
 {
     $result = AW_Advancednewsletter_Model_Form_Element_Testconnection::STATUS_FAIL;
     $data = $this->getRequest()->getParams();
     if (!isset($data['server_name']) || $data['server_name'] === '' || !isset($data['port']) || (int) $data['port'] == 0 || !isset($data['user_name']) || $data['user_name'] === '' || !isset($data['password']) || $data['password'] === '' || !isset($data['usessl'])) {
         $result = array('result' => $result);
         $this->getResponse()->setBody(Zend_Json::encode($result));
         return $this;
     }
     $configMail = array('auth' => 'login', 'username' => $data['user_name'], 'password' => $data['password'], 'ssl' => 'tls', 'port' => (int) $data['port']);
     if (!$data['usessl']) {
         unset($configMail['ssl']);
     }
     try {
         $connection = new Zend_Mail_Protocol_Smtp_Auth_Login($data['server_name'], $data['port'], $configMail);
         $connection->connect();
         $connection->helo();
         $result = AW_Advancednewsletter_Model_Form_Element_Testconnection::STATUS_SUCCESS;
     } catch (Exception $exc) {
         $result = AW_Advancednewsletter_Model_Form_Element_Testconnection::STATUS_FAIL;
     }
     $result = array('result' => $result);
     $this->getResponse()->setBody(Zend_Json::encode($result));
     return $this;
 }