aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php107
1 files changed, 38 insertions, 69 deletions
diff --git a/index.php b/index.php
index fdaeabc3..40cadf88 100644
--- a/index.php
+++ b/index.php
@@ -8,85 +8,54 @@
8 * @license http://www.wtfpl.net/ see COPYING file 8 * @license http://www.wtfpl.net/ see COPYING file
9 */ 9 */
10 10
11include dirname(__FILE__).'/inc/config.php'; 11include dirname(__FILE__).'/inc/poche/config.inc.php';
12 12
13myTool::initPhp(); 13$referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
14 14$view = Tools::checkVar('view', 'home');
15# XSRF protection with token 15$action = Tools::checkVar('action');
16if (!empty($_POST)) { 16$id = Tools::checkVar('id');
17 if (!Session::isToken($_POST['token'])) { 17$_SESSION['sort'] = Tools::checkVar('sort', 'id');
18 die(_('Wrong token.')); 18$url = new Url((isset ($_GET['url'])) ? $_GET['url'] : '');
19 }
20 unset($_SESSION['tokens']);
21}
22
23$ref = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
24 19
25if (isset($_GET['login'])) { 20if (isset($_GET['login'])) {
26 // Login 21 # hello you
27 if (!empty($_POST['login']) && !empty($_POST['password'])) { 22 $poche->login($referer);
28 if (Session::login($_SESSION['login'], $_SESSION['pass'], $_POST['login'], encode_string($_POST['password'] . $_POST['login']))) {
29 logm('login successful');
30 $msg->add('s', 'welcome in your poche!');
31 if (!empty($_POST['longlastingsession'])) {
32 $_SESSION['longlastingsession'] = 31536000;
33 $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession'];
34 session_set_cookie_params($_SESSION['longlastingsession']);
35 } else {
36 session_set_cookie_params(0); // when browser closes
37 }
38 session_regenerate_id(true);
39
40 MyTool::redirect($ref);
41 }
42 logm('login failed');
43 die(_("Login failed !"));
44 } else {
45 logm('login failed');
46 }
47} 23}
48elseif (isset($_GET['logout'])) { 24elseif (isset($_GET['logout'])) {
49 logm('logout'); 25 # see you soon !
50 Session::logout(); 26 $poche->logout();
51 MyTool::redirect();
52} 27}
53elseif (isset($_GET['config'])) { 28elseif (isset($_GET['config'])) {
54 if (isset($_POST['password']) && isset($_POST['password_repeat'])) { 29 # Update password
55 if ($_POST['password'] == $_POST['password_repeat'] && $_POST['password'] != "") { 30 $poche->updatePassword();
56 logm('password updated'); 31}
57 if (!MODE_DEMO) { 32elseif (isset($_GET['import'])) {
58 $store->updatePassword(encode_string($_POST['password'] . $_SESSION['login'])); 33 $poche->import($_GET['from']);
59 $msg->add('s', _('your password has been updated')); 34}
60 } 35elseif (isset($_GET['export'])) {
61 else { 36 $poche->export();
62 $msg->add('i', _('in demo mode, you can\'t update password'));
63 }
64 }
65 else
66 $msg->add('e', _('your password can\'t be empty and you have to repeat it in the second field'));
67 }
68} 37}
69 38
70# Traitement des paramètres et déclenchement des actions 39$tpl_vars = array(
71$view = (isset ($_REQUEST['view'])) ? htmlentities($_REQUEST['view']) : 'index'; 40 'referer' => $referer,
72$full_head = (isset ($_REQUEST['full_head'])) ? htmlentities($_REQUEST['full_head']) : 'yes'; 41 'view' => $view,
73$action = (isset ($_REQUEST['action'])) ? htmlentities($_REQUEST['action']) : ''; 42 'poche_url' => Tools::getPocheUrl(),
74$_SESSION['sort'] = (isset ($_REQUEST['sort'])) ? htmlentities($_REQUEST['sort']) : 'id'; 43 'title' => _('poche, a read it later open source system'),
75$id = (isset ($_REQUEST['id'])) ? htmlspecialchars($_REQUEST['id']) : ''; 44 'token' => Session::getToken(),
76$url = (isset ($_GET['url'])) ? $_GET['url'] : ''; 45);
77
78$tpl->assign('isLogged', Session::isLogged());
79$tpl->assign('referer', $ref);
80$tpl->assign('view', $view);
81$tpl->assign('poche_url', myTool::getUrl());
82$tpl->assign('demo', MODE_DEMO);
83$tpl->assign('title', _('poche, a read it later open source system'));
84 46
85if (Session::isLogged()) { 47if (Session::isLogged()) {
86 action_to_do($action, $url, $id); 48 $poche->action($action, $url, $id);
87 display_view($view, $id, $full_head); 49 $tpl_file = Tools::getTplFile($view);
50 $tpl_vars = array_merge($tpl_vars, $poche->displayView($view, $id));
88} 51}
89else { 52else {
90 53 $tpl_file = 'login.twig';
91 $tpl->draw('login');
92} 54}
55
56# because messages can be added in $poche->action(), we have to add this entry now (we can add it before)
57$messages = $poche->messages->display('all', FALSE);
58$tpl_vars = array_merge($tpl_vars, array('messages' => $messages));
59
60# Aaaaaaand action !
61echo $poche->tpl->render($tpl_file, $tpl_vars); \ No newline at end of file