Esempio n. 1
0
 public function login()
 {
     if ($this->username != 'admin') {
         $this->errorMessages[] = 'Username or password invalid';
         return;
     }
     if ($this->firstTime) {
         file_put_contents(Di::secretFilePath(), md5('admin'));
     }
     $secret = file_get_contents(Di::secretFilePath());
     if (md5($this->password) != $secret) {
         $this->errorMessages[] = 'Username or password invalid';
         return;
     }
     Di::isLogged(true);
     header('Location: /admin');
 }
Esempio n. 2
0
 public function __construct()
 {
     $uri = $_SERVER['REQUEST_URI'];
     if (strpos($uri, '/admin') === 0) {
         $this->content = new \NetBricks\SimpleCms\View\Back();
     } else {
         if (strpos($uri, '/login') === 0) {
             $this->content = new \NetBricks\SimpleCms\View\Login();
         } else {
             if (strpos($uri, '/logout') === 0) {
                 Di::isLogged(false);
                 header('Location: /');
             } else {
                 $this->content = new \NetBricks\SimpleCms\View\Front();
             }
         }
     }
 }
 private function isValid()
 {
     $hasErrors = false;
     $secret = file_get_contents(Di::secretFilePath());
     if (md5($_POST['current']) !== $secret) {
         $this->currentError = 'Current password invalid.';
         $this->currentInputClass = 'warning';
         $hasErrors = true;
     }
     if (strlen($_POST['new_password']) < 5) {
         $this->newPasswordError = 'New password too short. Type at least 5 characters.';
         $this->newPasswordInputClass = 'warning';
         $hasErrors = true;
     }
     if ($_POST['new_password'] != $_POST['retype_password']) {
         $this->retypePasswordError = 'Password is not the same.';
         $this->retypePasswordInputClass = 'warning';
         $hasErrors = true;
     }
     return !$hasErrors;
 }
Esempio n. 4
0
 public static function remove($id)
 {
     $stmt = Di::db()->prepare('delete from article where id=:id');
     $stmt->execute(array(':id' => (int) $id));
 }
Esempio n. 5
0
<?php

use Nbml\AutoLoader\ClassAutoLoader;
use Nbml\AutoLoader\ViewAutoLoader;
use Nbml\Compiler;
use NetBricks\SimpleCms\Di;
session_start();
if (!defined('LIBRARY_PATH')) {
    define('NBML_LIBRARY_DIR', realpath(__DIR__ . '/../../../library'));
}
require_once NBML_LIBRARY_DIR . '/Nbml/AutoLoader/ViewAutoLoader.php';
require_once NBML_LIBRARY_DIR . '/Nbml/AutoLoader/ClassAutoLoader.php';
initialize_autoloaders:
$classAutoLoader = new ClassAutoLoader();
$classAutoLoader->addIncludePath(NBML_LIBRARY_DIR)->addIncludePath(__DIR__ . '/../src')->register();
$viewAutoLoader = new ViewAutoLoader();
$viewAutoLoader->setCompilerDefaultDestinationDir(__DIR__ . '/../tmp')->setAlwaysCompile(true)->addIncludePath(__DIR__ . '/../src')->register();
$viewCompiler = new Compiler();
$viewCompiler->addTagProcessor('\\Nbml\\MetadataTag\\PublicMetadataTag')->addTagProcessor('\\Nbml\\MetadataTag\\StateMetadataTag')->addTagProcessor('\\Nbml\\MetadataTag\\OnDemandMetadataTag')->addTagProcessor('\\Nbml\\MetadataTag\\OnStateMetadataTag')->addTagProcessor('\\Nbml\\MetadataTag\\CssMetadataTag')->addTagProcessor('\\Nbml\\MetadataTag\\JsMetadataTag')->addTagProcessor('\\NetBricks\\SimpleCms\\AdminAccessMetadataTag');
$viewAutoLoader->setViewCompiler($viewCompiler);
Di::sqLiteFilePath(realpath(__DIR__ . '/../var/') . '/base.db');
Di::secretFilePath(realpath(__DIR__ . '/../var/') . '/secret');
//Installation:
\NetBricks\SimpleCms\Model\Article::initDb();
echo new NetBricks\SimpleCms\View\Application();