aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2013-08-02 22:40:51 +0200
committerNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2013-08-02 22:40:51 +0200
commita4565e88edbc8e3bd092a475469769c86a4c350c (patch)
treea6a3c935b03a23ff87575c8c315cf8ba78fe68c2 /index.php
parentf6c9baab3efeec1d0efa151e276fc08d5b58f9e9 (diff)
downloadwallabag-a4565e88edbc8e3bd092a475469769c86a4c350c.tar.gz
wallabag-a4565e88edbc8e3bd092a475469769c86a4c350c.tar.zst
wallabag-a4565e88edbc8e3bd092a475469769c86a4c350c.zip
add Twig & refactor poche
Diffstat (limited to 'index.php')
-rw-r--r--index.php46
1 files changed, 24 insertions, 22 deletions
diff --git a/index.php b/index.php
index fdaeabc3..78daaaf9 100644
--- a/index.php
+++ b/index.php
@@ -10,7 +10,7 @@
10 10
11include dirname(__FILE__).'/inc/config.php'; 11include dirname(__FILE__).'/inc/config.php';
12 12
13myTool::initPhp(); 13pocheTool::initPhp();
14 14
15# XSRF protection with token 15# XSRF protection with token
16if (!empty($_POST)) { 16if (!empty($_POST)) {
@@ -20,14 +20,13 @@ if (!empty($_POST)) {
20 unset($_SESSION['tokens']); 20 unset($_SESSION['tokens']);
21} 21}
22 22
23$ref = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; 23$referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
24 24
25if (isset($_GET['login'])) { 25if (isset($_GET['login'])) {
26 // Login 26 // Login
27 if (!empty($_POST['login']) && !empty($_POST['password'])) { 27 if (!empty($_POST['login']) && !empty($_POST['password'])) {
28 if (Session::login($_SESSION['login'], $_SESSION['pass'], $_POST['login'], encode_string($_POST['password'] . $_POST['login']))) { 28 if (Session::login($_SESSION['login'], $_SESSION['pass'], $_POST['login'], encode_string($_POST['password'] . $_POST['login']))) {
29 logm('login successful'); 29 pocheTool::logm('login successful');
30 $msg->add('s', 'welcome in your poche!');
31 if (!empty($_POST['longlastingsession'])) { 30 if (!empty($_POST['longlastingsession'])) {
32 $_SESSION['longlastingsession'] = 31536000; 31 $_SESSION['longlastingsession'] = 31536000;
33 $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession']; 32 $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession'];
@@ -37,33 +36,33 @@ if (isset($_GET['login'])) {
37 } 36 }
38 session_regenerate_id(true); 37 session_regenerate_id(true);
39 38
40 MyTool::redirect($ref); 39 pocheTool::redirect($referer);
41 } 40 }
42 logm('login failed'); 41 pocheTool::logm('login failed');
43 die(_("Login failed !")); 42 die(_("Login failed !"));
44 } else { 43 } else {
45 logm('login failed'); 44 pocheTool::logm('login failed');
46 } 45 }
47} 46}
48elseif (isset($_GET['logout'])) { 47elseif (isset($_GET['logout'])) {
49 logm('logout'); 48 pocheTool::logm('logout');
50 Session::logout(); 49 Session::logout();
51 MyTool::redirect(); 50 pocheTool::redirect();
52} 51}
53elseif (isset($_GET['config'])) { 52elseif (isset($_GET['config'])) {
54 if (isset($_POST['password']) && isset($_POST['password_repeat'])) { 53 if (isset($_POST['password']) && isset($_POST['password_repeat'])) {
55 if ($_POST['password'] == $_POST['password_repeat'] && $_POST['password'] != "") { 54 if ($_POST['password'] == $_POST['password_repeat'] && $_POST['password'] != "") {
56 logm('password updated'); 55 pocheTool::logm('password updated');
57 if (!MODE_DEMO) { 56 if (!MODE_DEMO) {
58 $store->updatePassword(encode_string($_POST['password'] . $_SESSION['login'])); 57 $store->updatePassword(encode_string($_POST['password'] . $_SESSION['login']));
59 $msg->add('s', _('your password has been updated')); 58 #your password has been updated
60 } 59 }
61 else { 60 else {
62 $msg->add('i', _('in demo mode, you can\'t update password')); 61 #in demo mode, you can\'t update password
63 } 62 }
64 } 63 }
65 else 64 #else
66 $msg->add('e', _('your password can\'t be empty and you have to repeat it in the second field')); 65 #your password can\'t be empty and you have to repeat it in the second field
67 } 66 }
68} 67}
69 68
@@ -75,18 +74,21 @@ $_SESSION['sort'] = (isset ($_REQUEST['sort'])) ? htmlentities($_REQUEST['sort
75$id = (isset ($_REQUEST['id'])) ? htmlspecialchars($_REQUEST['id']) : ''; 74$id = (isset ($_REQUEST['id'])) ? htmlspecialchars($_REQUEST['id']) : '';
76$url = (isset ($_GET['url'])) ? $_GET['url'] : ''; 75$url = (isset ($_GET['url'])) ? $_GET['url'] : '';
77 76
78$tpl->assign('isLogged', Session::isLogged()); 77$tpl_vars = array(
79$tpl->assign('referer', $ref); 78 'isLogged' => Session::isLogged(),
80$tpl->assign('view', $view); 79 'referer' => $referer,
81$tpl->assign('poche_url', myTool::getUrl()); 80 'view' => $view,
82$tpl->assign('demo', MODE_DEMO); 81 'poche_url' => pocheTool::getUrl(),
83$tpl->assign('title', _('poche, a read it later open source system')); 82 'demo' => MODE_DEMO,
83 'title' => _('poche, a read it later open source system'),
84);
84 85
85if (Session::isLogged()) { 86if (Session::isLogged()) {
86 action_to_do($action, $url, $id); 87 action_to_do($action, $url, $id);
87 display_view($view, $id, $full_head); 88 display_view($view, $id, $full_head);
88} 89}
89else { 90else {
90 91 $template = $twig->loadTemplate('login.twig');
91 $tpl->draw('login');
92} 92}
93
94echo $template->render($tpl_vars); \ No newline at end of file