account.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. let account = {
  2. display: function(){
  3. document.getElementById("accountStrandTitle").innerText = merchant.name;
  4. document.getElementById("accountEmail").value = merchant.email;
  5. document.getElementById("accountUpdate").onclick = ()=>{this.updateData()};
  6. let passButton = document.getElementById("accountShowPassword");
  7. let passBox = document.getElementById("changePasswordBox");
  8. passButton.onclick = ()=>{
  9. passButton.style.display = "none";
  10. passBox.style.display = "flex";
  11. };
  12. document.getElementById("cancelPasswordChange").onclick = ()=>{
  13. passButton.style.display = "block";
  14. passBox.style.display = "none";
  15. document.getElementById("accountCurrentPassword").value = "";
  16. document.getElementById("accountNewPassword").value = "";
  17. document.getElementById("accountConfirmPassword").value = "";
  18. };
  19. document.getElementById("changePasswordButton").onclick = ()=>{this.updatePassword()};
  20. },
  21. updateData: function(){
  22. let data = {
  23. email: document.getElementById("accountEmail").value
  24. }
  25. let loader = document.getElementById("loaderContainer");
  26. loader.style.display = "flex";
  27. fetch("/merchant/update", {
  28. method: "put",
  29. headers: {
  30. "Content-Type": "application/json;charset=utf-8"
  31. },
  32. body: JSON.stringify(data)
  33. })
  34. .then(response => response.json())
  35. .then((response)=>{
  36. if(typeof(response) === "string"){
  37. controller.createBanner(response, "error");
  38. }else{
  39. controller.createBanner("DATA UPDATED", "success");
  40. if(response.email !== merchant.email){
  41. controller.createBanner("YOU MUST VALIDATE YOUR NEW EMAIL ADDRESS BEFORE YOU CAN LOG IN AGAIN", "alert");
  42. }
  43. merchant.email = response.email;
  44. document.getElementById("accountEmail").value = merchant.email;
  45. }
  46. })
  47. .catch((err)=>{
  48. controller.createBanner("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE", "error");
  49. })
  50. .finally(()=>{
  51. loader.style.display = "none";
  52. });
  53. },
  54. updatePassword: function(){
  55. console.log("updating password");
  56. }
  57. }
  58. module.exports = account;