public function postValidateForm($validator, $values)
 {
     if (isset($values['promo_code'])) {
         $promo_code = PromoCodeTable::getInstance()->findOneByCode($values['promo_code']);
         if (!$promo_code) {
             throw new sfValidatorError($validator, 'Promotion Code is invalid');
         } else {
             $values['account_type'] = $promo_code->account_type;
         }
     }
     /** @var sfGuardUser $user */
     $user = sfGuardUserTable::getInstance()->createQuery('u')->where('u.email_address = ?', $values['email_address'])->fetchOne();
     if ($user && $values['password']) {
         if ($user->getIsActive() && $user->checkPassword($values['password'])) {
             sfContext::getInstance()->getUser()->signIn($user);
             sfContext::getInstance()->getController()->redirect('/project');
         } else {
             throw new sfValidatorError($validator, 'The email and/or password is invalid');
         }
     }
     $email = $values['email_address'];
     $domain = strtolower(substr($email, strpos($email, '@') + 1));
     if (DomainTable::getInstance()->findOneBy('name', $domain)) {
         $error = new sfValidatorError($validator, 'That looks like a personal email address. Please use your company email.');
         throw new sfValidatorErrorSchema($validator, array('email_address' => $error));
     }
     return $values;
 }
 public function verifyEmailDomain($validator, $values)
 {
     $email = $values['email_address'];
     $domain = strtolower(substr($email, strpos($email, '@') + 1));
     if (DomainTable::getInstance()->findOneBy('name', $domain)) {
         $error = new sfValidatorError($validator, 'That looks like a personal email address. Please use your company email.');
         throw new sfValidatorErrorSchema($validator, array('email_address' => $error));
     }
     return $values;
 }
示例#3
0
 /**
  * Edit a mailbox.
  */
 public function editAction()
 {
     if (!$this->_mailbox) {
         $this->_mailbox = new Mailbox();
     }
     $this->view->mailboxModel = $this->_mailbox;
     $domainList = DomainTable::getDomains($this->getAdmin());
     $editForm = new ViMbAdmin_Form_Mailbox_Edit(null, $domainList);
     $editForm->setDefaults($this->_mailbox->toArray());
     if ($this->_mailbox['id']) {
         $editForm->removeElement('password');
         $editForm->getElement('local_part')->setAttrib('disabled', 'disabled')->setRequired(false);
         $editForm->getElement('domain')->setAttrib('disabled', 'disabled')->setRequired(false);
     } else {
         $editForm->getElement('domain')->setValue($this->_domain->id);
     }
     if ($this->getRequest()->isPost() && $editForm->isValid($_POST)) {
         do {
             // do we have a domain
             if (!$this->_domain) {
                 $this->_domain = Doctrine::getTable('Domain')->find($editForm->getElement('domain')->getValue());
                 if (!$this->_domain || !$this->authorise(false, $this->_domain, false)) {
                     $this->addMessage(_("Invalid, unauthorised or non-existent domain."), ViMbAdmin_Message::ERROR);
                     $this->_redirect('domain/list');
                 }
             }
             if ($this->_mailbox['id']) {
                 $this->_domain = $this->_mailbox->Domain;
                 $editForm->removeElement('local_part');
                 $editForm->removeElement('domain');
                 $editForm->removeElement('password');
                 $this->_mailbox->fromArray($editForm->getValues());
                 $op = 'edit';
             } else {
                 // do we have available mailboxes?
                 if (!$this->getAdmin()->isSuper() && $this->_domain['mailboxes'] != 0 && $this->_domain->countMailboxes() >= $this->_domain['mailboxes']) {
                     $this->_helper->viewRenderer->setNoRender(true);
                     $this->addMessage(_('You have used all of your allocated mailboxes.'), ViMbAdmin_Message::ERROR);
                     break;
                 }
                 $this->_mailbox->fromArray($editForm->getValues());
                 $this->_mailbox['domain'] = $this->_domain['domain'];
                 $this->_mailbox['username'] = "******";
                 $this->_mailbox['homedir'] = $this->_options['defaults']['mailbox']['homedir'];
                 $this->_mailbox['uid'] = $this->_options['defaults']['mailbox']['uid'];
                 $this->_mailbox['gid'] = $this->_options['defaults']['mailbox']['gid'];
                 $this->_mailbox->formatMaildir($this->_options['defaults']['mailbox']['maildir']);
                 $plainPassword = $this->_mailbox['password'];
                 $this->_mailbox->hashPassword($this->_options['defaults']['mailbox']['password_scheme'], $this->_mailbox['password'], $this->_options['defaults']['mailbox']['password_hash']);
                 // is the mailbox address valid?
                 if (!Zend_Validate::is("{$this->_mailbox['local_part']}@{$this->_mailbox['domain']}", 'EmailAddress', array(1, null))) {
                     $editForm->getElement('local_part')->addError(_('Invalid email address.'));
                     break;
                 }
                 // does a mailbox of the same name exist?
                 $dup = Doctrine_Query::create()->from('Mailbox m')->where('m.local_part = ?', $this->_mailbox['local_part'])->andWhere('m.domain = ?', $this->_mailbox['domain'])->execute(null, Doctrine_Core::HYDRATE_ARRAY);
                 if (count($dup)) {
                     $this->addMessage(_('Mailbox already exists for') . " {$this->_mailbox['local_part']}@{$this->_mailbox['domain']}", ViMbAdmin_Message::ERROR);
                     break;
                 }
                 if ($this->_options['mailboxAliases'] == 1) {
                     $aliasModel = new Alias();
                     $aliasModel->address = $this->_mailbox['username'];
                     $aliasModel->goto = $this->_mailbox['username'];
                     $aliasModel->domain = $this->_domain['domain'];
                     $aliasModel->active = 1;
                     $aliasModel->save();
                 }
                 $op = 'add';
             }
             // check quota
             if ($this->_domain['quota'] != 0) {
                 if ($this->_mailbox['quota'] <= 0 || $this->_mailbox['quota'] > $this->_domain['quota']) {
                     $this->_mailbox['quota'] = $this->_domain['quota'];
                     $this->addMessage(_("Mailbox quota set to ") . $this->_domain['quota'], ViMbAdmin_Message::ALERT);
                 }
             }
             $this->_mailbox->save();
             if ($editForm->getValue('welcome_email')) {
                 if (!$this->_sendSettingsEmail($editForm->getValue('cc_welcome_email') ? $editForm->getValue('cc_welcome_email') : false, $plainPassword, true)) {
                     $this->addMessage(_('Could not sent welcome email'), ViMbAdmin_Message::ALERT);
                 }
             }
             LogTable::log('MAILBOX_' . ($op == 'add' ? 'ADD' : 'EDIT'), print_r($this->_mailbox->toArray(), true), $this->getAdmin(), $this->_mailbox['domain']);
             $this->_helper->viewRenderer->setNoRender(true);
             $this->addMessage(_('You have successfully added/edited the mailbox record.'), ViMbAdmin_Message::SUCCESS);
             return print $this->view->render('close_colorbox_reload_parent.phtml');
         } while (false);
         // break-able clause
     }
     if ($this->_domain) {
         $editForm->getElement('domain')->setValue($this->_domain['id']);
     }
     $this->view->editForm = $editForm;
 }
示例#4
0
 /**
  * Adds a new domain to the admin.
  */
 public function addDomainAction()
 {
     if (!$this->_targetAdmin) {
         $this->addMessage(_('Invalid or missing admin id.'), ViMbAdmin_Message::ERROR);
         return false;
     }
     $adminDomains = DomainAdminTable::getAllowedDomains($this->_targetAdmin);
     $allDomains = DomainTable::getDomains($this->_admin);
     $remainingDomains = array_diff($allDomains, $adminDomains);
     $form = new ViMbAdmin_Form_Admin_AddDomain(null, $remainingDomains, $this->_targetAdmin);
     if ($this->getRequest()->isPost() && $form->isValid($_POST)) {
         $domainId = $form->getValue('domain');
         $domain = Doctrine::getTable('Domain')->find($domainId);
         if (!$domain) {
             $this->addMessage(_('Invalid or missing domain id.'), ViMbAdmin_Message::ERROR);
         } elseif (array_key_exists($domainId, $adminDomains)) {
             $this->addMessage(_('This domain is already assigned to the admin.'), ViMbAdmin_Message::ERROR);
         } else {
             $domain->addAdmin($this->_targetAdmin);
             unset($remainingDomains[$domainId]);
             $form = new ViMbAdmin_Form_Admin_AddDomain(null, $remainingDomains, $this->_targetAdmin);
             $this->addMessage(_('You have successfully assigned a domain to the admin.'), ViMbAdmin_Message::SUCCESS);
         }
     }
     if (sizeof($remainingDomains) == 0) {
         $this->addMessage(_('There is no domain to assign to this admin.'), ViMbAdmin_Message::INFO);
     }
     $this->view->form = $form;
 }
示例#5
0
 /**
  * Edit an alias.
  */
 public function editAction()
 {
     if (!$this->_alias) {
         $this->_alias = new Alias();
         if ($this->_domain) {
             $this->view->domainModel = $this->_domain;
         }
     } else {
         // if editing, then use that domain
         $this->view->domainModel = $this->_alias['Domain'];
     }
     $this->view->aliasModel = $this->_alias;
     $domainList = DomainTable::getDomains($this->getAdmin());
     $this->view->domainList = $domainList;
     $editForm = new ViMbAdmin_Form_Alias_Edit(null, $domainList);
     if ($this->getRequest()->isPost()) {
         if ($this->_alias['id']) {
             $editForm->removeElement('local_part');
             $editForm->removeElement('domain');
         }
         if ($editForm->isValid($_POST)) {
             $postValues = $editForm->getValues();
             if (isset($postValues['domain'])) {
                 $this->_domain = $this->loadDomain($postValues['domain']);
             }
             if (!$this->_domain || !$this->authorise(false, $this->_domain, false)) {
                 $this->addMessage(_("Invalid, unauthorised or non-existent domain."), ViMbAdmin_Message::ERROR);
                 $this->_redirect($this->getRequest()->getPathInfo());
             }
             if (!$this->_alias['id']) {
                 $alias = Doctrine::getTable('Alias')->findOneByAddress("{$postValues['local_part']}@{$this->_domain['domain']}");
                 if ($alias) {
                     if ($this->_options['mailboxAliases']) {
                         if ($alias->address == $alias->goto) {
                             $this->addMessage(_('A mailbox alias exists for') . " {$postValues['local_part']}@{$this->_domain['domain']}", ViMbAdmin_Message::ERROR);
                         } else {
                             $this->addMessage(_('Alias already exists for') . " {$postValues['local_part']}@{$this->_domain['domain']}", ViMbAdmin_Message::ERROR);
                         }
                     } else {
                         $this->addMessage(_('Alias already exists for') . " {$postValues['local_part']}@{$this->_domain['domain']}", ViMbAdmin_Message::ERROR);
                     }
                     $this->_redirect($this->getRequest()->getPathInfo());
                 }
             }
             if (!$postValues['goto']) {
                 $editForm->getElement('goto')->addError(_('You must have at least one goto address.'));
             } else {
                 // is the alias valid (allowing for wildcard domains (i.e. with no local part)
                 if (!$this->_alias['id'] && $postValues['local_part'] != '' && !Zend_Validate::is("{$postValues['local_part']}@{$this->_domain['domain']}", 'EmailAddress', array(1, null))) {
                     $editForm->getElement('local_part')->addError(_('Invalid email address.'));
                 }
                 foreach ($postValues['goto'] as $key => $oneGoto) {
                     $oneGoto = trim($oneGoto);
                     if ($oneGoto == '') {
                         unset($postValues['goto'][$key]);
                     } else {
                         if (!Zend_Validate::is($oneGoto, 'EmailAddress', array(1, null))) {
                             $editForm->getElement('goto')->addError(_('Invalid email address(es).'));
                         }
                     }
                 }
                 if (!$postValues['goto']) {
                     $editForm->getElement('goto')->addError(_('You must have at least one goto address.'));
                 }
                 if (!$editForm->getElement('goto')->hasErrors() && ($editForm->getElement('local_part') === null || !$editForm->getElement('local_part')->hasErrors())) {
                     $this->_alias->fromArray($postValues);
                     if (!$this->_alias['id']) {
                         // do we have available mailboxes?
                         if (!$this->getAdmin()->isSuper() && $this->_domain['aliases'] != 0 && $this->_domain->countAliases() >= $this->_domain['aliases']) {
                             $this->_helper->viewRenderer->setNoRender(true);
                             $this->addMessage(_('You have used all of your allocated aliases.'), ViMbAdmin_Message::ERROR);
                             return print $this->view->render('close_colorbox_reload_parent.phtml');
                         }
                         $this->_alias['domain'] = $this->_domain['domain'];
                         $this->_alias['address'] = "{$postValues['local_part']}@{$this->_domain['domain']}";
                         LogTable::log('ALIAS_ADD', "Added {$this->_alias['address']} -> {$this->_alias['goto']}", $this->getAdmin(), $this->_alias['domain']);
                     } else {
                         LogTable::log('ALIAS_EDIT', "Edited {$this->_alias['address']} -> {$this->_alias['goto']}", $this->getAdmin(), $this->_alias['domain']);
                     }
                     $this->_alias['goto'] = implode(',', array_unique($postValues['goto']));
                     $this->_alias->save();
                     $this->_helper->viewRenderer->setNoRender(true);
                     $this->addMessage(_('You have successfully added/edited the alias.'), ViMbAdmin_Message::SUCCESS);
                     return print $this->view->render('close_colorbox_reload_parent.phtml');
                 }
             }
         }
     } else {
         if ($this->_domain) {
             $editForm->getElement('domain')->setValue($this->_domain->id);
         }
         if ($this->_mailbox) {
             $this->view->defaultGoto = "{$this->_mailbox->local_part}@{$this->_mailbox->Domain->domain}";
         }
         if ($this->_alias['id']) {
             $editForm->setDefaults($this->_alias->toArray());
             $editForm->getElement('local_part')->setValue(str_replace("@{$this->_alias['domain']}", '', $this->_alias['address']))->setAttrib('disabled', 'disabled');
             $editForm->getElement('domain')->setAttrib('disabled', 'disabled');
         }
     }
     if ($this->_domain) {
         $editForm->getElement('domain')->setValue($this->_domain['id']);
     }
     $this->view->editForm = $editForm;
 }