]>
Commit | Line | Data |
---|---|---|
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 | ||
eb1af592 | 11 | include dirname(__FILE__).'/inc/poche/config.inc.php'; |
1a268ba7 | 12 | |
4f5b44bd | 13 | $notices = array(); |
f0070a15 | 14 | |
a1953dff | 15 | # XSRF protection with token |
4f5b44bd NL |
16 | // if (!empty($_POST)) { |
17 | // if (!Session::isToken($_POST['token'])) { | |
18 | // die(_('Wrong token')); | |
19 | // // TODO remettre le test | |
20 | // } | |
21 | // unset($_SESSION['tokens']); | |
22 | // } | |
a1953dff | 23 | |
a4565e88 | 24 | $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; |
8c72b98d | 25 | |
a1953dff | 26 | if (isset($_GET['login'])) { |
4f5b44bd | 27 | # hello you |
a1953dff | 28 | if (!empty($_POST['login']) && !empty($_POST['password'])) { |
eb1af592 NL |
29 | if (Session::login($_SESSION['login'], $_SESSION['pass'], $_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']))) { |
30 | Tools::logm('login successful'); | |
31 | $notices['value'] = _('login successful'); | |
8cbb2a88 | 32 | |
a1953dff | 33 | if (!empty($_POST['longlastingsession'])) { |
34 | $_SESSION['longlastingsession'] = 31536000; | |
35 | $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession']; | |
36 | session_set_cookie_params($_SESSION['longlastingsession']); | |
37 | } else { | |
4f5b44bd | 38 | session_set_cookie_params(0); |
a1953dff | 39 | } |
40 | session_regenerate_id(true); | |
eb1af592 | 41 | Tools::redirect($referer); |
a1953dff | 42 | } |
eb1af592 NL |
43 | Tools::logm('login failed'); |
44 | $notices['value'] = _('Login failed !'); | |
45 | Tools::redirect(); | |
a1953dff | 46 | } else { |
eb1af592 NL |
47 | Tools::logm('login failed'); |
48 | Tools::redirect(); | |
a1953dff | 49 | } |
50 | } | |
51 | elseif (isset($_GET['logout'])) { | |
4f5b44bd | 52 | # see you soon ! |
eb1af592 | 53 | Tools::logm('logout'); |
a1953dff | 54 | Session::logout(); |
eb1af592 | 55 | Tools::redirect(); |
a1953dff | 56 | } |
da368cc8 | 57 | elseif (isset($_GET['config'])) { |
4f5b44bd | 58 | # Update password |
da368cc8 NL |
59 | if (isset($_POST['password']) && isset($_POST['password_repeat'])) { |
60 | if ($_POST['password'] == $_POST['password_repeat'] && $_POST['password'] != "") { | |
538cdfa8 | 61 | if (!MODE_DEMO) { |
eb1af592 NL |
62 | Tools::logm('password updated'); |
63 | $poche->store->updatePassword(Tools::encodeString($_POST['password'] . $_SESSION['login'])); | |
4f5b44bd | 64 | Session::logout(); |
eb1af592 | 65 | Tools::redirect(); |
6499b26a NL |
66 | } |
67 | else { | |
eb1af592 | 68 | Tools::logm('in demo mode, you can\'t do this'); |
6499b26a | 69 | } |
da368cc8 | 70 | } |
da368cc8 | 71 | } |
da368cc8 | 72 | } |
a1953dff | 73 | |
4f5b44bd NL |
74 | # Aaaaaaand action ! |
75 | $view = (isset ($_REQUEST['view'])) ? htmlentities($_REQUEST['view']) : 'home'; | |
76 | $full_head = (isset ($_REQUEST['full_head'])) ? htmlentities($_REQUEST['full_head']) : 'yes'; | |
77 | $action = (isset ($_REQUEST['action'])) ? htmlentities($_REQUEST['action']) : ''; | |
78 | $_SESSION['sort'] = (isset ($_REQUEST['sort'])) ? htmlentities($_REQUEST['sort']) : 'id'; | |
79 | $id = (isset ($_REQUEST['id'])) ? htmlspecialchars($_REQUEST['id']) : ''; | |
eb1af592 NL |
80 | |
81 | $url = new Url((isset ($_GET['url'])) ? $_GET['url'] : ''); | |
a1953dff | 82 | |
a4565e88 | 83 | $tpl_vars = array( |
a4565e88 NL |
84 | 'referer' => $referer, |
85 | 'view' => $view, | |
eb1af592 | 86 | 'poche_url' => Tools::getPocheUrl(), |
a4565e88 NL |
87 | 'demo' => MODE_DEMO, |
88 | 'title' => _('poche, a read it later open source system'), | |
8cbb2a88 | 89 | 'token' => Session::getToken(), |
4f5b44bd | 90 | 'notices' => $notices, |
a4565e88 | 91 | ); |
139769aa | 92 | |
e4d2565e | 93 | if (Session::isLogged()) { |
eb1af592 NL |
94 | $poche->action($action, $url, $id); |
95 | $tpl_file = Tools::getTplFile($view); | |
96 | $tpl_vars = array_merge($tpl_vars, $poche->displayView($view, $id)); | |
e4d2565e | 97 | } |
98 | else { | |
8cbb2a88 | 99 | $tpl_file = 'login.twig'; |
8c72b98d | 100 | } |
a4565e88 | 101 | |
eb1af592 | 102 | echo $poche->tpl->render($tpl_file, $tpl_vars); |