aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche
diff options
context:
space:
mode:
authorNicolas Lœuillet <nicolas.loeuillet@gmail.com>2013-08-06 14:18:03 +0200
committerNicolas Lœuillet <nicolas.loeuillet@gmail.com>2013-08-06 14:18:03 +0200
commit7ce7ec4c942e0a3567858ad0ec8e654000b49a3f (patch)
tree8de9df7ff2ddfe980f8247e2305ad4b1b27194fa /inc/poche
parent17a9cb96088d4634deca29c8be9f90d94c0f6473 (diff)
downloadwallabag-7ce7ec4c942e0a3567858ad0ec8e654000b49a3f.tar.gz
wallabag-7ce7ec4c942e0a3567858ad0ec8e654000b49a3f.tar.zst
wallabag-7ce7ec4c942e0a3567858ad0ec8e654000b49a3f.zip
prepare to multi users
Diffstat (limited to 'inc/poche')
-rw-r--r--inc/poche/Poche.class.php36
-rw-r--r--inc/poche/User.class.php33
-rw-r--r--inc/poche/config.inc.php3
3 files changed, 54 insertions, 18 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';