2020-03-09 08:00:03 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
import Descriptor from 'salix/components/descriptor';
|
|
|
|
import UserError from 'core/lib/user-error';
|
|
|
|
|
|
|
|
class Controller extends Descriptor {
|
|
|
|
get user() {
|
|
|
|
return this.entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
set user(value) {
|
|
|
|
this.entity = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
get entity() {
|
|
|
|
return super.entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
set entity(value) {
|
|
|
|
super.entity = value;
|
|
|
|
this.hasAccount = null;
|
|
|
|
if (!value) return;
|
|
|
|
|
2023-01-31 13:57:24 +00:00
|
|
|
this.$http.get(`Accounts/${value.id}/exists`)
|
2020-03-09 08:00:03 +00:00
|
|
|
.then(res => this.hasAccount = res.data.exists);
|
|
|
|
}
|
|
|
|
|
2023-09-25 11:06:28 +00:00
|
|
|
loadData() {
|
|
|
|
const filter = {
|
|
|
|
where: {id: this.$params.id},
|
|
|
|
include: {
|
|
|
|
relation: 'role',
|
|
|
|
scope: {
|
|
|
|
fields: ['id', 'name']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return Promise.all([
|
|
|
|
this.$http.get(`VnUsers/preview`, {filter})
|
|
|
|
.then(res => {
|
|
|
|
const [user] = res.data;
|
|
|
|
this.user = user;
|
|
|
|
}),
|
|
|
|
this.$http.get(`Accounts/${this.$params.id}/exists`)
|
|
|
|
.then(res => this.hasAccount = res.data.exists)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-03-09 08:00:03 +00:00
|
|
|
onDelete() {
|
2023-01-23 14:24:00 +00:00
|
|
|
return this.$http.delete(`VnUsers/${this.id}`)
|
2020-03-09 08:00:03 +00:00
|
|
|
.then(() => this.$state.go('account.index'))
|
|
|
|
.then(() => this.vnApp.showSuccess(this.$t('User removed')));
|
|
|
|
}
|
|
|
|
|
|
|
|
onChangePassClick(askOldPass) {
|
|
|
|
this.$http.get('UserPasswords/findOne')
|
|
|
|
.then(res => {
|
|
|
|
this.passRequirements = res.data;
|
|
|
|
this.askOldPass = askOldPass;
|
|
|
|
this.$.changePass.show();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onPassChange() {
|
|
|
|
if (!this.newPassword)
|
|
|
|
throw new UserError(`You must enter a new password`);
|
|
|
|
if (this.newPassword != this.repeatPassword)
|
|
|
|
throw new UserError(`Passwords don't match`);
|
|
|
|
|
|
|
|
let method;
|
|
|
|
const params = {newPassword: this.newPassword};
|
|
|
|
|
|
|
|
if (this.askOldPass) {
|
2024-02-15 08:39:02 +00:00
|
|
|
method = 'change-password';
|
2020-03-09 08:00:03 +00:00
|
|
|
params.oldPassword = this.oldPassword;
|
|
|
|
} else
|
|
|
|
method = 'setPassword';
|
|
|
|
|
2023-01-31 13:57:24 +00:00
|
|
|
return this.$http.patch(`Accounts/${this.id}/${method}`, params)
|
2020-03-09 08:00:03 +00:00
|
|
|
.then(() => {
|
|
|
|
this.emit('change');
|
|
|
|
this.vnApp.showSuccess(this.$t('Password changed succesfully!'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onPassClose() {
|
|
|
|
this.oldPassword = '';
|
|
|
|
this.newPassword = '';
|
|
|
|
this.repeatPassword = '';
|
|
|
|
this.$.$apply();
|
|
|
|
}
|
|
|
|
|
|
|
|
onEnableAccount() {
|
2023-01-31 13:57:24 +00:00
|
|
|
return this.$http.post(`Accounts`, {id: this.id})
|
2020-03-09 08:00:03 +00:00
|
|
|
.then(() => this.onSwitchAccount(true));
|
|
|
|
}
|
|
|
|
|
|
|
|
onDisableAccount() {
|
2023-01-31 13:57:24 +00:00
|
|
|
return this.$http.delete(`Accounts/${this.id}`)
|
2020-03-09 08:00:03 +00:00
|
|
|
.then(() => this.onSwitchAccount(false));
|
|
|
|
}
|
|
|
|
|
|
|
|
onSwitchAccount(enable) {
|
|
|
|
this.hasAccount = enable;
|
|
|
|
const message = enable
|
|
|
|
? 'Account enabled!'
|
|
|
|
: 'Account disabled!';
|
|
|
|
this.emit('change');
|
|
|
|
this.vnApp.showSuccess(this.$t(message));
|
|
|
|
}
|
|
|
|
|
|
|
|
onSetActive(active) {
|
2023-01-23 14:24:00 +00:00
|
|
|
return this.$http.patch(`VnUsers/${this.id}`, {active})
|
2020-03-09 08:00:03 +00:00
|
|
|
.then(() => {
|
|
|
|
this.user.active = active;
|
|
|
|
const message = active
|
|
|
|
? 'User activated!'
|
|
|
|
: 'User deactivated!';
|
|
|
|
this.emit('change');
|
|
|
|
this.vnApp.showSuccess(this.$t(message));
|
|
|
|
});
|
|
|
|
}
|
2023-11-16 22:07:26 +00:00
|
|
|
|
|
|
|
onSync() {
|
2023-11-16 23:08:29 +00:00
|
|
|
const params = {force: true};
|
|
|
|
if (this.shouldSyncPassword)
|
|
|
|
params.password = this.syncPassword;
|
|
|
|
|
2023-11-16 22:07:26 +00:00
|
|
|
return this.$http.patch(`Accounts/${this.user.name}/sync`, params)
|
|
|
|
.then(() => this.vnApp.showSuccess(this.$t('User synchronized!')));
|
|
|
|
}
|
|
|
|
|
|
|
|
onSyncClose() {
|
|
|
|
this.shouldSyncPassword = false;
|
|
|
|
this.syncPassword = undefined;
|
|
|
|
}
|
2020-03-09 08:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngModule.component('vnUserDescriptor', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
user: '<'
|
|
|
|
}
|
|
|
|
});
|