2014-07-11 23:01:42 +04:00
|
|
|
import ValidationEngine from 'ghost/mixins/validation-engine';
|
2014-07-06 00:44:19 +04:00
|
|
|
import NProgressSaveMixin from 'ghost/mixins/nprogress-save';
|
2014-07-26 09:12:37 +04:00
|
|
|
import SelectiveSaveMixin from 'ghost/mixins/selective-save';
|
2014-07-11 23:01:42 +04:00
|
|
|
|
2014-07-26 09:12:37 +04:00
|
|
|
var User = DS.Model.extend(NProgressSaveMixin, SelectiveSaveMixin, ValidationEngine, {
|
2014-07-11 23:01:42 +04:00
|
|
|
validationType: 'user',
|
2014-07-14 20:32:55 +04:00
|
|
|
|
2014-05-09 09:00:10 +04:00
|
|
|
uuid: DS.attr('string'),
|
|
|
|
name: DS.attr('string'),
|
|
|
|
slug: 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 12:06:10 +04:00
|
|
|
language: DS.attr('string', {defaultValue: 'en_US'}),
|
2014-05-09 09:00:10 +04:00
|
|
|
meta_title: DS.attr('string'),
|
|
|
|
meta_description: DS.attr('string'),
|
2014-06-05 20:04:59 +04:00
|
|
|
last_login: DS.attr('moment-date'),
|
|
|
|
created_at: DS.attr('moment-date'),
|
2014-07-23 10:13:20 +04:00
|
|
|
created_by: DS.attr('number'),
|
|
|
|
updated_at: DS.attr('moment-date'),
|
|
|
|
updated_by: DS.attr('number'),
|
2014-07-21 01:48:24 +04:00
|
|
|
roles: DS.hasMany('role', { embedded: 'always' }),
|
2014-05-15 03:36:13 +04:00
|
|
|
|
2014-07-22 01:19:46 +04:00
|
|
|
|
|
|
|
// TODO: Once client-side permissions are in place,
|
|
|
|
// remove the hard role check.
|
|
|
|
isAuthor: Ember.computed('roles', function () {
|
|
|
|
return this.get('roles').objectAt(0).get('name').toLowerCase() === 'author';
|
|
|
|
}),
|
|
|
|
|
2014-07-22 01:48:45 +04:00
|
|
|
// TODO: Once client-side permissions are in place,
|
|
|
|
// remove the hard role check.
|
|
|
|
isEditor: Ember.computed('roles', function () {
|
|
|
|
return this.get('roles').objectAt(0).get('name').toLowerCase() === 'editor';
|
|
|
|
}),
|
|
|
|
|
2014-07-13 08:01:26 +04:00
|
|
|
saveNewPassword: function () {
|
|
|
|
var url = this.get('ghostPaths.url').api('users', 'password');
|
2014-05-09 09:00:10 +04:00
|
|
|
return ic.ajax.request(url, {
|
2014-07-13 08:01:26 +04:00
|
|
|
type: 'PUT',
|
|
|
|
data: {
|
|
|
|
password: [{
|
|
|
|
'oldPassword': this.get('password'),
|
|
|
|
'newPassword': this.get('newPassword'),
|
|
|
|
'ne2Password': this.get('ne2Password')
|
|
|
|
}]
|
|
|
|
}
|
2014-03-23 06:31:45 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-07-08 09:24:07 +04:00
|
|
|
resendInvite: function () {
|
2014-07-25 06:42:55 +04:00
|
|
|
var fullUserData = this.toJSON(),
|
|
|
|
userData = {
|
|
|
|
email: fullUserData.email,
|
|
|
|
roles: fullUserData.roles
|
|
|
|
};
|
2014-07-08 09:24:07 +04:00
|
|
|
|
2014-07-13 08:01:26 +04:00
|
|
|
return ic.ajax.request(this.get('ghostPaths.url').api('users'), {
|
2014-07-08 09:24:07 +04:00
|
|
|
type: 'POST',
|
|
|
|
data: JSON.stringify({users: [userData]}),
|
|
|
|
contentType: 'application/json'
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-07-13 08:01:26 +04:00
|
|
|
passwordValidationErrors: function () {
|
2014-03-23 06:31:45 +04:00
|
|
|
var validationErrors = [];
|
|
|
|
|
2014-07-13 08:01:26 +04:00
|
|
|
if (!validator.equals(this.get('newPassword'), this.get('ne2Password'))) {
|
|
|
|
validationErrors.push({message: 'Your new passwords do not match'});
|
2014-03-23 06:31:45 +04:00
|
|
|
}
|
|
|
|
|
2014-07-13 08:01:26 +04:00
|
|
|
if (!validator.isLength(this.get('newPassword'), 8)) {
|
|
|
|
validationErrors.push({message: 'Your password is not long enough. It must be at least 8 characters long.'});
|
2014-03-23 06:31:45 +04:00
|
|
|
}
|
|
|
|
|
2014-05-09 09:00:10 +04:00
|
|
|
return validationErrors;
|
2014-07-13 08:01:26 +04:00
|
|
|
}.property('password', 'newPassword', 'ne2Password'),
|
|
|
|
|
2014-07-19 04:58:27 +04:00
|
|
|
isPasswordValid: Ember.computed.empty('passwordValidationErrors.[]'),
|
|
|
|
active: function () {
|
|
|
|
return _.contains(['active', 'warn-1', 'warn-2', 'warn-3', 'warn-4', 'locked'], this.get('status'));
|
|
|
|
}.property('status'),
|
|
|
|
invited: function () {
|
|
|
|
return _.contains(['invited', 'invited-pending'], this.get('status'));
|
|
|
|
}.property('status'),
|
|
|
|
pending: Ember.computed.equal('status', 'invited-pending').property('status')
|
2014-03-23 06:31:45 +04:00
|
|
|
});
|
2013-08-05 21:26:44 +04:00
|
|
|
|
2014-05-09 09:00:10 +04:00
|
|
|
export default User;
|