From 11648e055c0148980def8ca6fe5d27fb0e7d7a43 Mon Sep 17 00:00:00 2001 From: rr- Date: Thu, 2 Jul 2015 20:24:01 +0200 Subject: [PATCH] Added support for explicit HTTP permalinks --- data/config.ini | 1 + public_html/js/Auth.js | 1 + public_html/js/Presenters/PostPresenter.js | 3 +++ public_html/templates/post.tpl | 11 ++++++++++- src/Routes/Login.php | 7 +++++++ 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/data/config.ini b/data/config.ini index e32b34bd..7208f327 100644 --- a/data/config.ini +++ b/data/config.ini @@ -31,6 +31,7 @@ secret = change minPasswordLength = 5 needEmailActivationToRegister = 1 defaultAccessRank = restrictedUser +forceHttpInPermalinks = 0 [security.privileges] register = anonymous diff --git a/public_html/js/Auth.js b/public_html/js/Auth.js index 468b571c..a90a865c 100644 --- a/public_html/js/Auth.js +++ b/public_html/js/Auth.js @@ -141,6 +141,7 @@ App.Auth = function(_, jQuery, util, api, appState, promise) { appState.set('loginToken', response.json.token && response.json.token.name); appState.set('loggedIn', response.json.user && !!response.json.user.id); appState.set('loggedInUser', response.json.user); + appState.set('config', response.json.config); } function isLoggedIn(userName) { diff --git a/public_html/js/Presenters/PostPresenter.js b/public_html/js/Presenters/PostPresenter.js index 920cf0de..5e32ea48 100644 --- a/public_html/js/Presenters/PostPresenter.js +++ b/public_html/js/Presenters/PostPresenter.js @@ -4,6 +4,7 @@ App.Presenters = App.Presenters || {}; App.Presenters.PostPresenter = function( _, jQuery, + appState, util, promise, api, @@ -171,6 +172,7 @@ App.Presenters.PostPresenter = function( return templates.post({ query: params.query, post: post, + forceHttpInPermalinks: appState.get('config')['forceHttpInPermalinks'], ownScore: post.ownScore, postFavorites: post.favorites, postHistory: post.history, @@ -334,6 +336,7 @@ App.Presenters.PostPresenter = function( App.DI.register('postPresenter', [ '_', 'jQuery', + 'appState', 'util', 'promise', 'api', diff --git a/public_html/templates/post.tpl b/public_html/templates/post.tpl index 92eb5876..611cd140 100644 --- a/public_html/templates/post.tpl +++ b/public_html/templates/post.tpl @@ -1,4 +1,13 @@ -<% var permaLink = (window.location.origin + '/' + window.location.pathname + '/data/posts/' + post.name).replace(/([^:])\/+/g, '$1/') %> +<% +var permaLink = ''; +permaLink += window.location.origin + '/'; +permaLink += window.location.pathname + '/'; +permaLink += 'data/posts/' + post.name; +permaLink = permaLink.replace(/([^:])\/+/g, '$1/'); +if (forceHttpInPermalinks > 0) { + permaLink = permaLink.replace('https', 'http'); +} +%>
diff --git a/src/Routes/Login.php b/src/Routes/Login.php index 61923883..ff4e1c1e 100644 --- a/src/Routes/Login.php +++ b/src/Routes/Login.php @@ -1,5 +1,6 @@ config = $config; $this->authService = $authService; $this->userService = $userService; $this->tokenService = $tokenService; @@ -79,6 +83,9 @@ class Login extends AbstractRoute 'token' => $this->tokenViewProxy->fromEntity($this->authService->getLoginToken()), 'user' => $this->userViewProxy->fromEntity($user), 'privileges' => $this->privilegeService->getCurrentPrivileges(), + 'config' => [ + 'forceHttpInPermalinks' => $this->config->security->forceHttpInPermalinks, + ], ]; } }