diff --git a/app/controllers/feature.js b/app/controllers/feature.js index 2e9c829d9..e2389e0a3 100644 --- a/app/controllers/feature.js +++ b/app/controllers/feature.js @@ -24,6 +24,10 @@ 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/app/controllers/settings.js b/app/controllers/settings.js index 2f2bec592..27346eef9 100644 --- a/app/controllers/settings.js +++ b/app/controllers/settings.js @@ -1,6 +1,8 @@ import Ember from 'ember'; var SettingsController = Ember.Controller.extend({ + needs: ['feature'], + showGeneral: Ember.computed('session.user.name', function () { return this.get('session.user.isAuthor') || this.get('session.user.isEditor') ? false : true; }), @@ -21,6 +23,9 @@ var SettingsController = Ember.Controller.extend({ }), showAbout: Ember.computed('session.user.name', function () { return this.get('session.user.isAuthor') ? false : true; + }), + showPassProtection: Ember.computed('session.user.name', 'controllers.feature.passProtectUI', function () { + return this.get('session.user.isAuthor') || this.get('session.user.isEditor') || !this.get('controllers.feature.passProtectUI') ? false : true; }) }); diff --git a/app/controllers/settings/labs.js b/app/controllers/settings/labs.js index 0cfd0062b..f5e90b212 100644 --- a/app/controllers/settings/labs.js +++ b/app/controllers/settings/labs.js @@ -23,6 +23,16 @@ 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/app/controllers/settings/pass-protect.js b/app/controllers/settings/pass-protect.js new file mode 100644 index 000000000..7f4f5288c --- /dev/null +++ b/app/controllers/settings/pass-protect.js @@ -0,0 +1,27 @@ +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/app/models/setting.js b/app/models/setting.js index 2b63b9ae1..b30abfdbb 100644 --- a/app/models/setting.js +++ b/app/models/setting.js @@ -19,7 +19,9 @@ var Setting = DS.Model.extend(NProgressSaveMixin, ValidationEngine, { ghost_head: DS.attr('string'), ghost_foot: DS.attr('string'), labs: DS.attr('string'), - navigation: DS.attr('string') + navigation: DS.attr('string'), + isPrivate: DS.attr('boolean'), + password: DS.attr('string') }); export default Setting; diff --git a/app/router.js b/app/router.js index 18adc0948..f5396bae2 100644 --- a/app/router.js +++ b/app/router.js @@ -43,6 +43,7 @@ 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/app/routes/settings/pass-protect.js b/app/routes/settings/pass-protect.js new file mode 100644 index 000000000..02173f3e6 --- /dev/null +++ b/app/routes/settings/pass-protect.js @@ -0,0 +1,45 @@ +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/app/templates/settings.hbs b/app/templates/settings.hbs index db30c06ba..9cf2c1feb 100644 --- a/app/templates/settings.hbs +++ b/app/templates/settings.hbs @@ -27,6 +27,10 @@ {{gh-activating-list-item route="settings.code-injection" title="Code Injection" classNames="settings-nav-code icon-code"}} {{/if}} + {{#if showPassProtection}} + {{gh-activating-list-item route="settings.pass-protect" title="Password Protection" classNames="settings-nav-pass icon-lock"}} + {{/if}} + {{#if showLabs}} {{gh-activating-list-item route="settings.labs" title="Labs" classNames="settings-nav-labs icon-atom"}} {{/if}} diff --git a/app/templates/settings/labs.hbs b/app/templates/settings/labs.hbs index db4719979..9ab2e32bc 100644 --- a/app/templates/settings/labs.hbs +++ b/app/templates/settings/labs.hbs @@ -44,4 +44,21 @@ +
+ +
+
+
+ + +

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

+
+
+
+ diff --git a/app/templates/settings/pass-protect.hbs b/app/templates/settings/pass-protect.hbs new file mode 100644 index 000000000..06ad3b981 --- /dev/null +++ b/app/templates/settings/pass-protect.hbs @@ -0,0 +1,29 @@ +
+ {{#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/app/views/settings/pass-protect.js b/app/views/settings/pass-protect.js new file mode 100644 index 000000000..235261fac --- /dev/null +++ b/app/views/settings/pass-protect.js @@ -0,0 +1,5 @@ +import BaseView from 'ghost/views/settings/content-base'; + +var SettingsGeneralView = BaseView.extend(); + +export default SettingsGeneralView;