]> git.immae.eu Git - github/wallabag/wallabag.git/blame - index.php
twig implementation
[github/wallabag/wallabag.git] / index.php
CommitLineData
1a268ba7
NL
1<?php
2/**
3 * poche, a read it later open source system
4 *
5 * @category poche
421b65eb 6 * @author Nicolas Lœuillet <support@inthepoche.com>
1a268ba7
NL
7 * @copyright 2013
8 * @license http://www.wtfpl.net/ see COPYING file
9 */
10
c594aedf 11include dirname(__FILE__).'/inc/config.php';
1a268ba7 12
8cbb2a88 13$errors = array();
f0070a15 14
a1953dff 15# XSRF protection with token
16if (!empty($_POST)) {
17 if (!Session::isToken($_POST['token'])) {
8cbb2a88 18 die(_('Wrong token'));
a1953dff 19 }
20 unset($_SESSION['tokens']);
21}
22
a4565e88 23$referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
8c72b98d 24
a1953dff 25if (isset($_GET['login'])) {
a1953dff 26 if (!empty($_POST['login']) && !empty($_POST['password'])) {
aa8c9f2a 27 if (Session::login($_SESSION['login'], $_SESSION['pass'], $_POST['login'], encode_string($_POST['password'] . $_POST['login']))) {
161395d7 28 pocheTools::logm('login successful');
8cbb2a88
NL
29 $errors[]['value'] = _('login successful');
30
a1953dff 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);
161395d7 39 pocheTools::redirect($referer);
a1953dff 40 }
161395d7 41 pocheTools::logm('login failed');
8cbb2a88 42 $errors[]['value'] = _('Login failed !');
a1953dff 43 } else {
161395d7 44 pocheTools::logm('login failed');
a1953dff 45 }
46}
47elseif (isset($_GET['logout'])) {
161395d7 48 pocheTools::logm('logout');
a1953dff 49 Session::logout();
161395d7 50 pocheTools::redirect();
a1953dff 51}
da368cc8
NL
52elseif (isset($_GET['config'])) {
53 if (isset($_POST['password']) && isset($_POST['password_repeat'])) {
54 if ($_POST['password'] == $_POST['password_repeat'] && $_POST['password'] != "") {
161395d7 55 pocheTools::logm('password updated');
538cdfa8 56 if (!MODE_DEMO) {
6499b26a 57 $store->updatePassword(encode_string($_POST['password'] . $_SESSION['login']));
a4565e88 58 #your password has been updated
6499b26a
NL
59 }
60 else {
a4565e88 61 #in demo mode, you can\'t update password
6499b26a 62 }
da368cc8 63 }
a4565e88
NL
64 #else
65 #your password can\'t be empty and you have to repeat it in the second field
da368cc8 66 }
da368cc8 67}
a1953dff 68
69# Traitement des paramètres et déclenchement des actions
8cbb2a88 70$view = (isset ($_REQUEST['view'])) ? htmlentities($_REQUEST['view']) : 'home';
a1953dff 71$full_head = (isset ($_REQUEST['full_head'])) ? htmlentities($_REQUEST['full_head']) : 'yes';
72$action = (isset ($_REQUEST['action'])) ? htmlentities($_REQUEST['action']) : '';
73$_SESSION['sort'] = (isset ($_REQUEST['sort'])) ? htmlentities($_REQUEST['sort']) : 'id';
74$id = (isset ($_REQUEST['id'])) ? htmlspecialchars($_REQUEST['id']) : '';
75$url = (isset ($_GET['url'])) ? $_GET['url'] : '';
a1953dff 76
a4565e88 77$tpl_vars = array(
a4565e88
NL
78 'referer' => $referer,
79 'view' => $view,
161395d7 80 'poche_url' => pocheTools::getUrl(),
a4565e88
NL
81 'demo' => MODE_DEMO,
82 'title' => _('poche, a read it later open source system'),
8cbb2a88
NL
83 'token' => Session::getToken(),
84 'errors' => $errors,
a4565e88 85);
139769aa 86
8cbb2a88
NL
87$tpl_file = 'home.twig';
88
e4d2565e 89if (Session::isLogged()) {
a1953dff 90 action_to_do($action, $url, $id);
8cbb2a88 91 $tpl_vars = array_merge($tpl_vars, display_view($view, $id));
e4d2565e 92}
93else {
8cbb2a88 94 $tpl_file = 'login.twig';
8c72b98d 95}
a4565e88 96
8cbb2a88 97echo $twig->render($tpl_file, $tpl_vars);