in source/webapp/src/lib/js/signInModal.js [307:387]
registerEvents() {
/* sign out button is clicked */
this.signoutBtn.click((event) => {
try {
event.preventDefault();
const {
user,
} = this.cognito;
console.log(`Bye ${user.username}`);
this.cognito.signOut();
this.signOut();
} catch (e) {
console.error(encodeURIComponent(e.message));
}
return this;
});
/* modal dialog is about to show, reset the ui */
this.signinModal.off('show.bs.modal').on('show.bs.modal', () => {
try {
this.alertMessage.html('').collapse('hide');
} catch (e) {
console.error(encodeURIComponent(e.message));
}
});
/* reset password field onHide */
this.signinModal.off('hide.bs.modal').on('hide.bs.modal', () => {
this.inputPassword.val('');
this.alertMessage.html('').collapse('hide');
});
/* sign in form submit event */
this.signinForm.off('submit').submit(async (event) => {
try {
event.preventDefault();
if (!this.cognito) {
throw new Error('invalid cognito setting');
}
const Username = this.inputUsername.val();
const Password = this.inputPassword.val();
const {
status,
} = await this.cognito.authenticate({ Username, Password });
if (status === 'newPasswordRequired') {
this.newPasswordModal.modal('show');
} else {
await this.signIn();
}
this.signinModal.modal('hide');
} catch (e) {
e.message = `${this.signinForm.attr('id')}.submit: ${encodeURIComponent(e.message)}`;
this.alertMessage.html(`<small>${e.message}</small>`).collapse('show');
console.error(e.message);
}
});
/* forgot password flow */
const resetPassword = this.signinForm.find('[data-action="reset-password"]').first();
resetPassword.click(async (event) => {
try {
event.preventDefault();
/* close the signin modal and bring up forgot password modal */
this.signinModal.modal('hide');
this.forgotPasswordModal.show();
} catch (e) {
console.error(encodeURIComponent(e.message));
}
return this;
});
}