Exemplo n.º 1
0
 public function setupAction()
 {
     $form = new ViMbAdmin_Form_Admin_Edit();
     $form->removeElement('active');
     $form->removeElement('super');
     $form->removeElement('welcome_email');
     if ($this->getAuth()->getIdentity()) {
         $this->addMessage(_('You are already logged in.'), ViMbAdmin_Message::INFO);
         $this->_redirect('domain/list');
     }
     if ($this->_options['securitysalt'] == '') {
         $charSet = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
         $randomSalt = substr(str_shuffle("{$charSet}{$charSet}"), 0, 31);
         // please note this is not UTF-8 compatible
         $this->view->saltSet = false;
         $this->view->randomSalt = $randomSalt;
         $form->getElement('salt')->setValue($randomSalt);
     } elseif (!AdminTable::isEmpty()) {
         $this->addMessage(_("Admins already exist in the system."), ViMbAdmin_Message::INFO);
         $this->_redirect('auth/login');
     } 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."), ViMbAdmin_Message::INFO);
             } else {
                 $admin = new Admin();
                 $admin['username'] = $form->getValue('username');
                 $admin->setPassword($form->getValue('password'), $this->_options['securitysalt'], false);
                 $admin->super = true;
                 $admin->active = true;
                 $admin->save();
                 try {
                     $mailer = new Zend_Mail();
                     $mailer->setSubject(_('ViMbAdmin :: Your New Administrator Account'));
                     $mailer->addTo($admin['username']);
                     $mailer->setFrom($this->_options['server']['email']['address'], $this->_options['server']['email']['name']);
                     $this->view->username = $admin['username'];
                     $this->view->password = $form->getValue('password');
                     $mailer->setBodyText($this->view->render('admin/email/new_admin.phtml'));
                     $mailer->send();
                 } catch (Exception $e) {
                 }
                 $this->addMessage(_('Your administrator account has been added. Please log in below.'), ViMbAdmin_Message::SUCCESS);
             }
             // Try and track new installs to see if it is worthwhile continueing development
             include_once APPLICATION_PATH . '/../public/PiwikTracker.php';
             if (class_exists('PiwikTracker')) {
                 if ($_SERVER['HTTPS'] == 'on') {
                     PiwikTracker::$URL = 'https://stats.opensolutions.ie/';
                 } else {
                     PiwikTracker::$URL = 'http://stats.opensolutions.ie/';
                 }
                 $piwikTracker = new PiwikTracker($idSite = 5);
                 $piwikTracker->doTrackPageView('Nes Install Completed');
                 $piwikTracker->doTrackGoal($idGoal = 1, $revenue = 0);
             }
             $this->_helper->viewRenderer->setNoRender(true);
             $this->_redirect('auth/login');
         }
     }
     $this->view->form = $form;
 }