2022-11-16 01:44:39 +00:00
|
|
|
import './style.scss';
|
2015-01-23 13:09:30 +00:00
|
|
|
|
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();
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
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 = '';
|
2015-01-23 13:09:30 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,onPassModifyClick() {
|
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);
|
2015-01-23 13:09:30 +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
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,onPassInfoClick() {
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.passwordInfo.show();
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|