mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-14 09:52:09 +03:00
c28d8e6044
closes #3162 - removes injection of user object in application route's beforeModel - removes injection/cleanup of user object in signedIn/signedOut actions - removes loading of user and passing to signedIn action in signup/setup controllers - adds 'user' property to session object - updates header nav to reference session.user - sets model of settings/user route to session.user and forces reload - on leaving settings/user, rollback any unsaved changes
71 lines
2.3 KiB
JavaScript
71 lines
2.3 KiB
JavaScript
/*global alert */
|
|
var SettingsUserController = Ember.ObjectController.extend({
|
|
|
|
user: Ember.computed.alias('model'),
|
|
|
|
coverDefault: '/shared/img/user-cover.png',
|
|
cover: function () {
|
|
// @TODO: add {{asset}} subdir path
|
|
var cover = this.get('user.cover');
|
|
if (typeof cover !== 'string') {
|
|
cover = this.get('coverDefault');
|
|
}
|
|
return cover;
|
|
}.property('user.cover', 'coverDefault'),
|
|
|
|
coverTitle: function () {
|
|
return this.get('user.name') + '\'s Cover Image';
|
|
}.property('user.name'),
|
|
|
|
image: function () {
|
|
// @TODO: add {{asset}} subdir path
|
|
return 'background-image: url(' + this.getWithDefault('user.image', '/shared/img/user-image.png') + ')';
|
|
}.property('user.image'),
|
|
|
|
actions: {
|
|
save: function () {
|
|
var user = this.get('user'),
|
|
self = this;
|
|
|
|
self.notifications.closePassive();
|
|
|
|
alert('@TODO: Saving user...');
|
|
|
|
if (user.validate().get('isValid')) {
|
|
user.save().then(function (response) {
|
|
alert('Done saving' + JSON.stringify(response));
|
|
}, function () {
|
|
alert('Error saving.');
|
|
});
|
|
} else {
|
|
alert('Errors found! ' + JSON.stringify(user.get('errors')));
|
|
}
|
|
},
|
|
|
|
password: function () {
|
|
alert('@TODO: Changing password...');
|
|
var user = this.get('user'),
|
|
passwordProperties = this.getProperties('password', 'newPassword', 'ne2Password');
|
|
|
|
if (user.validatePassword(passwordProperties).get('passwordIsValid')) {
|
|
user.saveNewPassword(passwordProperties).then(function () {
|
|
alert('Success!');
|
|
// Clear properties from view
|
|
this.setProperties({
|
|
'password': '',
|
|
'newpassword': '',
|
|
'ne2password': ''
|
|
});
|
|
}.bind(this), function (errors) {
|
|
alert('Errors ' + JSON.stringify(errors));
|
|
});
|
|
} else {
|
|
alert('Errors found! ' + JSON.stringify(user.get('passwordErrors')));
|
|
}
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
export default SettingsUserController;
|