1. 1 :
  2. 2 : /**
  3. 3 : * Plugin roundcube_auth - Associated JS file
  4. 4 : */
  5. 5 : function docReady(fn)
  6. 6 : {
  7. 7 : // see if DOM is already available
  8. 8 : if (document.readyState === "complete"
  9. 9 : || document.readyState === "interactive")
  10. 10 : {
  11. 11 : // call on next available tick
  12. 12 : setTimeout(fn, 1);
  13. 13 : } else { document.addEventListener("DOMContentLoaded", fn); }
  14. 14 : }
  15. 15 :
  16. 16 : docReady(function()
  17. 17 : {
  18. 18 : // DOM is loaded and ready for manipulation here
  19. 19 :
  20. 20 : //=====
  21. 21 : //
  22. 22 : //=====
  23. 23 : if(window.rcmail)
  24. 24 : {
  25. 25 : // NOT USED CURRENTLY
  26. 26 : rcmail.addEventListener('plugin.auth_redirect', function(evt)
  27. 27 : {
  28. 28 : // console.log("PLUGIN_AUTH_REDIRECT");
  29. 29 : // console.log(evt);
  30. 30 : // console.log(window.location);
  31. 31 : // // window.location
  32. 32 : // const baseURL = "https://rcube.preprod.m2.e2.rie.gouv.fr/bureau/"
  33. 33 : // window.location.replace(`${baseURL}?${evt}`);
  34. 34 : });
  35. 35 : }
  36. 36 :
  37. 37 : //=====
  38. 38 : //
  39. 39 : //=====
  40. 40 : const forms = document.getElementsByTagName('form');
  41. 41 :
  42. 42 : if(forms.length > 0)
  43. 43 : {
  44. 44 : for (let form of forms)
  45. 45 : {
  46. 46 : // Select login form
  47. 47 : if(form.action.includes('?_task=login'))
  48. 48 : {
  49. 49 : form.addEventListener('submit', (e) =>
  50. 50 : {
  51. 51 : // Select OIDC button
  52. 52 : if(e.submitter.id == "rcmlogin_oidc")
  53. 53 : {
  54. 54 : // Avoid form submission
  55. 55 : e.preventDefault();
  56. 56 :
  57. 57 : // Redirect to OIDC route
  58. 58 : window.location.replace(`${window.location.origin}?oidc=1`);
  59. 59 : }
  60. 60 : });
  61. 61 : }
  62. 62 : }
  63. 63 : }
  64. 64 : });