hedera-web/forms/account/conf/conf.js

80 lines
2.0 KiB
JavaScript
Raw Normal View History

2021-03-31 10:18:25 +00:00
Hedera.Conf = new Class({
2016-09-26 09:28:47 +00:00
Extends: Hedera.Form
2021-03-31 10:18:25 +00:00
,activate: function() {
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
2021-03-31 10:18:25 +00:00
,onPassChangeClick: function() {
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
}
2021-03-31 10:18:25 +00:00
,onPassModifyClick: function() {
2016-10-11 14:45:10 +00:00
try {
2022-05-28 01:18:06 +00:00
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 == '')
2021-03-31 10:18:25 +00:00
throw new Error(_('Passwords empty'));
2016-10-11 14:45:10 +00:00
if (newPassword !== repeatedPassword)
2021-03-31 10:18:25 +00:00
throw new Error(_('Passwords doesn\'t match'));
2016-10-11 14:45:10 +00:00
2022-05-28 15:49:46 +00:00
var verificationToken = this.hash.$.verificationToken;
2021-03-31 10:18:25 +00:00
var params = {newPassword: newPassword};
if (verificationToken) {
params.verificationToken = verificationToken;
2022-10-04 13:12:16 +00:00
this.conn.send('user/restore-password', params,
2021-03-31 10:18:25 +00:00
this._onPassChange.bind(this));
} else {
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;
2022-05-05 13:56:17 +00:00
this.conn.lbSend('PATCH',
`Accounts/${userId}/changePassword`, params,
this._onPassChange.bind(this)
);
2021-03-31 10:18:25 +00:00
}
} catch (e) {
Htk.Toast.showError(e.message);
}
}
2022-05-05 13:56:17 +00:00
2021-03-31 10:18:25 +00:00
,_onPassChange: function(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
}
2021-03-31 10:18:25 +00:00
,onPassInfoClick: function() {
2022-05-28 01:18:06 +00:00
this.$.passwordInfo.show();
}
});