Example #1
0
 private function login()
 {
     $form = $this->loginForm;
     if ($form->isValid($_POST)) {
         $values = $form->getValues();
         $model = new Joobsbox_Model_Users();
         $result = $model->authenticate($values['username'], $values['password']);
         if ($result->isValid()) {
             $sess = new Zend_Session_Namespace("auth");
             $redirectUrl = $sess->loginSuccessRedirectUrl;
             header("Location: {$redirectUrl}");
             unset($sess->loginSuccessRedirectUrl);
             exit;
         } else {
             $values = $form->getValues();
             $messages = $form->getMessages();
             $form->populate($values);
             $this->view->form = $form;
             $this->view->loginError = $this->view->translate("Username and/or password incorrect");
         }
     } else {
         $values = $form->getValues();
         $messages = $form->getMessages();
         $form->populate($values);
         $this->view->form = $form;
     }
 }
 public function validateAdminUser()
 {
     $form = $this->adminForm;
     $values = $form->getValues();
     if ($form->isValid($_POST)) {
         $db = Zend_Registry::get("db");
         $values = $form->getValues();
         $username = $values['username'];
         $password = $values['password'];
         $this->reloadConfig();
         $db->delete($this->config->db->prefix . $this->config->dbtables->users, array("username='******'"));
         $db->insert($this->config->db->prefix . $this->config->dbtables->users, array('username' => $values['username'], 'password' => md5(Zend_Registry::get('staticSalt') . $values['password'] . sha1($password)), 'password_salt' => sha1($values['password']), 'realname' => $values['realname'], 'email' => $values['email']));
         $config = new Zend_Config_Xml(CONFIG_LOCATION, null, array('allowModifications' => true));
         $config->general->restrict_install = 1;
         $writer = new Zend_Config_Writer_Xml(array('config' => $config, 'filename' => CONFIG_LOCATION));
         $writer->write();
         $model = new Joobsbox_Model_Users();
         $result = $model->authenticate($username, $password);
         $session = new Zend_Session_Namespace('AdminPanel');
         $session->notices[] = $this->view->translate("Congratulations! Your JoobsBox is working now. Feel free to configure some categories.");
         $this->_redirect("admin");
     } else {
         $values = $form->getValues();
         $messages = $form->getMessages();
         $form->populate($values);
         $this->view->form = $form->render();
     }
 }