Skip to content

Commit

Permalink
finish up password protection
Browse files Browse the repository at this point in the history
closes TryGhost#5073
- takes password protection out of labs and moves it to general settings
- adds random-words generator to randomly generate passwords
  • Loading branch information
acburdine committed May 12, 2015
1 parent f6b56ad commit bd2b206
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 135 deletions.
1 change: 1 addition & 0 deletions core/client/Brocfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ app.import('bower_components/codemirror/mode/xml/xml.js');
app.import('bower_components/codemirror/mode/css/css.js');
app.import('bower_components/codemirror/mode/javascript/javascript.js');
app.import('bower_components/xregexp/xregexp-all.js');
app.import('bower_components/password-generator/lib/password-generator.js');

module.exports = app.toTree();
4 changes: 0 additions & 4 deletions core/client/app/controllers/feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ var FeatureController = Ember.Controller.extend(Ember.PromiseProxyMixin, {
}

return value;
}),

passProtectUI: Ember.computed('config.passProtectUI', 'labs.passProtectUI', function () {
return this.get('config.passProtectUI') || this.get('labs.passProtectUI');
})
});

Expand Down
8 changes: 8 additions & 0 deletions core/client/app/controllers/settings/general.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Ember from 'ember';
import randomPassword from 'ghost/utils/random-password';

var SettingsGeneralController = Ember.Controller.extend({
selectedTheme: null,

Expand Down Expand Up @@ -37,6 +39,12 @@ var SettingsGeneralController = Ember.Controller.extend({
}, []);
}).readOnly(),

generatePassword: Ember.observer('model.isPrivate', function () {
if (this.get('model.isPrivate') && this.get('model.isDirty')) {
this.get('model').set('password', randomPassword());
}
}),

actions: {
save: function () {
var self = this;
Expand Down
10 changes: 0 additions & 10 deletions core/client/app/controllers/settings/labs.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ var LabsController = Ember.Controller.extend(Ember.Evented, {
});
},

usePassProtectUI: Ember.computed('controllers.feature.passProtectUI', function (key, value) {
// setter
if (arguments.length > 1) {
this.saveLabs('passProtectUI', value);
}

// getter
return this.get('controllers.feature.passProtectUI');
}),

actions: {
onUpload: function (file) {
var self = this,
Expand Down
27 changes: 0 additions & 27 deletions core/client/app/controllers/settings/pass-protect.js

This file was deleted.

1 change: 0 additions & 1 deletion core/client/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ Router.map(function () {
this.route('labs');
this.route('code-injection');
this.route('navigation');
this.route('pass-protect');
});

// Redirect debug to settings labs
Expand Down
45 changes: 0 additions & 45 deletions core/client/app/routes/settings/pass-protect.js

This file was deleted.

17 changes: 17 additions & 0 deletions core/client/app/templates/settings/general.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@
</span>
<p>Select a theme for your blog</p>
</div>

<div class="form-group for-checkbox">
<label for="isPrivate">Make this blog private</label>
<label class="checkbox" for="isPrivate">
{{input id="isPrivate" name="general[isPrivate]" type="checkbox"
checked=model.isPrivate}}
<span class="input-toggle-component"></span>
<p>Enable password protection</p>
</label>
</div>

{{#if model.isPrivate}}
<div class="form-group">
{{input name="general[password]" type="text" value=model.password}}
<p>This password will be needed to access your blog. All search engine optimization and social features are now disabled.</p>
</div>
{{/if}}
</fieldset>
</form>
</section>
17 changes: 0 additions & 17 deletions core/client/app/templates/settings/labs.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,4 @@
</fieldset>
</form>

<hr>

<form>
<fieldset>
<div class="form-group for-checkbox">
<label for="labs-passProtectUI">Password Protection</label>
<label class="checkbox" for="labs-passProtectUI">
{{input id="labs-passProtectUI" name="labs[passProtectUI]" type="checkbox"
checked=usePassProtectUI}}
<span class="input-toggle-component"></span>
<p>Enable the password protection interface</p>
</label>
<p>A settings screen which enables you to add password protection to the front of your blog (work in progress)</p>
</div>
</fieldset>
</form>

</section>
29 changes: 0 additions & 29 deletions core/client/app/templates/settings/pass-protect.hbs

This file was deleted.

10 changes: 10 additions & 0 deletions core/client/app/utils/random-password.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* global generatePassword */

function randomPassword() {
var word = generatePassword(6),
randomN = Math.floor(Math.random() * 1000);

return word + randomN;
}

export default randomPassword;
8 changes: 7 additions & 1 deletion core/client/app/validators/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ var SettingValidator = Ember.Object.create({
title = model.get('title'),
description = model.get('description'),
email = model.get('email'),
postsPerPage = model.get('postsPerPage');
postsPerPage = model.get('postsPerPage'),
isPrivate = model.get('isPrivate'),
password = model.get('password');

if (!validator.isLength(title, 0, 150)) {
validationErrors.push({message: 'Title is too long'});
Expand All @@ -19,6 +21,10 @@ var SettingValidator = Ember.Object.create({
validationErrors.push({message: 'Supply a valid email address'});
}

if (isPrivate && password === '') {
validationErrors.push({message: 'Password must be supplied'});
}

if (postsPerPage > 1000) {
validationErrors.push({message: 'The maximum number of posts per page is 1000'});
}
Expand Down
1 change: 1 addition & 0 deletions core/client/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"nanoscroller": "0.8.4",
"normalize-scss": "3.0.2",
"nprogress": "0.1.6",
"password-generator": "git://github.com/bermi/password-generator#49accd7",
"rangyinputs": "1.2.0",
"showdown-ghost": "0.3.6",
"validator-js": "3.39.0",
Expand Down
1 change: 0 additions & 1 deletion core/server/api/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ var _ = require('lodash'),
function getValidKeys() {
var validKeys = {
fileStorage: config.fileStorage === false ? false : true,
passProtectUI: config.passProtectUI === true ? true : false,
apps: config.apps === true ? true : false,
version: config.ghostVersion,
environment: process.env.NODE_ENV,
Expand Down

0 comments on commit bd2b206

Please sign in to comment.