Example #1
0
 public function passwordProtection()
 {
     $language = OW::getLanguage();
     $form = new Form('password_protection');
     $form->setAjax(true);
     $form->setAction(OW::getRouter()->urlFor('BASE_CTRL_BaseDocument', 'passwordProtection'));
     $form->setAjaxDataType(Form::AJAX_DATA_TYPE_SCRIPT);
     $password = new PasswordField('password');
     $form->addElement($password);
     $submit = new Submit('submit');
     $submit->setValue(OW::getLanguage()->text('base', 'password_protection_submit_label'));
     $form->addElement($submit);
     $this->addForm($form);
     if (OW::getRequest()->isAjax() && $form->isValid($_POST)) {
         $data = $form->getValues();
         $password = OW::getConfig()->getValue('base', 'guests_can_view_password');
         $cryptedPassword = crypt($data['password'], OW_PASSWORD_SALT);
         if (!empty($data['password']) && $cryptedPassword === $password) {
             setcookie('base_password_protection', UTIL_String::getRandomString(), time() + 86400 * 30, '/');
             echo "OW.info('" . OW::getLanguage()->text('base', 'password_protection_success_message') . "');window.location.reload();";
         } else {
             echo "OW.error('" . OW::getLanguage()->text('base', 'password_protection_error_message') . "');";
         }
         exit;
     }
     OW::getDocument()->setHeading($language->text('base', 'password_protection_text'));
     OW::getDocument()->getMasterPage()->setTemplate(OW::getThemeManager()->getMasterPageTemplate('mobile_blank'));
 }