@@ -72,4 +75,29 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/modules/worker/front/descriptor/index.js b/modules/worker/front/descriptor/index.js
index 07e16c0d6..13ffa6f2f 100644
--- a/modules/worker/front/descriptor/index.js
+++ b/modules/worker/front/descriptor/index.js
@@ -1,5 +1,6 @@
import ngModule from '../module';
import Descriptor from 'salix/components/descriptor';
+const UserError = require('vn-loopback/util/user-error');
class Controller extends Descriptor {
constructor($element, $, $rootScope) {
super($element, $);
@@ -12,9 +13,11 @@ class Controller extends Descriptor {
set worker(value) {
this.entity = value;
-
if (value)
this.getIsExcluded();
+
+ if (this.entity && !this.entity.user.emailVerified)
+ this.getPassRequirements();
}
getIsExcluded() {
@@ -38,7 +41,7 @@ class Controller extends Descriptor {
{
relation: 'user',
scope: {
- fields: ['name'],
+ fields: ['name', 'emailVerified'],
include: {
relation: 'emailUser',
scope: {
@@ -66,10 +69,29 @@ class Controller extends Descriptor {
}
]
};
-
return this.getData(`Workers/${this.id}`, {filter})
.then(res => this.entity = res.data);
}
+
+ getPassRequirements() {
+ this.$http.get('UserPasswords/findOne')
+ .then(res => {
+ this.passRequirements = res.data;
+ });
+ }
+
+ setPassword() {
+ if (!this.newPassword)
+ throw new UserError(`You must enter a new password`);
+ if (this.newPassword != this.repeatPassword)
+ throw new UserError(`Passwords don't match`);
+ this.$http.patch(
+ `Workers/${this.entity.id}/setPassword`,
+ {workerFk: this.entity.id, newPass: this.newPassword}
+ ) .then(() => {
+ this.vnApp.showSuccess(this.$translate.instant('Password changed!'));
+ });
+ }
}
Controller.$inject = ['$element', '$scope', '$rootScope'];
diff --git a/modules/worker/front/descriptor/index.spec.js b/modules/worker/front/descriptor/index.spec.js
index dfb800415..d158a9e8e 100644
--- a/modules/worker/front/descriptor/index.spec.js
+++ b/modules/worker/front/descriptor/index.spec.js
@@ -23,4 +23,24 @@ describe('vnWorkerDescriptor', () => {
expect(controller.worker).toEqual(response);
});
});
+
+ describe('setPassword()', () => {
+ it('should throw an error: You must enter a new password', () => {
+ try {
+ controller.setPassword();
+ } catch (error) {
+ expect(error.message).toEqual('You must enter a new password');
+ }
+ });
+
+ it('should throw an error: Passwords don\'t match', () => {
+ controller.newPassword = 'aaa';
+ controller.repeatPassword = 'bbb';
+ try {
+ controller.setPassword();
+ } catch (error) {
+ expect(error.message).toEqual('Passwords don\'t match');
+ }
+ });
+ });
});