]>
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 | |
161395d7 | 13 | pocheTools::initPhp(); |
f0070a15 | 14 | |
a1953dff | 15 | # XSRF protection with token |
16 | if (!empty($_POST)) { | |
17 | if (!Session::isToken($_POST['token'])) { | |
2ee436ea | 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 | 25 | if (isset($_GET['login'])) { |
26 | // Login | |
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'); |
a1953dff | 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 | |
161395d7 | 39 | pocheTools::redirect($referer); |
a1953dff | 40 | } |
161395d7 | 41 | pocheTools::logm('login failed'); |
2ee436ea | 42 | die(_("Login failed !")); |
a1953dff | 43 | } else { |
161395d7 | 44 | pocheTools::logm('login failed'); |
a1953dff | 45 | } |
46 | } | |
47 | elseif (isset($_GET['logout'])) { | |
161395d7 | 48 | pocheTools::logm('logout'); |
a1953dff | 49 | Session::logout(); |
161395d7 | 50 | pocheTools::redirect(); |
a1953dff | 51 | } |
da368cc8 NL |
52 | elseif (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 | |
70 | $view = (isset ($_REQUEST['view'])) ? htmlentities($_REQUEST['view']) : 'index'; | |
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 NL |
77 | $tpl_vars = array( |
78 | 'isLogged' => Session::isLogged(), | |
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'), | |
84 | ); | |
139769aa | 85 | |
e4d2565e | 86 | if (Session::isLogged()) { |
a1953dff | 87 | action_to_do($action, $url, $id); |
88 | display_view($view, $id, $full_head); | |
e4d2565e | 89 | } |
90 | else { | |
a4565e88 | 91 | $template = $twig->loadTemplate('login.twig'); |
8c72b98d | 92 | } |
a4565e88 NL |
93 | |
94 | echo $template->render($tpl_vars); |