]>
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 | ||
c594aedf | 11 | include dirname(__FILE__).'/inc/config.php'; |
1a268ba7 | 12 | |
6f87a197 | 13 | myTool::initPhp(); |
f0070a15 | 14 | |
a1953dff | 15 | # XSRF protection with token |
16 | if (!empty($_POST)) { | |
17 | if (!Session::isToken($_POST['token'])) { | |
18 | die('Wrong token.'); | |
19 | } | |
20 | unset($_SESSION['tokens']); | |
21 | } | |
22 | ||
8c72b98d | 23 | $ref = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; |
24 | ||
a1953dff | 25 | if (isset($_GET['login'])) { |
26 | // Login | |
27 | if (!empty($_POST['login']) && !empty($_POST['password'])) { | |
28 | if (Session::login('poche', 'poche', $_POST['login'], $_POST['password'])) { | |
29 | logm('login successful'); | |
30 | if (!empty($_POST['longlastingsession'])) { | |
31 | $_SESSION['longlastingsession'] = 31536000; | |
32 | $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession']; | |
33 | session_set_cookie_params($_SESSION['longlastingsession']); | |
34 | } else { | |
35 | session_set_cookie_params(0); // when browser closes | |
36 | } | |
37 | session_regenerate_id(true); | |
5917f419 | 38 | |
8c72b98d | 39 | MyTool::redirect($ref); |
a1953dff | 40 | } |
41 | logm('login failed'); | |
42 | die("Login failed !"); | |
43 | } else { | |
44 | logm('login failed'); | |
45 | } | |
46 | } | |
47 | elseif (isset($_GET['logout'])) { | |
48 | logm('logout'); | |
49 | Session::logout(); | |
50 | MyTool::redirect(); | |
51 | } | |
52 | ||
53 | # Traitement des paramètres et déclenchement des actions | |
54 | $view = (isset ($_REQUEST['view'])) ? htmlentities($_REQUEST['view']) : 'index'; | |
55 | $full_head = (isset ($_REQUEST['full_head'])) ? htmlentities($_REQUEST['full_head']) : 'yes'; | |
56 | $action = (isset ($_REQUEST['action'])) ? htmlentities($_REQUEST['action']) : ''; | |
57 | $_SESSION['sort'] = (isset ($_REQUEST['sort'])) ? htmlentities($_REQUEST['sort']) : 'id'; | |
58 | $id = (isset ($_REQUEST['id'])) ? htmlspecialchars($_REQUEST['id']) : ''; | |
59 | $url = (isset ($_GET['url'])) ? $_GET['url'] : ''; | |
a1953dff | 60 | |
61 | $tpl->assign('isLogged', Session::isLogged()); | |
62 | $tpl->assign('referer', $ref); | |
63 | $tpl->assign('view', $view); | |
6f87a197 | 64 | $tpl->assign('poche_url', myTool::getUrl()); |
8046748b | 65 | $tpl->assign('title', 'poche, a read it later open source system'); |
139769aa | 66 | |
e4d2565e | 67 | if (Session::isLogged()) { |
a1953dff | 68 | action_to_do($action, $url, $id); |
69 | display_view($view, $id, $full_head); | |
e4d2565e | 70 | } |
71 | else { | |
72 | $tpl->draw('login'); | |
8c72b98d | 73 | } |