aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc')
-rw-r--r--inc/poche/Poche.class.php36
-rw-r--r--inc/poche/User.class.php33
-rw-r--r--inc/poche/config.inc.php3
-rw-r--r--inc/store/sqlite.class.php68
-rw-r--r--inc/store/store.class.php6
5 files changed, 89 insertions, 57 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 789d6647..2c0c73f9 100644
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -10,6 +10,7 @@
10 10
11class Poche 11class Poche
12{ 12{
13 public $user;
13 public $store; 14 public $store;
14 public $tpl; 15 public $tpl;
15 public $messages; 16 public $messages;
@@ -26,17 +27,20 @@ class Poche
26 { 27 {
27 $this->install(); 28 $this->install();
28 } 29 }
29
30 $this->saveUser();
31 } 30 }
32 31
33 private function init() 32 private function init()
34 { 33 {
34 Tools::initPhp();
35 Session::init();
36 $this->user = isset($_SESSION['poche_user']) ? $_SESSION['poche_user'] : array();
37
35 # l10n 38 # l10n
36 putenv('LC_ALL=' . LANG); 39 $language = ($this->user->getConfigValue('language')) ? $this->user->getConfigValue('language') : LANG;
37 setlocale(LC_ALL, LANG); 40 putenv('LC_ALL=' . $language);
38 bindtextdomain(LANG, LOCALE); 41 setlocale(LC_ALL, $language);
39 textdomain(LANG); 42 bindtextdomain($language, LOCALE);
43 textdomain($language);
40 44
41 # template engine 45 # template engine
42 $loader = new Twig_Loader_Filesystem(TPL); 46 $loader = new Twig_Loader_Filesystem(TPL);
@@ -48,10 +52,9 @@ class Poche
48 $filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain'); 52 $filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain');
49 $this->tpl->addFilter($filter); 53 $this->tpl->addFilter($filter);
50 54
51 $this->pagination = new Paginator(PAGINATION, 'p'); 55 # Pagination
52 56 $pager = ($this->user->getConfigValue('pager')) ? $this->user->getConfigValue('pager') : PAGINATION;
53 Tools::initPhp(); 57 $this->pagination = new Paginator($pager, 'p');
54 Session::init();
55 } 58 }
56 59
57 private function install() 60 private function install()
@@ -77,12 +80,6 @@ class Poche
77 exit(); 80 exit();
78 } 81 }
79 82
80 private function saveUser()
81 {
82 $_SESSION['login'] = (isset ($_SESSION['login'])) ? $_SESSION['login'] : $this->store->getLogin();
83 $_SESSION['pass'] = (isset ($_SESSION['pass'])) ? $_SESSION['pass'] : $this->store->getPassword();
84 }
85
86 /** 83 /**
87 * Call action (mark as fav, archive, delete, etc.) 84 * Call action (mark as fav, archive, delete, etc.)
88 */ 85 */
@@ -221,7 +218,11 @@ class Poche
221 public function login($referer) 218 public function login($referer)
222 { 219 {
223 if (!empty($_POST['login']) && !empty($_POST['password'])) { 220 if (!empty($_POST['login']) && !empty($_POST['password'])) {
224 if (Session::login($_SESSION['login'], $_SESSION['pass'], $_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']))) { 221 $user = $this->store->login($_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']));
222 if ($user != array()) {
223 # Save login into Session
224 Session::login($user['username'], $user['password'], $_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']), array('poche_user' => new User($user)));
225
225 Tools::logm('login successful'); 226 Tools::logm('login successful');
226 $this->messages->add('s', 'welcome to your poche'); 227 $this->messages->add('s', 'welcome to your poche');
227 if (!empty($_POST['longlastingsession'])) { 228 if (!empty($_POST['longlastingsession'])) {
@@ -248,6 +249,7 @@ class Poche
248 { 249 {
249 $this->messages->add('s', 'see you soon!'); 250 $this->messages->add('s', 'see you soon!');
250 Tools::logm('logout'); 251 Tools::logm('logout');
252 $this->user = array();
251 Session::logout(); 253 Session::logout();
252 Tools::redirect(); 254 Tools::redirect();
253 } 255 }
diff --git a/inc/poche/User.class.php b/inc/poche/User.class.php
new file mode 100644
index 00000000..ef47730f
--- /dev/null
+++ b/inc/poche/User.class.php
@@ -0,0 +1,33 @@
1<?php
2/**
3 * poche, a read it later open source system
4 *
5 * @category poche
6 * @author Nicolas LÅ“uillet <support@inthepoche.com>
7 * @copyright 2013
8 * @license http://www.wtfpl.net/ see COPYING file
9 */
10
11class User
12{
13 public $id;
14 public $username;
15 public $name;
16 public $password;
17 public $email;
18 public $config;
19
20 function __construct($user)
21 {
22 $this->id = $user['id'];
23 $this->username = $user['username'];
24 $this->name = $user['name'];
25 $this->password = $user['password'];
26 $this->email = $user['email'];
27 $this->config = $user['config'];
28 }
29
30 function getConfigValue($name) {
31 return (isset($this->config[$name])) ? $this->config[$name] : FALSE;
32 }
33} \ No newline at end of file
diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php
index ee0f6616..d0c686f0 100644
--- a/inc/poche/config.inc.php
+++ b/inc/poche/config.inc.php
@@ -21,12 +21,13 @@ define ('ABS_PATH', 'assets/');
21define ('TPL', './tpl'); 21define ('TPL', './tpl');
22define ('LOCALE', './locale'); 22define ('LOCALE', './locale');
23define ('CACHE', './cache'); 23define ('CACHE', './cache');
24define ('LANG', 'fr_FR.UTF8'); 24define ('LANG', 'en_EN.UTF8');
25define ('PAGINATION', '10'); 25define ('PAGINATION', '10');
26define ('THEME', 'light'); 26define ('THEME', 'light');
27$storage_type = 'sqlite'; # sqlite, mysql, (file, not yet) 27$storage_type = 'sqlite'; # sqlite, mysql, (file, not yet)
28 28
29# /!\ Be careful if you change the lines below /!\ 29# /!\ Be careful if you change the lines below /!\
30require_once './inc/poche/User.class.php';
30require_once './inc/poche/Tools.class.php'; 31require_once './inc/poche/Tools.class.php';
31require_once './inc/poche/Url.class.php'; 32require_once './inc/poche/Url.class.php';
32require_once './inc/3rdparty/class.messages.php'; 33require_once './inc/3rdparty/class.messages.php';
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 }