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

82 lines
2.0 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() {
var oldPassword = this.$.oldPassword.value;
var newPassword = this.$.newPassword.value;
var repeatedPassword = this.$.repeatPassword.value;
2016-10-11 14:45:10 +00:00
if (newPassword == '' && repeatedPassword == '')
throw new Error(_('Passwords empty'));
if (newPassword !== repeatedPassword)
throw new Error(_('Passwords doesn\'t match'));
var verificationToken = this.hash.$.verificationToken;
var params = {newPassword: newPassword};
2021-03-31 10:18:25 +00:00
if (verificationToken) {
params.verificationToken = verificationToken;
this.conn.send('user/restore-password', params,
this._onPassChange.bind(this));
} else {
try {
2022-05-05 13:56:17 +00:00
let userId = this.gui.user.id;
2021-03-31 10:18:25 +00:00
params.oldPassword = oldPassword;
await this.conn.lbSend('PATCH',
2022-05-05 13:56:17 +00:00
`Accounts/${userId}/changePassword`, params,
);
this._onPassChange();
} catch(err) {
this._onPassChange(null, err);
2021-03-31 10:18:25 +00:00
}
}
}
2022-05-05 13:56:17 +00:00
2022-11-16 01:46:44 +00:00
,_onPassChange(json, error) {
2022-05-05 13:56:17 +00:00
if (!error) {
2022-05-28 01:18:06 +00:00
this.$.changePassword.hide();
2021-03-31 10:18:25 +00:00
this.hash.unset('verificationToken');
Htk.Toast.showMessage(_('Password changed!'));
2022-05-28 01:18:06 +00:00
this.$.userForm.refresh();
2021-03-31 10:18:25 +00:00
} else {
Htk.Toast.showError(error.message);
2022-05-28 15:49:46 +00:00
if (this.hash.$.verificationToken)
2022-05-28 01:18:06 +00:00
this.$.newPassword.select();
2021-03-31 10:18:25 +00:00
else
2022-05-28 01:18:06 +00:00
this.$.oldPassword.select();
2016-10-11 14:45:10 +00:00
}
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();
}
});