Inheritance: extends ViMbAdmin_Form
コード例 #1
0
ファイル: AdminController.php プロジェクト: Danny-P/ViMbAdmin
 /**
  * Adds a new admin or superadmin to the system. Optionally it can send a welcome email.
  */
 public function addAction()
 {
     $this->view->form = $form = new ViMbAdmin_Form_Admin_AddEdit();
     $form->removeElement('salt');
     if ($this->getRequest()->isPost() && $form->isValid($_POST)) {
         $this->_targetAdmin = new \Entities\Admin();
         $this->getD2EM()->persist($this->getTargetAdmin());
         $form->assignFormToEntity($this->getTargetAdmin(), $this, false);
         $this->getTargetAdmin()->setCreated(new \DateTime());
         $password = $this->getTargetAdmin()->getPassword();
         $this->getTargetAdmin()->setPassword(OSS_Auth_Password::hash($password, $this->_options['resources']['auth']['oss']));
         $this->log(\Entities\Log::ACTION_ADMIN_ADD, "{$this->getAdmin()->getFormattedName()} added admin {$this->getTargetAdmin()->getFormattedName()}");
         $this->getD2EM()->flush();
         if ($form->getValue('welcome_email')) {
             $mailer = $this->getMailer();
             $mailer->setSubject('ViMbAdmin :: Your New Administrator Account');
             $mailer->addTo($this->getTargetAdmin()->getUsername());
             $mailer->setFrom($this->_options['server']['email']['address'], $this->_options['server']['email']['name']);
             $this->view->username = $this->getTargetAdmin()->getUsername();
             $this->view->password = $form->getValue('password');
             $mailer->setBodyText($this->view->render('admin/email/new_admin.phtml'));
             try {
                 $mailer->send();
             } catch (Exception $e) {
                 $this->getLogger()->debug($e->getTraceAsString());
                 $this->addMessage('Could not send welcome email', OSS_Message::ALERT);
             }
         }
         $this->addMessage(_('You have successfully added a new administrator to the system.'), OSS_Message::SUCCESS);
         $this->_redirect('admin/list');
     }
 }
コード例 #2
0
ファイル: AuthController.php プロジェクト: Danny-P/ViMbAdmin
 public function setupAction()
 {
     if ($this->getD2EM()->getRepository('\\Entities\\Admin')->getCount() != 0) {
         $this->addMessage(_("Admins already exist in the system."), OSS_Message::INFO);
         $this->_redirect('auth/login');
     }
     if ($this->getAuth()->getIdentity()) {
         $this->addMessage(_('You are already logged in.'), OSS_Message::INFO);
         $this->_redirect('domain/list');
     }
     $this->view->form = $form = new ViMbAdmin_Form_Admin_AddEdit();
     $form->removeElement('active');
     $form->removeElement('super');
     $form->removeElement('welcome_email');
     if (!isset($this->_options['securitysalt']) || strlen($this->_options['securitysalt']) != 64) {
         $this->view->saltSet = false;
         $randomSalt = $this->view->randomSalt = OSS_String::salt(64);
         $form->getElement('salt')->setValue($randomSalt);
         $this->view->rememberSalt = OSS_String::salt(64);
         $this->view->passwordSalt = OSS_String::salt(64);
     } else {
         $this->view->saltSet = true;
         if ($this->getRequest()->isPost() && $form->isValid($_POST)) {
             if ($form->getElement('salt')->getValue() != $this->_options['securitysalt']) {
                 $this->addMessage(_("Incorrect security salt provided. Please copy and paste it from the <code>application.ini</code> file."), OSS_Message::INFO);
             } else {
                 $admin = new \Entities\Admin();
                 $admin->setUsername($form->getValue('username'));
                 $admin->setPassword(OSS_Auth_Password::hash($form->getValue('password'), $this->_options['resources']['auth']['oss']));
                 $admin->setSuper(true);
                 $admin->setActive(true);
                 $admin->setCreated(new \DateTime());
                 $admin->setModified(new \DateTime());
                 $this->getD2EM()->persist($admin);
                 // we need to populate the Doctine migration table
                 $dbversion = new \Entities\DatabaseVersion();
                 $dbversion->setVersion(ViMbAdmin_Version::DBVERSION);
                 $dbversion->setName(ViMbAdmin_Version::DBVERSION_NAME);
                 $dbversion->setAppliedOn(new \DateTime());
                 $this->getD2EM()->persist($dbversion);
                 $this->getD2EM()->flush();
                 try {
                     $mailer = $this->getMailer();
                     $mailer->setSubject(_('ViMbAdmin :: Your New Administrator Account'));
                     $mailer->addTo($admin->getUsername());
                     $mailer->setFrom($this->_options['server']['email']['address'], $this->_options['server']['email']['name']);
                     $this->view->username = $admin->getUsername();
                     $this->view->password = $form->getValue('password');
                     $mailer->setBodyText($this->view->render('admin/email/new_admin.phtml'));
                     $mailer->send();
                 } catch (Zend_Mail_Exception $e) {
                     $this->addMessage(_('Could not send welcome email to the new administrator. 
                         Please ensure you have configured a mail relay server in your <code>application.ini</code>.'), OSS_Message::ALERT);
                 }
                 $this->addMessage(_('Your administrator account has been added. Please log in below.'), OSS_Message::SUCCESS);
             }
             if (!(isset($this->_options['skipInstallPingback']) && $this->_options['skipInstallPingback'])) {
                 try {
                     // Try and track new installs to see if it is worthwhile continuing development
                     include_once APPLICATION_PATH . '/../public/PiwikTracker.php';
                     if (class_exists('PiwikTracker')) {
                         if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
                             PiwikTracker::$URL = 'https://stats.opensolutions.ie/';
                         } else {
                             PiwikTracker::$URL = 'http://stats.opensolutions.ie/';
                         }
                         $piwikTracker = new PiwikTracker($idSite = 5);
                         $piwikTracker->doTrackPageView('New V3 Install Completed');
                         $piwikTracker->doTrackGoal($idGoal = 2, $revenue = 1);
                     }
                 } catch (Exception $e) {
                 }
             }
             $this->_redirect('auth/login');
         }
     }
 }