2014-05-09 00:00:10 -05:00
|
|
|
var User = DS.Model.extend({
|
|
|
|
uuid: DS.attr('string'),
|
|
|
|
name: DS.attr('string'),
|
|
|
|
slug: DS.attr('string'),
|
|
|
|
password: DS.attr('string'),
|
|
|
|
email: DS.attr('string'),
|
|
|
|
image: DS.attr('string'),
|
|
|
|
cover: DS.attr('string'),
|
|
|
|
bio: DS.attr('string'),
|
|
|
|
website: DS.attr('string'),
|
|
|
|
location: DS.attr('string'),
|
|
|
|
accessibility: DS.attr('string'),
|
|
|
|
status: DS.attr('string'),
|
2014-07-05 03:06:10 -05:00
|
|
|
language: DS.attr('string', {defaultValue: 'en_US'}),
|
2014-05-09 00:00:10 -05:00
|
|
|
meta_title: DS.attr('string'),
|
|
|
|
meta_description: DS.attr('string'),
|
2014-06-05 11:04:59 -05:00
|
|
|
last_login: DS.attr('moment-date'),
|
|
|
|
created_at: DS.attr('moment-date'),
|
2014-05-09 00:00:10 -05:00
|
|
|
created_by: DS.attr('number'),
|
2014-06-05 11:04:59 -05:00
|
|
|
updated_at: DS.attr('moment-date'),
|
2014-05-09 00:00:10 -05:00
|
|
|
updated_by: DS.attr('number'),
|
2014-05-14 18:36:13 -05:00
|
|
|
|
2014-05-09 00:00:10 -05:00
|
|
|
validationErrors: function () {
|
2014-03-22 21:31:45 -05:00
|
|
|
var validationErrors = [];
|
|
|
|
|
|
|
|
if (!validator.isLength(this.get('name'), 0, 150)) {
|
2014-06-01 15:53:16 -05:00
|
|
|
validationErrors.push({message: 'Name is too long'});
|
2014-03-22 21:31:45 -05:00
|
|
|
}
|
2014-04-28 15:42:38 -05:00
|
|
|
|
2014-03-22 21:31:45 -05:00
|
|
|
if (!validator.isLength(this.get('bio'), 0, 200)) {
|
2014-06-01 15:53:16 -05:00
|
|
|
validationErrors.push({message: 'Bio is too long'});
|
2014-03-22 21:31:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!validator.isEmail(this.get('email'))) {
|
2014-06-01 15:53:16 -05:00
|
|
|
validationErrors.push({message: 'Please supply a valid email address'});
|
2014-03-22 21:31:45 -05:00
|
|
|
}
|
2014-04-28 15:42:38 -05:00
|
|
|
|
2014-03-22 21:31:45 -05:00
|
|
|
if (!validator.isLength(this.get('location'), 0, 150)) {
|
2014-06-01 15:53:16 -05:00
|
|
|
validationErrors.push({message: 'Location is too long'});
|
2014-03-22 21:31:45 -05:00
|
|
|
}
|
|
|
|
|
2014-06-09 11:17:39 -05:00
|
|
|
if (!validator.isURL(this.get('website'), { protocols: ['http', 'https'], require_protocol: true }) ||
|
|
|
|
!validator.isLength(this.get('website'), 0, 2000)) {
|
|
|
|
validationErrors.push({message: 'Please use a valid url'});
|
2014-03-22 21:31:45 -05:00
|
|
|
}
|
2014-04-28 15:42:38 -05:00
|
|
|
|
2014-05-09 00:00:10 -05:00
|
|
|
return validationErrors;
|
|
|
|
}.property('name', 'bio', 'email', 'location', 'website'),
|
2014-03-22 21:31:45 -05:00
|
|
|
|
2014-05-09 00:00:10 -05:00
|
|
|
isValid: Ember.computed.empty('validationErrors.[]'),
|
2014-03-22 21:31:45 -05:00
|
|
|
|
|
|
|
saveNewPassword: function (password) {
|
2014-05-09 00:00:10 -05:00
|
|
|
var url = this.get('ghostPaths').adminUrl('changepw');
|
|
|
|
return ic.ajax.request(url, {
|
2014-03-22 21:31:45 -05:00
|
|
|
type: 'POST',
|
|
|
|
data: password
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-05-09 00:00:10 -05:00
|
|
|
passwordValidationErrors: function (password) {
|
2014-03-22 21:31:45 -05:00
|
|
|
var validationErrors = [];
|
|
|
|
|
2014-03-31 04:57:50 -05:00
|
|
|
if (!validator.equals(password.newPassword, password.ne2Password)) {
|
2014-06-01 15:53:16 -05:00
|
|
|
validationErrors.push('Your new passwords do not match');
|
2014-03-22 21:31:45 -05:00
|
|
|
}
|
|
|
|
|
2014-03-31 04:57:50 -05:00
|
|
|
if (!validator.isLength(password.newPassword, 8)) {
|
2014-06-01 15:53:16 -05:00
|
|
|
validationErrors.push('Your password is not long enough. It must be at least 8 characters long.');
|
2014-03-22 21:31:45 -05:00
|
|
|
}
|
|
|
|
|
2014-05-09 00:00:10 -05:00
|
|
|
return validationErrors;
|
2014-03-25 18:34:30 -05:00
|
|
|
},
|
2014-05-07 16:28:29 -05:00
|
|
|
|
2014-03-31 04:57:50 -05:00
|
|
|
|
2014-06-27 14:08:16 -05:00
|
|
|
|
|
|
|
|
2014-03-22 21:31:45 -05:00
|
|
|
});
|
2013-08-05 12:26:44 -05:00
|
|
|
|
2014-05-09 00:00:10 -05:00
|
|
|
export default User;
|