]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Installation mode
authorNicolas Lœuillet <nicolas@loeuillet.org>
Fri, 31 May 2013 20:55:52 +0000 (22:55 +0200)
committerNicolas Lœuillet <nicolas@loeuillet.org>
Fri, 31 May 2013 20:55:52 +0000 (22:55 +0200)
inc/Session.class.php
inc/config.php
inc/functions.php
inc/store/sqlite.class.php
inc/store/store.class.php
index.php
tpl/install.html [new file with mode: 0644]
tpl/login.html

index ee12b3d155e1ae15f210dda5d8cf6e5e6d27e29d..eff924ccdb06dddf8c68bcfab1a15fc967bfc000 100644 (file)
@@ -93,7 +93,7 @@ class Session
     // Force logout
     public static function logout()
     {
-        unset($_SESSION['uid'],$_SESSION['info'],$_SESSION['expires_on'],$_SESSION['tokens']);
+        unset($_SESSION['uid'],$_SESSION['info'],$_SESSION['expires_on'],$_SESSION['tokens'], $_SESSION['login'], $_SESSION['pass']);
     }
 
     // Make sure user is logged in.
index 737f5215a685d55cc5f02d8f6f10528f6465eacd..2de725f4087888dad9c1282e924f87969b068398 100644 (file)
@@ -18,6 +18,7 @@ define ('ABS_PATH', 'assets/');
 define ('CONVERT_LINKS_FOOTNOTES', TRUE);
 define ('REVERT_FORCED_PARAGRAPH_ELEMENTS',FALSE);
 define ('DOWNLOAD_PICTURES', TRUE);
+define ('SALT', '464v54gLLw928uz4zUBqkRJeiPY68zCX');
 $storage_type = 'sqlite'; # sqlite or file
 
 include 'functions.php';
@@ -33,9 +34,7 @@ require_once 'class.messages.php';
 
 Session::init();
 
-$store         = new $storage_type();
-$msg   = new Messages();
-
+$store     = new $storage_type();
 # initialisation de RainTPL
 raintpl::$tpl_dir   = './tpl/';
 raintpl::$cache_dir = './cache/';
@@ -43,4 +42,24 @@ raintpl::$base_url  = get_poche_url();
 raintpl::configure('path_replace', false);
 raintpl::configure('debug', false);
 $tpl = new raintpl();
+
+if(!$store->isInstalled())
+{
+    logm('poche still not installed');
+    $tpl->draw('install');
+    if (isset($_GET['install'])) {
+        if (($_POST['password'] == $_POST['password_repeat']) 
+            && $_POST['password'] != "" && $_POST['login'] != "") {
+            $store->install($_POST['login'], encode_string($_POST['password'] . $_POST['login']));
+            Session::logout();
+            MyTool::redirect();
+        }
+    }
+    exit();
+}
+
+$_SESSION['login'] = (isset ($_SESSION['login'])) ? $_SESSION['login'] : $store->getLogin();
+$_SESSION['pass']  = (isset ($_SESSION['pass'])) ? $_SESSION['pass'] : $store->getPassword();
+
+$msg = new Messages();
 $tpl->assign('msg', $msg);
\ No newline at end of file
index c2a149c6dcea0beaf80b6387e74463cfa066ee0a..73e591c55398e58077d838d3af22ac3e2e8eb4ba 100644 (file)
@@ -23,6 +23,11 @@ function get_poche_url()
     return $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
 }
 
+function encode_string($string) 
+{
+    return sha1($string . SALT);
+}
+
 // function define to retrieve url content
 function get_external_file($url)
 {
@@ -375,12 +380,10 @@ function action_to_do($action, $url, $id = 0)
             break;
         case 'toggle_fav' :
             $store->favoriteById($id);
-            $msg->add('s', 'the favorite toggle has been done successfully');
             logm('mark as favorite link #' . $id);
             break;
         case 'toggle_archive' :
             $store->archiveById($id);
-            $msg->add('s', 'the archive toggle has been done successfully');
             logm('archive link #' . $id);
             break;
         default:
index cda412e6b8659766abda8e12fd5275d314416a0e..4bfbb29e83632d26f353647574a313dc2809cd94 100644 (file)
@@ -17,7 +17,6 @@ class Sqlite extends Store {
         parent::__construct();
 
         $this->handle = new PDO(self::$db_path);
-        $this->handle->exec('CREATE TABLE IF NOT EXISTS "entries" ("id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL  UNIQUE , "title" VARCHAR, "url" VARCHAR UNIQUE , "is_read" INTEGER DEFAULT 0, "is_fav" INTEGER DEFAULT 0, "content" BLOB)');
         $this->handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     }
 
@@ -25,6 +24,56 @@ class Sqlite extends Store {
         return $this->handle;
     }
 
+    public function isInstalled() {
+        $sql        = "SELECT name FROM sqlite_sequence WHERE name=?";
+        $query      = $this->executeQuery($sql, array('config'));
+        $hasConfig  = $query->fetchAll();
+
+        if (count($hasConfig) == 0) 
+            return FALSE;
+
+        if (!$this->getLogin() || !$this->getPassword()) 
+            return FALSE;
+
+        return TRUE;
+    }
+
+    public function install($login, $password) {
+        $this->getHandle()->exec('CREATE TABLE IF NOT EXISTS "config" ("id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL  UNIQUE , "name" VARCHAR UNIQUE, "value" BLOB)');
+
+        $this->handle->exec('CREATE TABLE IF NOT EXISTS "entries" ("id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL  UNIQUE , "title" VARCHAR, "url" VARCHAR UNIQUE , "is_read" INTEGER DEFAULT 0, "is_fav" INTEGER DEFAULT 0, "content" BLOB)');
+
+        if (!$this->getLogin()) {
+            $sql_login     = 'INSERT INTO config ( name, value ) VALUES (?, ?)';
+            $params_login  = array('login', $login);
+            $query         = $this->executeQuery($sql_login, $params_login);
+        }
+
+        if (!$this->getPassword()) {
+            $sql_pass     = 'INSERT INTO config ( name, value ) VALUES (?, ?)';
+            $params_pass  = array('password', $password);
+            $query        = $this->executeQuery($sql_pass, $params_pass);
+        }
+
+        return TRUE;
+    }
+
+    public function getLogin() {
+        $sql    = "SELECT value FROM config WHERE name=?";
+        $query  = $this->executeQuery($sql, array('login'));
+        $login  = $query->fetchAll();
+
+        return isset($login[0]['value']) ? $login[0]['value'] : FALSE;
+    }
+
+    public function getPassword() {
+        $sql    = "SELECT value FROM config WHERE name=?";
+        $query  = $this->executeQuery($sql, array('password'));
+        $pass   = $query->fetchAll();
+
+        return isset($pass[0]['value']) ? $pass[0]['value'] : FALSE; 
+    }
+
     private function executeQuery($sql, $params) {
         try
         {
index 360ff7c20e5f06950f42f5ec4d91455ac620ea1c..dd7d4cfeeb1bd53f5a4d8d5a34de0453750d10f2 100644 (file)
@@ -13,6 +13,14 @@ class Store {
 
     }
 
+    public function getLogin() {
+
+    }
+
+    public function getPassword() {
+        
+    }
+
     public function add() {
 
     }
index 829d5513542789bf4c220cb457ca22f0f12bb166..1522a2ec84e08c09c913d7ace7423ec3700f86c2 100644 (file)
--- a/index.php
+++ b/index.php
@@ -25,9 +25,14 @@ $ref = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
 if (isset($_GET['login'])) {
     // Login
     if (!empty($_POST['login']) && !empty($_POST['password'])) {
-        if (Session::login('poche', 'poche', $_POST['login'], $_POST['password'])) {
+// echo $_SESSION['login']."<br>";
+// echo $_SESSION['pass']."<br>";
+// echo $_POST['login']."<br>";
+// echo encode_string($_POST['password'] . $_POST['login']);
+//         die;
+        if (Session::login($_SESSION['login'], $_SESSION['pass'], $_POST['login'], encode_string($_POST['password'] . $_POST['login']))) {
             logm('login successful');
-            $msg->add('s', 'welcome in your pocket!');
+            $msg->add('s', 'welcome in your poche!');
             if (!empty($_POST['longlastingsession'])) {
                 $_SESSION['longlastingsession'] = 31536000;
                 $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession'];
diff --git a/tpl/install.html b/tpl/install.html
new file mode 100644 (file)
index 0000000..d11a781
--- /dev/null
@@ -0,0 +1,30 @@
+{include="head"}
+    <body class="light-style">
+        <header>
+            <h1><a href="index.php"><img src="./img/logo.png" alt="logo poche" /></a>poche</h1>
+        </header>
+        <div id="main">
+            <form method="post" action="?install" name="loginform">
+                <fieldset class="w500p center">
+                    <h2 class="mbs txtcenter">install your poche</h2>
+                    <div class="row">
+                        <label class="col w150p" for="login">Login</label>
+                        <input class="col" type="text" id="login" name="login" placeholder="Login" tabindex="1" autofocus />
+                    </div>
+                    <div class="row">
+                        <label class="col w150p" for="password">Password</label>
+                        <input class="col" type="password" id="password" name="password" placeholder="Password" tabindex="2">
+                    </div>
+                    <div class="row">
+                        <label class="col w150p" for="password_repeat">Repeat your password</label>
+                        <input class="col" type="password" id="password_repeat" name="password_repeat" placeholder="Password" tabindex="3">
+                    </div>
+                    <div class="row mts txtcenter">
+                        <button class="bouton" type="submit" tabindex="4">Install</button>
+                    </div>
+                </fieldset>
+                <input type="hidden" name="returnurl" value="<?php echo htmlspecialchars($referer);?>">
+                <input type="hidden" name="token" value="<?php echo Session::getToken(); ?>">
+            </form>
+
+{include="footer"}
index ebe4b5e5e06f8ad8a90959c910fe96c65fc5d27c..69c17a5511f14facacde0aff29c4055799795af4 100644 (file)
@@ -12,7 +12,7 @@
                                                <input class="col" type="text" id="login" name="login" placeholder="Login" tabindex="1" autofocus />
                                        </div>
                                        <div class="row">
-                                               <label class="col w150p" for="password" >Password</label>
+                                               <label class="col w150p" for="password">Password</label>
                                                <input class="col" type="password" id="password" name="password" placeholder="Password" tabindex="2">
                                        </div>
                                        <div class="row">