forked from verdnatura/hedera-web
82 lines
2.0 KiB
JavaScript
82 lines
2.0 KiB
JavaScript
import './style.scss';
|
|
|
|
export default new Class({
|
|
Extends: Hedera.Form,
|
|
Template: require('./ui.xml'),
|
|
|
|
activate() {
|
|
this.$.userModel.setInfo('c', 'myClient', 'hedera');
|
|
this.$.userModel.setInfo('u', 'myUser', 'account');
|
|
|
|
if (this.hash.$.verificationToken)
|
|
this.onPassChangeClick();
|
|
}
|
|
|
|
,onPassChangeClick() {
|
|
this.$.oldPassword.value = '';
|
|
this.$.newPassword.value = '';
|
|
this.$.repeatPassword.value = '';
|
|
|
|
var verificationToken = this.hash.$.verificationToken;
|
|
this.$.oldPassword.style.display = verificationToken ? 'none' : 'block';
|
|
this.$.changePassword.show();
|
|
|
|
if (verificationToken)
|
|
this.$.newPassword.focus();
|
|
else
|
|
this.$.oldPassword.focus();
|
|
}
|
|
|
|
,async onPassModifyClick() {
|
|
var oldPassword = this.$.oldPassword.value;
|
|
var newPassword = this.$.newPassword.value;
|
|
var repeatedPassword = this.$.repeatPassword.value;
|
|
|
|
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};
|
|
|
|
if (verificationToken) {
|
|
params.verificationToken = verificationToken;
|
|
this.conn.send('user/restore-password', params,
|
|
this._onPassChange.bind(this));
|
|
} else {
|
|
try {
|
|
let userId = this.gui.user.id;
|
|
params.oldPassword = oldPassword;
|
|
await this.conn.lbSend('PATCH',
|
|
`Accounts/${userId}/changePassword`, params,
|
|
);
|
|
this._onPassChange();
|
|
} catch(err) {
|
|
this._onPassChange(null, err);
|
|
}
|
|
}
|
|
}
|
|
|
|
,_onPassChange(json, error) {
|
|
if (!error) {
|
|
this.$.changePassword.hide();
|
|
this.hash.unset('verificationToken');
|
|
Htk.Toast.showMessage(_('Password changed!'));
|
|
this.$.userForm.refresh();
|
|
} else {
|
|
Htk.Toast.showError(error.message);
|
|
|
|
if (this.hash.$.verificationToken)
|
|
this.$.newPassword.select();
|
|
else
|
|
this.$.oldPassword.select();
|
|
}
|
|
}
|
|
|
|
,onPassInfoClick() {
|
|
this.$.passwordInfo.show();
|
|
}
|
|
});
|
|
|