]>
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 | |
8cbb2a88 | 13 | $errors = array(); |
f0070a15 | 14 | |
a1953dff | 15 | # XSRF protection with token |
16 | if (!empty($_POST)) { | |
17 | if (!Session::isToken($_POST['token'])) { | |
2b840e0c NL |
18 | #die(_('Wrong token')); |
19 | // TODO CORRIGER ICI !!! | |
a1953dff | 20 | } |
21 | unset($_SESSION['tokens']); | |
22 | } | |
23 | ||
a4565e88 | 24 | $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; |
8c72b98d | 25 | |
a1953dff | 26 | if (isset($_GET['login'])) { |
a1953dff | 27 | if (!empty($_POST['login']) && !empty($_POST['password'])) { |
aa8c9f2a | 28 | if (Session::login($_SESSION['login'], $_SESSION['pass'], $_POST['login'], encode_string($_POST['password'] . $_POST['login']))) { |
161395d7 | 29 | pocheTools::logm('login successful'); |
8cbb2a88 NL |
30 | $errors[]['value'] = _('login successful'); |
31 | ||
a1953dff | 32 | if (!empty($_POST['longlastingsession'])) { |
33 | $_SESSION['longlastingsession'] = 31536000; | |
34 | $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession']; | |
35 | session_set_cookie_params($_SESSION['longlastingsession']); | |
36 | } else { | |
37 | session_set_cookie_params(0); // when browser closes | |
38 | } | |
39 | session_regenerate_id(true); | |
161395d7 | 40 | pocheTools::redirect($referer); |
a1953dff | 41 | } |
161395d7 | 42 | pocheTools::logm('login failed'); |
8cbb2a88 | 43 | $errors[]['value'] = _('Login failed !'); |
a1953dff | 44 | } else { |
161395d7 | 45 | pocheTools::logm('login failed'); |
a1953dff | 46 | } |
47 | } | |
48 | elseif (isset($_GET['logout'])) { | |
161395d7 | 49 | pocheTools::logm('logout'); |
a1953dff | 50 | Session::logout(); |
161395d7 | 51 | pocheTools::redirect(); |
a1953dff | 52 | } |
da368cc8 NL |
53 | elseif (isset($_GET['config'])) { |
54 | if (isset($_POST['password']) && isset($_POST['password_repeat'])) { | |
55 | if ($_POST['password'] == $_POST['password_repeat'] && $_POST['password'] != "") { | |
161395d7 | 56 | pocheTools::logm('password updated'); |
538cdfa8 | 57 | if (!MODE_DEMO) { |
6499b26a | 58 | $store->updatePassword(encode_string($_POST['password'] . $_SESSION['login'])); |
a4565e88 | 59 | #your password has been updated |
6499b26a NL |
60 | } |
61 | else { | |
a4565e88 | 62 | #in demo mode, you can\'t update password |
6499b26a | 63 | } |
da368cc8 | 64 | } |
a4565e88 NL |
65 | #else |
66 | #your password can\'t be empty and you have to repeat it in the second field | |
da368cc8 | 67 | } |
da368cc8 | 68 | } |
a1953dff | 69 | |
70 | # Traitement des paramètres et déclenchement des actions | |
8cbb2a88 | 71 | $view = (isset ($_REQUEST['view'])) ? htmlentities($_REQUEST['view']) : 'home'; |
a1953dff | 72 | $full_head = (isset ($_REQUEST['full_head'])) ? htmlentities($_REQUEST['full_head']) : 'yes'; |
73 | $action = (isset ($_REQUEST['action'])) ? htmlentities($_REQUEST['action']) : ''; | |
74 | $_SESSION['sort'] = (isset ($_REQUEST['sort'])) ? htmlentities($_REQUEST['sort']) : 'id'; | |
75 | $id = (isset ($_REQUEST['id'])) ? htmlspecialchars($_REQUEST['id']) : ''; | |
76 | $url = (isset ($_GET['url'])) ? $_GET['url'] : ''; | |
a1953dff | 77 | |
a4565e88 | 78 | $tpl_vars = array( |
a4565e88 NL |
79 | 'referer' => $referer, |
80 | 'view' => $view, | |
161395d7 | 81 | 'poche_url' => pocheTools::getUrl(), |
a4565e88 NL |
82 | 'demo' => MODE_DEMO, |
83 | 'title' => _('poche, a read it later open source system'), | |
8cbb2a88 NL |
84 | 'token' => Session::getToken(), |
85 | 'errors' => $errors, | |
a4565e88 | 86 | ); |
139769aa | 87 | |
e4d2565e | 88 | if (Session::isLogged()) { |
a1953dff | 89 | action_to_do($action, $url, $id); |
2b840e0c | 90 | $tpl_file = get_tpl_file($view); |
8cbb2a88 | 91 | $tpl_vars = array_merge($tpl_vars, display_view($view, $id)); |
e4d2565e | 92 | } |
93 | else { | |
8cbb2a88 | 94 | $tpl_file = 'login.twig'; |
8c72b98d | 95 | } |
a4565e88 | 96 | |
8cbb2a88 | 97 | echo $twig->render($tpl_file, $tpl_vars); |