From ed9fdbca7ff06f6efe84b62ce6a5cc6b7401275f Mon Sep 17 00:00:00 2001 From: Austin Burdine Date: Mon, 11 May 2015 09:35:55 -0600 Subject: [PATCH] finish up password protection closes #5073 - takes password protection out of labs and moves it to general settings - adds random-words generator to randomly generate passwords --- ghost/admin/Brocfile.js | 1 + ghost/admin/app/controllers/feature.js | 4 -- .../admin/app/controllers/settings/general.js | 8 ++++ ghost/admin/app/controllers/settings/labs.js | 10 ----- .../app/controllers/settings/pass-protect.js | 27 ----------- ghost/admin/app/router.js | 1 - .../admin/app/routes/settings/pass-protect.js | 45 ------------------- .../admin/app/templates/settings/general.hbs | 17 +++++++ ghost/admin/app/templates/settings/labs.hbs | 17 ------- .../app/templates/settings/pass-protect.hbs | 29 ------------ ghost/admin/app/utils/random-password.js | 10 +++++ ghost/admin/app/validators/setting.js | 8 +++- ghost/admin/bower.json | 1 + 13 files changed, 44 insertions(+), 134 deletions(-) delete mode 100644 ghost/admin/app/controllers/settings/pass-protect.js delete mode 100644 ghost/admin/app/routes/settings/pass-protect.js delete mode 100644 ghost/admin/app/templates/settings/pass-protect.hbs create mode 100644 ghost/admin/app/utils/random-password.js diff --git a/ghost/admin/Brocfile.js b/ghost/admin/Brocfile.js index 4d89258a04..6d9a7d5f7e 100644 --- a/ghost/admin/Brocfile.js +++ b/ghost/admin/Brocfile.js @@ -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(); diff --git a/ghost/admin/app/controllers/feature.js b/ghost/admin/app/controllers/feature.js index e2389e0a3e..2e9c829d9a 100644 --- a/ghost/admin/app/controllers/feature.js +++ b/ghost/admin/app/controllers/feature.js @@ -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'); }) }); diff --git a/ghost/admin/app/controllers/settings/general.js b/ghost/admin/app/controllers/settings/general.js index 7c76cb7007..7efddc613f 100644 --- a/ghost/admin/app/controllers/settings/general.js +++ b/ghost/admin/app/controllers/settings/general.js @@ -1,4 +1,6 @@ import Ember from 'ember'; +import randomPassword from 'ghost/utils/random-password'; + var SettingsGeneralController = Ember.Controller.extend({ selectedTheme: null, @@ -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; diff --git a/ghost/admin/app/controllers/settings/labs.js b/ghost/admin/app/controllers/settings/labs.js index f5e90b2127..0cfd0062bb 100644 --- a/ghost/admin/app/controllers/settings/labs.js +++ b/ghost/admin/app/controllers/settings/labs.js @@ -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, diff --git a/ghost/admin/app/controllers/settings/pass-protect.js b/ghost/admin/app/controllers/settings/pass-protect.js deleted file mode 100644 index 7f4f5288cd..0000000000 --- a/ghost/admin/app/controllers/settings/pass-protect.js +++ /dev/null @@ -1,27 +0,0 @@ -import Ember from 'ember'; - -var SettingsPassProtectController = Ember.Controller.extend({ - - actions: { - save: function () { - var self = this; - if (this.get('model.isPrivate') && this.get('model.password') === '') { - self.notifications.closePassive(); - self.notifications.showError('Password must have a value.'); - return; - } - - return this.get('model').save().then(function (model) { - self.notifications.closePassive(); - self.notifications.showSuccess('Settings successfully saved.'); - - return model; - }).catch(function (errors) { - self.notifications.closePassive(); - self.notifications.showErrors(errors); - }); - } - } -}); - -export default SettingsPassProtectController; diff --git a/ghost/admin/app/router.js b/ghost/admin/app/router.js index f5396bae23..18adc09487 100644 --- a/ghost/admin/app/router.js +++ b/ghost/admin/app/router.js @@ -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 diff --git a/ghost/admin/app/routes/settings/pass-protect.js b/ghost/admin/app/routes/settings/pass-protect.js deleted file mode 100644 index 02173f3e68..0000000000 --- a/ghost/admin/app/routes/settings/pass-protect.js +++ /dev/null @@ -1,45 +0,0 @@ -import AuthenticatedRoute from 'ghost/routes/authenticated'; -import loadingIndicator from 'ghost/mixins/loading-indicator'; -import CurrentUserSettings from 'ghost/mixins/current-user-settings'; -import styleBody from 'ghost/mixins/style-body'; - -var SettingsPassProtectRoute = AuthenticatedRoute.extend(styleBody, loadingIndicator, CurrentUserSettings, { - - classNames: ['settings-view-pass'], - - beforeModel: function () { - var feature = this.controllerFor('feature'), - self = this; - - if (!feature) { - this.generateController('feature'); - feature = this.controllerFor('feature'); - } - - return this.get('session.user') - .then(this.transitionAuthor()) - .then(this.transitionEditor()) - .then(function () { - return feature.then(function () { - if (!feature.get('passProtectUI')) { - return self.transitionTo('settings.general'); - } - }); - }); - }, - - model: function () { - return this.store.find('setting', {type: 'blog,theme'}).then(function (records) { - return records.get('firstObject'); - }); - }, - - actions: { - save: function () { - this.get('controller').send('save'); - } - } - -}); - -export default SettingsPassProtectRoute; diff --git a/ghost/admin/app/templates/settings/general.hbs b/ghost/admin/app/templates/settings/general.hbs index 9fcd147989..305ab158b2 100644 --- a/ghost/admin/app/templates/settings/general.hbs +++ b/ghost/admin/app/templates/settings/general.hbs @@ -84,6 +84,23 @@

Select a theme for your blog

+ +
+ + +
+ + {{#if model.isPrivate}} +
+ {{input name="general[password]" type="text" value=model.password}} +

This password will be needed to access your blog. All search engine optimization and social features are now disabled.

+
+ {{/if}} diff --git a/ghost/admin/app/templates/settings/labs.hbs b/ghost/admin/app/templates/settings/labs.hbs index 9ab2e32bcf..db4719979a 100644 --- a/ghost/admin/app/templates/settings/labs.hbs +++ b/ghost/admin/app/templates/settings/labs.hbs @@ -44,21 +44,4 @@ -
- -
-
-
- - -

A settings screen which enables you to add password protection to the front of your blog (work in progress)

-
-
-
- diff --git a/ghost/admin/app/templates/settings/pass-protect.hbs b/ghost/admin/app/templates/settings/pass-protect.hbs deleted file mode 100644 index 06ad3b9817..0000000000 --- a/ghost/admin/app/templates/settings/pass-protect.hbs +++ /dev/null @@ -1,29 +0,0 @@ -
- {{#link-to "settings" class="btn btn-default btn-back"}}Back{{/link-to}} -

Password protect your blog

-
- -
-
- -
-
-
-
- - -
- {{#if model.isPrivate}} -
- {{input name="private[password]" type="text" value=model.password}} -

This password will be needed to access your blog. All search engine optimization and social features are now disabled.

-
- {{/if}} -
-
-
diff --git a/ghost/admin/app/utils/random-password.js b/ghost/admin/app/utils/random-password.js new file mode 100644 index 0000000000..0e8c5b6c74 --- /dev/null +++ b/ghost/admin/app/utils/random-password.js @@ -0,0 +1,10 @@ +/* global generatePassword */ + +function randomPassword() { + var word = generatePassword(6), + randomN = Math.floor(Math.random() * 1000); + + return word + randomN; +} + +export default randomPassword; diff --git a/ghost/admin/app/validators/setting.js b/ghost/admin/app/validators/setting.js index 280b948e49..3f8bb24107 100644 --- a/ghost/admin/app/validators/setting.js +++ b/ghost/admin/app/validators/setting.js @@ -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'}); @@ -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'}); } diff --git a/ghost/admin/bower.json b/ghost/admin/bower.json index ecdd4c39cc..c822e301cd 100644 --- a/ghost/admin/bower.json +++ b/ghost/admin/bower.json @@ -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",