mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
parent
4f22a402a3
commit
4b3f3b8d0f
4 changed files with 21 additions and 21 deletions
|
@ -1,14 +1,13 @@
|
||||||
var urlService = require('../../services/url'),
|
const urlService = require('../../services/url'),
|
||||||
common = require('../../lib/common'),
|
common = require('../../lib/common'),
|
||||||
middleware = require('./lib/middleware'),
|
middleware = require('./lib/middleware'),
|
||||||
router = require('./lib/router'),
|
router = require('./lib/router'),
|
||||||
registerHelpers = require('./lib/helpers'),
|
registerHelpers = require('./lib/helpers'),
|
||||||
// routeKeywords.private: 'private'
|
// routeKeywords.private: 'private'
|
||||||
PRIVATE_KEYWORD = 'private',
|
PRIVATE_KEYWORD = 'private';
|
||||||
checkSubdir;
|
|
||||||
|
|
||||||
checkSubdir = function checkSubdir() {
|
let checkSubdir = function checkSubdir() {
|
||||||
var paths;
|
let paths = '';
|
||||||
|
|
||||||
if (urlService.utils.getSubdir()) {
|
if (urlService.utils.getSubdir()) {
|
||||||
paths = urlService.utils.getSubdir().split('/');
|
paths = urlService.utils.getSubdir().split('/');
|
||||||
|
@ -28,7 +27,7 @@ checkSubdir = function checkSubdir() {
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
activate: function activate(ghost) {
|
activate: function activate(ghost) {
|
||||||
var privateRoute = '/' + PRIVATE_KEYWORD + '/';
|
let privateRoute = `/${PRIVATE_KEYWORD}/`;
|
||||||
|
|
||||||
checkSubdir();
|
checkSubdir();
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
// Password input used on private.hbs for password-protected blogs
|
// Password input used on private.hbs for password-protected blogs
|
||||||
|
|
||||||
// (less) dirty requires
|
// (less) dirty requires
|
||||||
var proxy = require('../../../../helpers/proxy'),
|
const proxy = require('../../../../helpers/proxy'),
|
||||||
SafeString = proxy.SafeString,
|
SafeString = proxy.SafeString,
|
||||||
templates = proxy.templates;
|
templates = proxy.templates;
|
||||||
|
|
||||||
|
@ -13,19 +13,19 @@ module.exports = function input_password(options) { // eslint-disable-line camel
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.hash = options.hash || {};
|
options.hash = options.hash || {};
|
||||||
|
|
||||||
var className = (options.hash.class) ? options.hash.class : 'private-login-password',
|
let className = (options.hash.class) ? options.hash.class : 'private-login-password',
|
||||||
extras = 'autofocus="autofocus"',
|
extras = 'autofocus="autofocus"',
|
||||||
output;
|
output;
|
||||||
|
|
||||||
if (options.hash.placeholder) {
|
if (options.hash.placeholder) {
|
||||||
extras += ' placeholder="' + options.hash.placeholder + '"';
|
extras += ` placeholder="${options.hash.placeholder}"`;
|
||||||
}
|
}
|
||||||
|
|
||||||
output = templates.input({
|
output = templates.input({
|
||||||
type: 'password',
|
type: 'password',
|
||||||
name: 'password',
|
name: 'password',
|
||||||
className: className,
|
className,
|
||||||
extras: extras
|
extras
|
||||||
});
|
});
|
||||||
|
|
||||||
return new SafeString(output);
|
return new SafeString(output);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
var fs = require('fs-extra'),
|
const fs = require('fs-extra'),
|
||||||
session = require('cookie-session'),
|
session = require('cookie-session'),
|
||||||
crypto = require('crypto'),
|
crypto = require('crypto'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
|
@ -8,22 +8,23 @@ var fs = require('fs-extra'),
|
||||||
common = require('../../../lib/common'),
|
common = require('../../../lib/common'),
|
||||||
settingsCache = require('../../../services/settings/cache'),
|
settingsCache = require('../../../services/settings/cache'),
|
||||||
// routeKeywords.private: 'private'
|
// routeKeywords.private: 'private'
|
||||||
privateRoute = '/private/',
|
privateRoute = '/private/';
|
||||||
privateBlogging;
|
|
||||||
|
let privateBlogging = null;
|
||||||
|
|
||||||
function verifySessionHash(salt, hash) {
|
function verifySessionHash(salt, hash) {
|
||||||
if (!salt || !hash) {
|
if (!salt || !hash) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var hasher = crypto.createHash('sha256');
|
let hasher = crypto.createHash('sha256');
|
||||||
hasher.update(settingsCache.get('password') + salt, 'utf8');
|
hasher.update(settingsCache.get('password') + salt, 'utf8');
|
||||||
return hasher.digest('hex') === hash;
|
return hasher.digest('hex') === hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
privateBlogging = {
|
privateBlogging = {
|
||||||
checkIsPrivate: function checkIsPrivate(req, res, next) {
|
checkIsPrivate: function checkIsPrivate(req, res, next) {
|
||||||
var isPrivateBlog = settingsCache.get('is_private');
|
let isPrivateBlog = settingsCache.get('is_private');
|
||||||
|
|
||||||
if (!isPrivateBlog) {
|
if (!isPrivateBlog) {
|
||||||
res.isPrivateBlog = false;
|
res.isPrivateBlog = false;
|
||||||
|
@ -81,7 +82,7 @@ privateBlogging = {
|
||||||
},
|
},
|
||||||
|
|
||||||
authenticatePrivateSession: function authenticatePrivateSession(req, res, next) {
|
authenticatePrivateSession: function authenticatePrivateSession(req, res, next) {
|
||||||
var hash = req.session.token || '',
|
let hash = req.session.token || '',
|
||||||
salt = req.session.salt || '',
|
salt = req.session.salt || '',
|
||||||
isVerified = verifySessionHash(salt, hash),
|
isVerified = verifySessionHash(salt, hash),
|
||||||
url;
|
url;
|
||||||
|
@ -101,7 +102,7 @@ privateBlogging = {
|
||||||
return res.redirect(urlService.utils.urlFor('home', true));
|
return res.redirect(urlService.utils.urlFor('home', true));
|
||||||
}
|
}
|
||||||
|
|
||||||
var hash = req.session.token || '',
|
let hash = req.session.token || '',
|
||||||
salt = req.session.salt || '',
|
salt = req.session.salt || '',
|
||||||
isVerified = verifySessionHash(salt, hash);
|
isVerified = verifySessionHash(salt, hash);
|
||||||
|
|
||||||
|
@ -119,7 +120,7 @@ privateBlogging = {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
var bodyPass = req.body.password,
|
let bodyPass = req.body.password,
|
||||||
pass = settingsCache.get('password'),
|
pass = settingsCache.get('password'),
|
||||||
hasher = crypto.createHash('sha256'),
|
hasher = crypto.createHash('sha256'),
|
||||||
salt = Date.now().toString(),
|
salt = Date.now().toString(),
|
||||||
|
|
|
@ -11,12 +11,12 @@ function _renderer(req, res) {
|
||||||
res.routerOptions = {
|
res.routerOptions = {
|
||||||
type: 'custom',
|
type: 'custom',
|
||||||
templates: templateName,
|
templates: templateName,
|
||||||
defaultTemplate: path.resolve(__dirname, 'views', templateName + '.hbs')
|
defaultTemplate: path.resolve(__dirname, 'views', `${templateName}.hbs`)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Renderer begin
|
// Renderer begin
|
||||||
// Format data
|
// Format data
|
||||||
var data = {};
|
let data = {};
|
||||||
|
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
data.error = res.error;
|
data.error = res.error;
|
||||||
|
|
Loading…
Add table
Reference in a new issue