Prevent loading setup screen if already setup

Closes #3145
- Prevent navigation to the setup screen if Ghost setup
  has previously been completed.
- Fix templates that were incorrectly using foreach instead of each.
- Add validation for minimum password length.
- Fix up functional tests and split out tests for setup to a separate
  instance of casper because setup requires a new database.
- Add a cleanDatabase task to grunt which resets the database to
  new.
This commit is contained in:
Jason Williams 2014-07-15 19:52:44 +00:00
parent 3027c9fcdc
commit 25ff26016e
4 changed files with 28 additions and 9 deletions

View File

@ -3,10 +3,29 @@ import loadingIndicator from 'ghost/mixins/loading-indicator';
var SetupRoute = Ember.Route.extend(styleBody, loadingIndicator, {
classNames: ['ghost-setup'],
// use the beforeModel hook to check to see whether or not setup has been
// previously completed. If it has, stop the transition into the setup page.
beforeModel: function () {
var self = this;
// If user is logged in, setup has already been completed.
if (this.get('session').isAuthenticated) {
this.transitionTo(Ember.SimpleAuth.routeAfterAuthentication);
return;
}
// If user is not logged in, check the state of the setup process via the API
return ic.ajax.request(this.get('ghostPaths.url').api('authentication/setup'), {
type: 'GET'
}).then(function (result) {
var setup = result.setup[0].status;
if (setup) {
return self.transitionTo('signin');
}
});
}
});

View File

@ -16,13 +16,13 @@
<h3>Stack Trace</h3>
<p><strong>{{message}}</strong></p>
<ul class="error-stack-list">
{{#foreach stack}}
{{#each stack}}
<li>
at
{{#if function}}<em class="error-stack-function">{{function}}</em>{{/if}}
<span class="error-stack-file">({{at}})</span>
</li>
{{/foreach}}
{{/each}}
</ul>
</section>
{{/if}}

View File

@ -3,13 +3,13 @@ var SetupValidator = Ember.Object.create({
var data = model.getProperties('blogTitle', 'name', 'email', 'password'),
validationErrors = [];
if (!validator.isLength(data.blogTitle || '', 1)) {
if (!validator.isLength(data.blogTitle, 1)) {
validationErrors.push({
message: 'Please enter a blog title.'
});
}
if (!validator.isLength(data.name || '', 1)) {
if (!validator.isLength(data.name, 1)) {
validationErrors.push({
message: 'Please enter a name.'
});
@ -21,9 +21,9 @@ var SetupValidator = Ember.Object.create({
});
}
if (!validator.isLength(data.password || '', 1)) {
if (!validator.isLength(data.password, 8)) {
validationErrors.push({
message: 'Please enter a password.'
message: 'Password must be at least 8 characters long.'
});
}

View File

@ -3,7 +3,7 @@ var SignupValidator = Ember.Object.create({
var data = model.getProperties('name', 'email', 'password'),
validationErrors = [];
if (!validator.isLength(data.name || '', 1)) {
if (!validator.isLength(data.name, 1)) {
validationErrors.push({
message: 'Please enter a name.'
});
@ -15,9 +15,9 @@ var SignupValidator = Ember.Object.create({
});
}
if (!validator.isLength(data.password || '', 1)) {
if (!validator.isLength(data.password, 8)) {
validationErrors.push({
message: 'Please enter a password.'
message: 'Password must be at least 8 characters long.'
});
}