change password permission

This commit is contained in:
Dani Herrero 2017-09-21 07:53:23 +02:00
parent 205f6b2c54
commit aa4bfb4f51
2 changed files with 16 additions and 3 deletions

View File

@ -15,7 +15,7 @@
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
<vn-button label="Change password" vn-dialog="change-pass"></vn-button>
<vn-button ng-if="$ctrl.canChangePassword" label="Change password" vn-dialog="change-pass"></vn-button>
</vn-button-bar>
</form>
<vn-dialog

View File

@ -5,10 +5,23 @@ export default class Controller {
this.$ = $scope;
this.$http = $http;
this.vnApp = vnApp;
this.canChangePassword = false;
}
$onChanges() {
if (this.client)
if (this.client) {
this.account = this.client.account;
this.isCustomer();
}
}
isCustomer() {
if (this.client && this.client.id) {
this.$http.get(`/client/api/Clients/${this.client.id}/getRoleCustomer`).then(res => {
this.canChangePassword = (res.data && res.data.length) ? res.data[0].isCustomer : false;
});
} else {
this.canChangePassword = false;
}
}
onPassOpen() {
this.newPassword = '';
@ -16,7 +29,7 @@ export default class Controller {
this.$.$apply();
}
onPassChange(response) {
if (response == 'ACCEPT')
if (response == 'ACCEPT' && this.canChangePassword)
try {
if (!this.newPassword)
throw new Error(`Passwords can't be empty`);