aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/store
diff options
context:
space:
mode:
Diffstat (limited to 'inc/store')
-rw-r--r--inc/store/sqlite.class.php68
-rw-r--r--inc/store/store.class.php6
2 files changed, 35 insertions, 39 deletions
diff --git a/inc/store/sqlite.class.php b/inc/store/sqlite.class.php
index 3e391e40..3cc5276d 100644
--- a/inc/store/sqlite.class.php
+++ b/inc/store/sqlite.class.php
@@ -25,59 +25,59 @@ class Sqlite extends Store {
25 } 25 }
26 26
27 public function isInstalled() { 27 public function isInstalled() {
28 $sql = "SELECT name FROM sqlite_sequence WHERE name=?"; 28 $sql = "SELECT username FROM users WHERE id=?";
29 $query = $this->executeQuery($sql, array('config')); 29 $query = $this->executeQuery($sql, array('1'));
30 $hasConfig = $query->fetchAll(); 30 $hasAdmin = $query->fetchAll();
31 31
32 if (count($hasConfig) == 0) 32 if (count($hasAdmin) == 0)
33 return FALSE;
34
35 if (!$this->getLogin() || !$this->getPassword())
36 return FALSE; 33 return FALSE;
37 34
38 return TRUE; 35 return TRUE;
39 } 36 }
40 37
41 public function install($login, $password) { 38 public function install($login, $password) {
42 $this->getHandle()->exec('CREATE TABLE IF NOT EXISTS "config" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , "name" VARCHAR UNIQUE, "value" BLOB)'); 39 $sql = 'INSERT INTO users ( username, password ) VALUES (?, ?)';
43 40 $params = array($login, $password);
44 $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)'); 41 $query = $this->executeQuery($sql, $params);
45 42
46 if (!$this->getLogin()) { 43 return TRUE;
47 $sql_login = 'INSERT INTO config ( name, value ) VALUES (?, ?)'; 44 }
48 $params_login = array('login', $login);
49 $query = $this->executeQuery($sql_login, $params_login);
50 }
51 45
52 if (!$this->getPassword()) { 46 private function getConfigUser($id) {
53 $sql_pass = 'INSERT INTO config ( name, value ) VALUES (?, ?)'; 47 $sql = "SELECT * FROM users_config WHERE user_id = ?";
54 $params_pass = array('password', $password); 48 $query = $this->executeQuery($sql, array($id));
55 $query = $this->executeQuery($sql_pass, $params_pass); 49 $result = $query->fetchAll();
50 $user_config = array();
51
52 foreach ($result as $key => $value) {
53 $user_config[$value['name']] = $value['value'];
56 } 54 }
57 55
58 return TRUE; 56 return $user_config;
59 } 57 }
60 58
61 public function getLogin() { 59 public function login($username, $password) {
62 $sql = "SELECT value FROM config WHERE name=?"; 60 $sql = "SELECT * FROM users WHERE username=? AND password=?";
63 $query = $this->executeQuery($sql, array('login')); 61 $query = $this->executeQuery($sql, array($username, $password));
64 $login = $query->fetchAll(); 62 $login = $query->fetchAll();
65 63
66 return isset($login[0]['value']) ? $login[0]['value'] : FALSE; 64 $user = array();
67 } 65 if (isset($login[0])) {
68 66 $user['id'] = $login[0]['id'];
69 public function getPassword() { 67 $user['username'] = $login[0]['username'];
70 $sql = "SELECT value FROM config WHERE name=?"; 68 $user['password'] = $login[0]['password'];
71 $query = $this->executeQuery($sql, array('password')); 69 $user['name'] = $login[0]['name'];
72 $pass = $query->fetchAll(); 70 $user['email'] = $login[0]['email'];
71 $user['config'] = $this->getConfigUser($login[0]['id']);
72 }
73 73
74 return isset($pass[0]['value']) ? $pass[0]['value'] : FALSE; 74 return $user;
75 } 75 }
76 76
77 public function updatePassword($password) 77 public function updatePassword($id, $password)
78 { 78 {
79 $sql_update = "UPDATE config SET value=? WHERE name='password'"; 79 $sql_update = "UPDATE users SET password=? WHERE id=?";
80 $params_update = array($password); 80 $params_update = array($password, $id);
81 $query = $this->executeQuery($sql_update, $params_update); 81 $query = $this->executeQuery($sql_update, $params_update);
82 } 82 }
83 83
diff --git a/inc/store/store.class.php b/inc/store/store.class.php
index dd7d4cfe..5f8939b9 100644
--- a/inc/store/store.class.php
+++ b/inc/store/store.class.php
@@ -13,14 +13,10 @@ class Store {
13 13
14 } 14 }
15 15
16 public function getLogin() { 16 public function login() {
17 17
18 } 18 }
19 19
20 public function getPassword() {
21
22 }
23
24 public function add() { 20 public function add() {
25 21
26 } 22 }