From 8f53631d5b15879ac3ff5957e61139645a5f6b83 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Mon, 12 Jan 2015 03:15:13 +0000 Subject: [PATCH] Fixup validation engine to handle lack of proxying Closes #4766 - Adjust ValidationEngine so it no longer assumes the properties it is validating are proxies via ObjectController. - Fixup controllers, templates, and routes to use models where data needs to be validated. --- ghost/admin/controllers/signin.js | 3 ++- ghost/admin/controllers/signup.js | 3 ++- ghost/admin/mixins/validation-engine.js | 21 +++++++++++++++++---- ghost/admin/routes/signin.js | 15 ++++++++++++--- ghost/admin/routes/signup.js | 6 +++--- ghost/admin/templates/signin.hbs | 4 ++-- 6 files changed, 38 insertions(+), 14 deletions(-) diff --git a/ghost/admin/controllers/signin.js b/ghost/admin/controllers/signin.js index 1e22c9d2df..beca2f217e 100644 --- a/ghost/admin/controllers/signin.js +++ b/ghost/admin/controllers/signin.js @@ -7,7 +7,8 @@ var SigninController = Ember.Controller.extend(SimpleAuth.AuthenticationControll actions: { authenticate: function () { - var data = this.getProperties('identification', 'password'); + var model = this.get('model'), + data = model.getProperties('identification', 'password'); this._super(data).catch(function () { // If simple-auth's authenticate rejects we need to catch it diff --git a/ghost/admin/controllers/signup.js b/ghost/admin/controllers/signup.js index 82843101b0..5ad8389214 100644 --- a/ghost/admin/controllers/signup.js +++ b/ghost/admin/controllers/signup.js @@ -10,7 +10,8 @@ var SignupController = Ember.Controller.extend(ValidationEngine, { actions: { signup: function () { var self = this, - data = self.getProperties('model.name', 'model.email', 'model.password', 'model.token'); + model = this.get('model'), + data = model.getProperties('name', 'email', 'password', 'token'); self.notifications.closePassive(); diff --git a/ghost/admin/mixins/validation-engine.js b/ghost/admin/mixins/validation-engine.js index 089f1ac06f..bc58b71c3d 100644 --- a/ghost/admin/mixins/validation-engine.js +++ b/ghost/admin/mixins/validation-engine.js @@ -89,11 +89,24 @@ var ValidationEngine = Ember.Mixin.create({ * the class that mixes in this mixin. */ validate: function (opts) { - var model = opts.model || this, - type = this.get('validationType'), - validator = this.get('validators.' + type); - + // jscs:disable safeContextKeyword opts = opts || {}; + + var model = this, + type, + validator; + + if (opts.model) { + model = opts.model; + } else if (this instanceof DS.Model) { + model = this; + } else if (this.get('model')) { + model = this.get('model'); + } + + type = this.get('validationType') || model.get('validationType'); + validator = this.get('validators.' + type) || model.get('validators.' + type); + opts.validationType = type; return new Ember.RSVP.Promise(function (resolve, reject) { diff --git a/ghost/admin/routes/signin.js b/ghost/admin/routes/signin.js index 6db40151d0..62c0706227 100644 --- a/ghost/admin/routes/signin.js +++ b/ghost/admin/routes/signin.js @@ -12,13 +12,22 @@ var SigninRoute = Ember.Route.extend(styleBody, loadingIndicator, { } }, + model: function () { + return Ember.Object.create({ + identification: '', + password: '' + }); + }, + // the deactivate hook is called after a route has been exited. deactivate: function () { this._super(); - // clear the properties that hold the credentials from the controller - // when we're no longer on the signin screen - this.controllerFor('signin').setProperties({identification: '', password: ''}); + var controller = this.controllerFor('signin'); + + // clear the properties that hold the credentials when we're no longer on the signin screen + controller.set('model.identification', ''); + controller.set('model.password', ''); } }); diff --git a/ghost/admin/routes/signup.js b/ghost/admin/routes/signup.js index d49de138ed..b8a5085aa9 100644 --- a/ghost/admin/routes/signup.js +++ b/ghost/admin/routes/signup.js @@ -14,7 +14,7 @@ var SignupRoute = Ember.Route.extend(styleBody, loadingIndicator, { var self = this, tokenText, email, - model = {}, + model = Ember.Object.create(), re = /^(?:[A-Za-z0-9_\-]{4})*(?:[A-Za-z0-9_\-]{2}|[A-Za-z0-9_\-]{3})?$/; return new Ember.RSVP.Promise(function (resolve) { @@ -27,8 +27,8 @@ var SignupRoute = Ember.Route.extend(styleBody, loadingIndicator, { tokenText = atob(params.token); email = tokenText.split('|')[1]; - model.email = email; - model.token = params.token; + model.set('email', email); + model.set('token', params.token); return ic.ajax.request({ url: self.get('ghostPaths.url').api('authentication', 'invitation'), diff --git a/ghost/admin/templates/signin.hbs b/ghost/admin/templates/signin.hbs index 27e2d54e1f..6b505101c1 100644 --- a/ghost/admin/templates/signin.hbs +++ b/ghost/admin/templates/signin.hbs @@ -2,12 +2,12 @@
- {{input class="password" type="password" placeholder="Password" name="password" value=password}} + {{input class="password" type="password" placeholder="Password" name="password" value=model.password}}