0
1
Fork 0
hedera-web-mindshore/forms/account/conf/index.js

86 lines
2.1 KiB
JavaScript
Raw Normal View History

2022-11-16 01:44:39 +00:00
import './style.scss';
2022-11-16 01:44:39 +00:00
export default new Class({
Extends: Hedera.Form,
Template: require('./ui.xml'),
2022-11-16 01:46:44 +00:00
activate() {
2022-05-28 01:18:06 +00:00
this.$.userModel.setInfo('c', 'myClient', 'hedera');
this.$.userModel.setInfo('u', 'myUser', 'account');
2021-03-31 10:18:25 +00:00
2022-05-28 15:49:46 +00:00
if (this.hash.$.verificationToken)
2021-03-31 10:18:25 +00:00
this.onPassChangeClick();
}
2022-05-30 01:30:33 +00:00
2022-11-16 01:46:44 +00:00
,onPassChangeClick() {
2022-05-28 01:18:06 +00:00
this.$.oldPassword.value = '';
this.$.newPassword.value = '';
this.$.repeatPassword.value = '';
2022-05-28 15:49:46 +00:00
var verificationToken = this.hash.$.verificationToken;
2022-05-28 01:18:06 +00:00
this.$.oldPassword.style.display = verificationToken ? 'none' : 'block';
this.$.changePassword.show();
2016-10-11 14:45:10 +00:00
2021-03-31 10:18:25 +00:00
if (verificationToken)
2022-05-28 01:18:06 +00:00
this.$.newPassword.focus();
2016-10-14 10:58:35 +00:00
else
2022-05-28 01:18:06 +00:00
this.$.oldPassword.focus();
2016-10-11 14:45:10 +00:00
}
,async onPassModifyClick() {
const form = this.$.changePassword.node;
Vn.Node.disableInputs(form);
2023-01-16 12:59:11 +00:00
try {
const oldPassword = this.$.oldPassword.value;
const newPassword = this.$.newPassword.value;
const repeatedPassword = this.$.repeatPassword.value;
try {
if (newPassword == '' && repeatedPassword == '')
throw new Error(_('Passwords empty'));
if (newPassword !== repeatedPassword)
throw new Error(_('Passwords doesn\'t match'));
} catch (err) {
return Htk.Toast.showError(err.message);
2021-03-31 10:18:25 +00:00
}
const verificationToken = this.hash.$.verificationToken;
const params = {newPassword};
2021-03-31 10:18:25 +00:00
try {
if (verificationToken) {
params.verificationToken = verificationToken;
await this.conn.send('user/restore-password', params);
} else {
let userId = this.gui.user.id;
params.oldPassword = oldPassword;
await this.conn.patch(
`Accounts/${userId}/changePassword`, params);
}
} catch(err) {
Htk.Toast.showError(err.message);
2022-11-28 08:51:31 +00:00
if (verificationToken)
this.$.newPassword.select();
else
this.$.oldPassword.select();
return;
}
2022-11-28 08:51:31 +00:00
this.hash.unset('verificationToken');
await this.conn.open(this.gui.user.name, newPassword);
this.$.changePassword.hide();
} finally {
Vn.Node.disableInputs(form, false);
}
2022-11-28 08:51:31 +00:00
Htk.Toast.showMessage(_('Password changed!'));
2015-03-06 23:33:54 +00:00
}
2022-11-16 01:46:44 +00:00
,onPassInfoClick() {
2022-05-28 01:18:06 +00:00
this.$.passwordInfo.show();
}
});