diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-01-26 11:41:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-26 11:41:10 +0100 |
commit | c653ae3bfb11f663a52f55817e6d02a66d0852c8 (patch) | |
tree | d5a03a3e425180f1fafb646c8ec68a4b8458d0b3 /index.php | |
parent | 1410dce2db310e71b5e683b0871c2f28d8807844 (diff) | |
parent | 27ceea2aeeed69b43fef4ebff35ec8004fcc2e45 (diff) | |
download | Shaarli-c653ae3bfb11f663a52f55817e6d02a66d0852c8.tar.gz Shaarli-c653ae3bfb11f663a52f55817e6d02a66d0852c8.tar.zst Shaarli-c653ae3bfb11f663a52f55817e6d02a66d0852c8.zip |
Render login page through Slim controller (#1401)
Render login page through Slim controller
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 84 |
1 files changed, 38 insertions, 46 deletions
@@ -61,29 +61,31 @@ require_once 'application/FileUtils.php'; | |||
61 | require_once 'application/TimeZone.php'; | 61 | require_once 'application/TimeZone.php'; |
62 | require_once 'application/Utils.php'; | 62 | require_once 'application/Utils.php'; |
63 | 63 | ||
64 | use \Shaarli\ApplicationUtils; | 64 | use Shaarli\ApplicationUtils; |
65 | use Shaarli\Bookmark\BookmarkServiceInterface; | ||
66 | use \Shaarli\Bookmark\Exception\BookmarkNotFoundException; | ||
67 | use Shaarli\Bookmark\Bookmark; | 65 | use Shaarli\Bookmark\Bookmark; |
68 | use Shaarli\Bookmark\BookmarkFilter; | ||
69 | use Shaarli\Bookmark\BookmarkFileService; | 66 | use Shaarli\Bookmark\BookmarkFileService; |
70 | use \Shaarli\Config\ConfigManager; | 67 | use Shaarli\Bookmark\BookmarkFilter; |
71 | use \Shaarli\Feed\CachedPage; | 68 | use Shaarli\Bookmark\BookmarkServiceInterface; |
72 | use \Shaarli\Feed\FeedBuilder; | 69 | use Shaarli\Bookmark\Exception\BookmarkNotFoundException; |
70 | use Shaarli\Config\ConfigManager; | ||
71 | use Shaarli\Container\ContainerBuilder; | ||
72 | use Shaarli\Feed\CachedPage; | ||
73 | use Shaarli\Feed\FeedBuilder; | ||
73 | use Shaarli\Formatter\BookmarkMarkdownFormatter; | 74 | use Shaarli\Formatter\BookmarkMarkdownFormatter; |
74 | use Shaarli\Formatter\FormatterFactory; | 75 | use Shaarli\Formatter\FormatterFactory; |
75 | use \Shaarli\History; | 76 | use Shaarli\History; |
76 | use \Shaarli\Languages; | 77 | use Shaarli\Languages; |
77 | use \Shaarli\Netscape\NetscapeBookmarkUtils; | 78 | use Shaarli\Netscape\NetscapeBookmarkUtils; |
78 | use \Shaarli\Plugin\PluginManager; | 79 | use Shaarli\Plugin\PluginManager; |
79 | use \Shaarli\Render\PageBuilder; | 80 | use Shaarli\Render\PageBuilder; |
80 | use \Shaarli\Render\ThemeUtils; | 81 | use Shaarli\Render\ThemeUtils; |
81 | use \Shaarli\Router; | 82 | use Shaarli\Router; |
82 | use \Shaarli\Security\LoginManager; | 83 | use Shaarli\Security\LoginManager; |
83 | use \Shaarli\Security\SessionManager; | 84 | use Shaarli\Security\SessionManager; |
84 | use \Shaarli\Thumbnailer; | 85 | use Shaarli\Thumbnailer; |
85 | use \Shaarli\Updater\Updater; | 86 | use Shaarli\Updater\Updater; |
86 | use \Shaarli\Updater\UpdaterUtils; | 87 | use Shaarli\Updater\UpdaterUtils; |
88 | use Slim\App; | ||
87 | 89 | ||
88 | // Ensure the PHP version is supported | 90 | // Ensure the PHP version is supported |
89 | try { | 91 | try { |
@@ -250,7 +252,7 @@ if (isset($_POST['login'])) { | |||
250 | 252 | ||
251 | // Optional redirect after login: | 253 | // Optional redirect after login: |
252 | if (isset($_GET['post'])) { | 254 | if (isset($_GET['post'])) { |
253 | $uri = '?post='. urlencode($_GET['post']); | 255 | $uri = './?post='. urlencode($_GET['post']); |
254 | foreach (array('description', 'source', 'title', 'tags') as $param) { | 256 | foreach (array('description', 'source', 'title', 'tags') as $param) { |
255 | if (!empty($_GET[$param])) { | 257 | if (!empty($_GET[$param])) { |
256 | $uri .= '&'.$param.'='.urlencode($_GET[$param]); | 258 | $uri .= '&'.$param.'='.urlencode($_GET[$param]); |
@@ -261,22 +263,22 @@ if (isset($_POST['login'])) { | |||
261 | } | 263 | } |
262 | 264 | ||
263 | if (isset($_GET['edit_link'])) { | 265 | if (isset($_GET['edit_link'])) { |
264 | header('Location: ?edit_link='. escape($_GET['edit_link'])); | 266 | header('Location: ./?edit_link='. escape($_GET['edit_link'])); |
265 | exit; | 267 | exit; |
266 | } | 268 | } |
267 | 269 | ||
268 | if (isset($_POST['returnurl'])) { | 270 | if (isset($_POST['returnurl'])) { |
269 | // Prevent loops over login screen. | 271 | // Prevent loops over login screen. |
270 | if (strpos($_POST['returnurl'], 'do=login') === false) { | 272 | if (strpos($_POST['returnurl'], '/login') === false) { |
271 | header('Location: '. generateLocation($_POST['returnurl'], $_SERVER['HTTP_HOST'])); | 273 | header('Location: '. generateLocation($_POST['returnurl'], $_SERVER['HTTP_HOST'])); |
272 | exit; | 274 | exit; |
273 | } | 275 | } |
274 | } | 276 | } |
275 | header('Location: ?'); | 277 | header('Location: ./?'); |
276 | exit; | 278 | exit; |
277 | } else { | 279 | } else { |
278 | $loginManager->handleFailedLogin($_SERVER); | 280 | $loginManager->handleFailedLogin($_SERVER); |
279 | $redir = '&username='. urlencode($_POST['login']); | 281 | $redir = '?username='. urlencode($_POST['login']); |
280 | if (isset($_GET['post'])) { | 282 | if (isset($_GET['post'])) { |
281 | $redir .= '&post=' . urlencode($_GET['post']); | 283 | $redir .= '&post=' . urlencode($_GET['post']); |
282 | foreach (array('description', 'source', 'title', 'tags') as $param) { | 284 | foreach (array('description', 'source', 'title', 'tags') as $param) { |
@@ -286,7 +288,7 @@ if (isset($_POST['login'])) { | |||
286 | } | 288 | } |
287 | } | 289 | } |
288 | // Redirect to login screen. | 290 | // Redirect to login screen. |
289 | echo '<script>alert("'. t("Wrong login/password.") .'");document.location=\'?do=login'.$redir.'\';</script>'; | 291 | echo '<script>alert("'. t("Wrong login/password.") .'");document.location=\'./login'.$redir.'\';</script>'; |
290 | exit; | 292 | exit; |
291 | } | 293 | } |
292 | } | 294 | } |
@@ -594,19 +596,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM | |||
594 | 596 | ||
595 | // -------- Display login form. | 597 | // -------- Display login form. |
596 | if ($targetPage == Router::$PAGE_LOGIN) { | 598 | if ($targetPage == Router::$PAGE_LOGIN) { |
597 | if ($conf->get('security.open_shaarli')) { | 599 | header('Location: ./login'); |
598 | header('Location: ?'); | ||
599 | exit; | ||
600 | } // No need to login for open Shaarli | ||
601 | if (isset($_GET['username'])) { | ||
602 | $PAGE->assign('username', escape($_GET['username'])); | ||
603 | } | ||
604 | $PAGE->assign('returnurl', (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']):'')); | ||
605 | // add default state of the 'remember me' checkbox | ||
606 | $PAGE->assign('remember_user_default', $conf->get('privacy.remember_user_default')); | ||
607 | $PAGE->assign('user_can_login', $loginManager->canLogin($_SERVER)); | ||
608 | $PAGE->assign('pagetitle', t('Login') .' - '. $conf->get('general.title', 'Shaarli')); | ||
609 | $PAGE->renderPage('loginform'); | ||
610 | exit; | 600 | exit; |
611 | } | 601 | } |
612 | // -------- User wants to logout. | 602 | // -------- User wants to logout. |
@@ -933,7 +923,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM | |||
933 | // Show login screen, then redirect to ?post=... | 923 | // Show login screen, then redirect to ?post=... |
934 | if (isset($_GET['post'])) { | 924 | if (isset($_GET['post'])) { |
935 | header( // Redirect to login page, then back to post link. | 925 | header( // Redirect to login page, then back to post link. |
936 | 'Location: ?do=login&post='.urlencode($_GET['post']). | 926 | 'Location: /login?post='.urlencode($_GET['post']). |
937 | (!empty($_GET['title'])?'&title='.urlencode($_GET['title']):''). | 927 | (!empty($_GET['title'])?'&title='.urlencode($_GET['title']):''). |
938 | (!empty($_GET['description'])?'&description='.urlencode($_GET['description']):''). | 928 | (!empty($_GET['description'])?'&description='.urlencode($_GET['description']):''). |
939 | (!empty($_GET['tags'])?'&tags='.urlencode($_GET['tags']):''). | 929 | (!empty($_GET['tags'])?'&tags='.urlencode($_GET['tags']):''). |
@@ -944,7 +934,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM | |||
944 | 934 | ||
945 | showLinkList($PAGE, $bookmarkService, $conf, $pluginManager, $loginManager); | 935 | showLinkList($PAGE, $bookmarkService, $conf, $pluginManager, $loginManager); |
946 | if (isset($_GET['edit_link'])) { | 936 | if (isset($_GET['edit_link'])) { |
947 | header('Location: ?do=login&edit_link='. escape($_GET['edit_link'])); | 937 | header('Location: /login?edit_link='. escape($_GET['edit_link'])); |
948 | exit; | 938 | exit; |
949 | } | 939 | } |
950 | 940 | ||
@@ -1900,7 +1890,7 @@ function install($conf, $sessionManager, $loginManager) | |||
1900 | echo '<script>alert(' | 1890 | echo '<script>alert(' |
1901 | .'"Shaarli is now configured. ' | 1891 | .'"Shaarli is now configured. ' |
1902 | .'Please enter your login/password and start shaaring your bookmarks!"' | 1892 | .'Please enter your login/password and start shaaring your bookmarks!"' |
1903 | .');document.location=\'?do=login\';</script>'; | 1893 | .');document.location=\'./login\';</script>'; |
1904 | exit; | 1894 | exit; |
1905 | } | 1895 | } |
1906 | 1896 | ||
@@ -1930,11 +1920,9 @@ if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do= | |||
1930 | exit; | 1920 | exit; |
1931 | } | 1921 | } |
1932 | 1922 | ||
1933 | $container = new \Slim\Container(); | 1923 | $containerBuilder = new ContainerBuilder($conf, $sessionManager, $loginManager); |
1934 | $container['conf'] = $conf; | 1924 | $container = $containerBuilder->build(); |
1935 | $container['plugins'] = $pluginManager; | 1925 | $app = new App($container); |
1936 | $container['history'] = $history; | ||
1937 | $app = new \Slim\App($container); | ||
1938 | 1926 | ||
1939 | // REST API routes | 1927 | // REST API routes |
1940 | $app->group('/api/v1', function () { | 1928 | $app->group('/api/v1', function () { |
@@ -1953,6 +1941,10 @@ $app->group('/api/v1', function () { | |||
1953 | $this->get('/history', '\Shaarli\Api\Controllers\HistoryController:getHistory')->setName('getHistory'); | 1941 | $this->get('/history', '\Shaarli\Api\Controllers\HistoryController:getHistory')->setName('getHistory'); |
1954 | })->add('\Shaarli\Api\ApiMiddleware'); | 1942 | })->add('\Shaarli\Api\ApiMiddleware'); |
1955 | 1943 | ||
1944 | $app->group('', function () { | ||
1945 | $this->get('/login', '\Shaarli\Front\Controller\LoginController:index')->setName('login'); | ||
1946 | })->add('\Shaarli\Front\ShaarliMiddleware'); | ||
1947 | |||
1956 | $response = $app->run(true); | 1948 | $response = $app->run(true); |
1957 | 1949 | ||
1958 | // Hack to make Slim and Shaarli router work together: | 1950 | // Hack to make Slim and Shaarli router work together: |