コード例 #1
0
ファイル: EmailController.php プロジェクト: bjtenao/tudu-web
 /**
  * 更新绑定邮箱
  */
 public function updateAction()
 {
     $post = $this->_request->getPost();
     $address = isset($post['address']) ? $post['address'] : null;
     $password = trim($post['password']);
     $port = !empty($post['port']) ? $post['port'] : null;
     if (!trim($post['host'])) {
         return $this->json(false, $this->lang['missing_email_host'], array('advance' => true));
     }
     if (!Oray_Function::isDomainName($post['host']) && !Oray_Function::isIp($post['host'])) {
         return $this->json(false, sprintf($this->lang['invalid_imap_host'], strtoupper($post['protocol'])), array('advance' => true));
     }
     if ($port != null) {
         if ($port <= 0 || $port > 65535) {
             return $this->json(false, sprintf($this->lang['invalid_imap_port'], strtoupper($post['protocol'])));
         }
     }
     $email = $this->_daoEmail->getEmailByAddress($this->_user->orgId, $this->_user->userId, $address);
     if (null === $email) {
         return $this->json(false, $this->lang['mailbox_not_exists']);
     }
     $checkPwd = $email->password;
     $isSsl = isset($post['isssl']) && $post['isssl'] == 1 ? 1 : 0;
     $type = isset($post['type']) ? (int) $post['type'] : 0;
     $params = array('protocol' => $post['protocol'], 'host' => $post['host'], 'port' => (int) $post['port'] > 0 ? (int) $post['port'] : null, 'isssl' => $isSsl, 'type' => $type);
     if (!empty($password)) {
         $params['password'] = $password;
         $checkPwd = $password;
     }
     /**
      * 验证邮箱密码
      */
     if (!$this->_validMailbox($address, $checkPwd, $params['host'], $params['port'], (bool) $isSsl, $post['protocol'])) {
         return $this->json(false);
     }
     $ret = $this->_daoEmail->updateEmail($this->_user->orgId, $this->_user->userId, $address, $params);
     if (!$ret) {
         return $this->json(false, $this->lang['update_mailbox_failure']);
     }
     return $this->json(true, $this->lang['update_mailbox_success']);
 }
コード例 #2
0
 /**
  * 保存邮箱
  */
 public function savemailboxAction()
 {
     $post = $this->_request->getPost();
     $bind = false;
     $daoUser = $this->getMdDao('Dao_Md_User_User');
     $mailBox = $daoUser->getMailbox($this->_user->orgId, $this->_user->userId);
     if (!empty($post['address']) || !empty($post['password']) || !empty($post['imaphost'])) {
         $bind = true;
         if (empty($post['address']) || !Oray_Function::isEmail($post['address'])) {
             return $this->json(false, $this->lang['invalid_email_address']);
         }
         if (empty($post['password']) && !$mailBox) {
             return $this->json(false, $this->lang['missing_email_password']);
         }
         if (!empty($post['imaphost']) && (!Oray_Function::isDomainName($post['imaphost']) && !Oray_Function::isIp($post['imaphost']))) {
             return $this->json(false, $this->lang['invalid_imap_host']);
         }
         if ($post['port'] != '') {
             if ((int) $post['port'] <= 0 || (int) $post['port'] > 65535) {
                 return $this->json(false, $this->lang['invalid_imap_port']);
             }
         }
     }
     if ($bind) {
         $isSsl = isset($post['isssl']) && $post['isssl'] == 1 ? 1 : 0;
         $type = isset($post['type']) ? (int) $post['type'] : 0;
         if (null !== $mailBox) {
             $params = array('address' => $post['address'], 'imaphost' => $post['imaphost'], 'port' => (int) $post['port'] > 0 ? (int) $post['port'] : null, 'isssl' => $isSsl, 'type' => $type);
             if (!empty($post['password'])) {
                 $params['password'] = $post['password'];
             }
             $ret = $daoUser->updateMailbox($this->_user->orgId, $this->_user->userId, $params);
         } else {
             $ret = $daoUser->addMailbox(array('orgid' => $this->_user->orgId, 'userid' => $this->_user->userId, 'address' => $post['address'], 'imaphost' => $post['imaphost'], 'password' => $post['password'], 'port' => (int) $post['port'] > 0 ? (int) $post['port'] : null, 'isssl' => $isSsl, 'type' => $type));
         }
     } else {
         $ret = $daoUser->removeMailbox($this->_user->orgId, $this->_user->userId);
     }
     if (!$ret) {
         return $this->json(false, $this->lang['update_mailbox_failure']);
     }
     return $this->json(true, $this->lang['update_mailbox_success']);
 }