예제 #1
0
 public function loginAction()
 {
     if (isset($_SESSION['bareos']['authenticated']) && $_SESSION['bareos']['authenticated']) {
         return $this->redirect()->toRoute('dashboard', array('action' => 'index'));
     }
     $this->layout('layout/login');
     $config = $this->getServiceLocator()->get('Config');
     $form = new LoginForm($config['directors']);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $auth = new Auth();
         $form->setInputFilter($auth->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $director = $form->getInputFilter()->getValue('director');
             $username = $form->getInputFilter()->getValue('consolename');
             $password = $form->getInputFilter()->getValue('password');
             $config = $this->getServiceLocator()->get('Config');
             $this->director = $this->getServiceLocator()->get('director');
             $this->director->set_config($config['directors'][$director]);
             $this->director->set_user_credentials($username, $password);
             if ($this->director->auth($username, $password)) {
                 $_SESSION['bareos']['director'] = $director;
                 $_SESSION['bareos']['username'] = $username;
                 $_SESSION['bareos']['password'] = $password;
                 $_SESSION['bareos']['authenticated'] = true;
                 $_SESSION['bareos']['idletime'] = time();
                 return $this->redirect()->toRoute('dashboard', array('action' => 'index'));
             } else {
                 session_destroy();
                 $err_msg = "Sorry, can not authenticate. Wrong username and/or password.";
                 return new ViewModel(array('form' => $form, 'err_msg' => $err_msg));
             }
         } else {
             // given credentials in login form could not be validated in this case
             $err_msg = "Please provide a director, username and password.";
             session_destroy();
             return new ViewModel(array('form' => $form, 'err_msg' => $err_msg));
         }
     }
     return new ViewModel(array('form' => $form));
 }