0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Improve validation for user.website

closes #4444
- validate URL without protocol in server and client
- when saving url, add `http://` if the url doesn't have a protocol
This commit is contained in:
Victor Szeto 2014-11-16 23:35:32 -05:00
parent f76088169a
commit 2e8e2ce367
2 changed files with 11 additions and 1 deletions

View file

@ -51,7 +51,7 @@ var UserValidator = Ember.Object.create({
}
if (!Ember.isEmpty(website) &&
(!validator.isURL(website, {protocols: ['http', 'https'], require_protocol: true}) ||
(!validator.isURL(website, {require_protocol: false}) ||
!validator.isLength(website, 0, 2000))) {
validationErrors.push({message: 'Website is not a valid url'});
}

View file

@ -94,6 +94,16 @@ User = ghostBookshelf.Model.extend({
return attrs;
},
format: function (options) {
if (!_.isEmpty(options.website) &&
!validator.isURL(options.website, {
require_protocol: true,
protocols: ['http', 'https']})) {
options.website = 'http://' + options.website;
}
return options;
},
posts: function () {
return this.hasMany('Posts', 'created_by');
},