Beispiel #1
0
 /**
  * Adds a new admin or superadmin to the system. Optionally it can send a welcome email.
  */
 public function addAction()
 {
     $form = new ViMbAdmin_Form_Admin_Edit();
     $form->removeElement('salt');
     if ($this->getRequest()->isPost() && $form->isValid($_POST)) {
         $adminModel = new Admin();
         $adminModel->fromArray($form->getValues());
         $adminModel->setPassword($form->getValue('password'), $this->_options['securitysalt'], false);
         $adminModel->save();
         LogTable::log('ADMIN_ADD', "Added new " . ($adminModel['super'] ? 'super ' : '') . "admin {$adminModel['username']}", $this->getAdmin());
         if ($form->getValue('welcome_email')) {
             try {
                 $mailer = new Zend_Mail();
                 $mailer->setSubject(_('ViMbAdmin :: Your New Administrator Account'));
                 $mailer->addTo($adminModel->username);
                 $mailer->setFrom($this->_options['server']['email']['address'], $this->_options['server']['email']['name']);
                 $this->view->username = $adminModel->username;
                 $this->view->password = $form->getValue('password');
                 $mailer->setBodyText($this->view->render('admin/email/new_admin.phtml'));
                 $mailer->send();
             } catch (Exception $e) {
                 $this->getLogger()->debug($e->getTraceAsString());
                 $this->addMessage(_('Could not send welcome email'), ViMbAdmin_Message::ALERT);
             }
         }
         $this->addMessage(_('You have successfully added a new administrator to the system.'), ViMbAdmin_Message::SUCCESS);
         $this->_helper->viewRenderer->setNoRender(true);
         return print $this->view->render('close_colorbox_reload_parent.phtml');
     }
     $this->view->form = $form;
 }
Beispiel #2
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;
 }