Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

158 wiersze
5.9 KiB

  1. import useJwt from 'auth/jwt/coreUseJwt';
  2. /**
  3. * Return if user is logged in
  4. * This is completely up to you and how you want to store the token in your frontend application
  5. * e.g. If you are using cookies to store the application please update this function
  6. */
  7. // eslint-disable-next-line arrow-body-style
  8. export const hostname = 'localhost';
  9. const hostPort = '8090';
  10. export const hostPath = `http://${hostname}:${hostPort}`;
  11. export const apiPath = window.location.href.match("localhost:3000") ? `${hostPath}/api` : (window.location.href.match(":3000") ? "http://" + window.location.hostname + ":8090/api" : `/api`);
  12. export const paymentPath = window.location.href.match("localhost:3000") ? `${hostPath}/payment` : `/payment`;
  13. export const delBugMode = true;
  14. export const iAmSmartCallbackPath = () => {
  15. let hostname = window.location.hostname;
  16. if (hostname.match("pnspsuat")) {
  17. hostname = "pnspsuat.gld.gov.hk";
  18. }
  19. return hostname;
  20. };
  21. export const getNonce = () => {
  22. let hostname = window.location.hostname;
  23. if (hostname.match("localhost")) {
  24. hostname = "pnspsuat.gld.gov.hk";
  25. }
  26. return hostname;
  27. };
  28. export const getBowserType = () => {
  29. // console.log(navigator.userAgent)
  30. // const regex = /Mobi|Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Mi|huawei|Opera Mini|SAMSUNG|Samsung|SGH-[I|N|T]|GT-[I|N]|SM-[A|N|P|T|Z]|SHV-E|SCH-[I|J|R|S]|SPH-L/i;
  31. // if(!regex.test(navigator.userAgent))
  32. if (navigator.userAgent.indexOf("Edg") != -1) {
  33. if (navigator.userAgent.match(/Android/i)) return "Android_Edge"
  34. if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) return "iOS_Edge"
  35. return "PC_Browser"
  36. } else if (navigator.userAgent.indexOf("Chrome") != -1) {
  37. if (navigator.userAgent.match(/Android/i)) return "Android_Chrome"
  38. if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) return "iOS_Chrome"
  39. return "PC_Browser"
  40. } else if (navigator.userAgent.indexOf('CriOS') != -1) {
  41. if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) return "iOS_Chrome"
  42. return "PC_Browser"
  43. } else if (navigator.userAgent.indexOf("Safari") != -1 && navigator.userAgent.indexOf("Chrome") == -1) {
  44. if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) return "iOS_Safari"
  45. return "PC_Browser"
  46. } else if (navigator.userAgent.indexOf("Firefox") != -1) {
  47. if (navigator.userAgent.match(/Android/i)) return "Android_Firefox"
  48. if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) return "iOS_Firefox"
  49. return "PC_Browser"
  50. } else if (navigator.userAgent.match(/SAMSUNG|Samsung|SGH-[I|N|T]|GT-[I|N]|SM-[A|N|P|T|Z]|SHV-E|SCH-[I|J|R|S]|SPH-L/i)) {
  51. return "Android_Samsung"
  52. } else if (navigator.userAgent.match(/huawei/i)) {
  53. return "Android_Huawei"
  54. } else if (navigator.userAgent.match(/Mi/i)) {
  55. return "Android_Xiaomi"
  56. }
  57. return "PC_Browser";
  58. }
  59. export const isAppBowser = () => {
  60. return "PC_Browser" != getBowserType();
  61. }
  62. export const isUserLoggedIn = () => {
  63. return localStorage.getItem('userData') && localStorage.getItem(useJwt.jwtConfig.storageTokenKeyName);
  64. };
  65. export const getUserData = () => JSON.parse(localStorage.getItem('userData'));
  66. export const isGranted = (auth) => {
  67. const abilities = getUserData() ? getUserData()["abilities"] : null;
  68. if (abilities == null || abilities.length == 0) return false;
  69. if (!Array.isArray(auth)) return _checkAuth(abilities, auth);
  70. if (auth.length > abilities.length) return false;
  71. let haveAuth = true;
  72. for (let i = 0; i < auth.length; i++) {
  73. haveAuth = _checkAuth(abilities, auth[i])
  74. if (!haveAuth) return haveAuth;
  75. }
  76. return haveAuth;
  77. };
  78. const _checkAuth = (abilities, auth) => {
  79. for (let i = 0; i < abilities.length; i++) {
  80. if (auth == abilities[i].actionSubjectCombo) return true;
  81. }
  82. return false;
  83. }
  84. export const isGrantedAny = (auth) => {
  85. const abilities = getUserData() ? getUserData()["abilities"] : null;
  86. if (abilities == null || abilities.length == 0) return false;
  87. if (!Array.isArray(auth)) return _checkAuth(abilities, auth);
  88. let haveAuth = false;
  89. for (let i = 0; i < auth.length; i++) {
  90. haveAuth = _checkAuth(abilities, auth[i])
  91. if (haveAuth) return haveAuth;
  92. }
  93. return haveAuth;
  94. };
  95. /**
  96. * This function is used for demo purpose route navigation
  97. * In real app you won't need this function because your app will navigate to same route for each users regardless of ability
  98. * Please note role field is just for showing purpose it's not used by anything in frontend
  99. * We are checking role just for ease
  100. * NOTE: If you have different pages to navigate based on user ability then this function can be useful. However, you need to update it.
  101. * @param {String} userRole Role of user
  102. */
  103. export const getHomeRouteForLoggedInUser = (userRole) => {
  104. if (userRole === 'admin') return '/';
  105. if (userRole === 'user') return '/';
  106. if (userRole === 'client') return { name: 'access-control' };
  107. return { name: 'auth-login' };
  108. };
  109. // open payment record
  110. export const local = { en: "en-us", zh: "zh-hk", cn: "zh-cn" };
  111. export const preferpaymentmethods = ['visa', 'mastercard', 'pps', 'creditcard', 'fps'];
  112. export const getPaymentMethod = (paymentMethod) => {
  113. if (paymentMethod == "online") return 'payOnlineMethod';
  114. if (paymentMethod == "demandNote") return 'payDnMethod';
  115. if (paymentMethod == "office") return 'payNPGOMethod';
  116. return "other";
  117. }
  118. export const getSearchCriteria = (path) =>{
  119. let searchCriteria = ""
  120. if (localStorage.getItem('searchCriteria')==""){
  121. return searchCriteria
  122. } else if (Object.keys(localStorage.getItem('searchCriteria')).length>0){
  123. searchCriteria = JSON.parse(localStorage.getItem("searchCriteria"))
  124. if (searchCriteria.path === path){
  125. return searchCriteria.data
  126. } else {
  127. return ""
  128. }
  129. }
  130. }
  131. export const checkSearchCriteriaPath = (path) =>{
  132. if(!path.startsWith("/application")
  133. || path === "/application/search"){
  134. if(!path.startsWith("/user/")){
  135. if(!path.startsWith("/publicNotice/")|| path === "/publicNotice"){
  136. return true
  137. }
  138. }
  139. }
  140. }