Browse Source

added session_limit, adapted ajax calls (axios interceptor) in theme

bach 2 years ago
parent
commit
a352b9745b
36 changed files with 188 additions and 45 deletions
  1. 1 0
      composer.json
  2. 54 1
      composer.lock
  3. 1 0
      config/sync/core.extension.yml
  4. 19 0
      config/sync/session_limit.settings.yml
  5. 0 0
      web/themes/custom/materiotheme/assets/dist/main.js
  6. BIN
      web/themes/custom/materiotheme/assets/dist/main.js.gz
  7. 0 0
      web/themes/custom/materiotheme/assets/dist/module-article.bundle.js
  8. BIN
      web/themes/custom/materiotheme/assets/dist/module-article.bundle.js.gz
  9. 0 0
      web/themes/custom/materiotheme/assets/dist/module-thematique.bundle.js
  10. BIN
      web/themes/custom/materiotheme/assets/dist/module-thematique.bundle.js.gz
  11. 1 1
      web/themes/custom/materiotheme/assets/dist/report.html
  12. 1 1
      web/themes/custom/materiotheme/assets/scripts/main.js
  13. 17 1
      web/themes/custom/materiotheme/vuejs/api/graphql-axios.js
  14. 17 1
      web/themes/custom/materiotheme/vuejs/api/json-axios.js
  15. 19 1
      web/themes/custom/materiotheme/vuejs/api/ma-axios.js
  16. 17 1
      web/themes/custom/materiotheme/vuejs/api/rest-axios.js
  17. 1 1
      web/themes/custom/materiotheme/vuejs/components/Block/SearchBlock.vue
  18. 1 1
      web/themes/custom/materiotheme/vuejs/components/Block/UserBlock.vue
  19. 1 1
      web/themes/custom/materiotheme/vuejs/components/Content/ArticleCard.vue
  20. 1 1
      web/themes/custom/materiotheme/vuejs/components/Content/HeaderMenu.vue
  21. 1 1
      web/themes/custom/materiotheme/vuejs/components/Content/LeftContent.vue
  22. 1 1
      web/themes/custom/materiotheme/vuejs/components/Content/MainContent.vue
  23. 2 2
      web/themes/custom/materiotheme/vuejs/components/Content/ModalCard.vue
  24. 1 1
      web/themes/custom/materiotheme/vuejs/components/Content/Showroom.vue
  25. 1 1
      web/themes/custom/materiotheme/vuejs/components/Form/LoginForm.vue
  26. 1 1
      web/themes/custom/materiotheme/vuejs/components/Form/RegisterForm.vue
  27. 3 3
      web/themes/custom/materiotheme/vuejs/components/Pages/Article.vue
  28. 3 3
      web/themes/custom/materiotheme/vuejs/components/Pages/Thematique.vue
  29. 1 1
      web/themes/custom/materiotheme/vuejs/components/productsMixins.js
  30. 2 2
      web/themes/custom/materiotheme/vuejs/store/index.js
  31. 3 3
      web/themes/custom/materiotheme/vuejs/store/modules/blabla.js
  32. 2 2
      web/themes/custom/materiotheme/vuejs/store/modules/common.js
  33. 2 2
      web/themes/custom/materiotheme/vuejs/store/modules/pages.js
  34. 4 4
      web/themes/custom/materiotheme/vuejs/store/modules/search.js
  35. 3 3
      web/themes/custom/materiotheme/vuejs/store/modules/showrooms.js
  36. 7 4
      web/themes/custom/materiotheme/vuejs/store/modules/user.js

+ 1 - 0
composer.json

@@ -137,6 +137,7 @@
         "drupal/search_api_page": "^1.x-dev",
         "drupal/search_api_solr": "^4.1",
         "drupal/select_translation": "^1.x-dev",
+        "drupal/session_limit": "^2.0@beta",
         "drupal/simplenews": "^2.0@beta",
         "drupal/social_media_links": "^2.8",
         "drupal/string_translation_ui": "^1.2",

+ 54 - 1
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "957ca05105e223d75024ee67bb653c06",
+    "content-hash": "d266fe2b9e10650e36671e119f2fb2fb",
     "packages": [
         {
             "name": "alchemy/zippy",
@@ -12237,6 +12237,58 @@
                 "source": "https://git.drupalcode.org/project/select_translation"
             }
         },
+        {
+            "name": "drupal/session_limit",
+            "version": "2.0.0-beta2",
+            "source": {
+                "type": "git",
+                "url": "https://git.drupalcode.org/project/session_limit.git",
+                "reference": "2.0.0-beta2"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://ftp.drupal.org/files/projects/session_limit-2.0.0-beta2.zip",
+                "reference": "2.0.0-beta2",
+                "shasum": "05f6bb02c2d108212b7c2072e5596df919afd09d"
+            },
+            "require": {
+                "drupal/core": "^8 || ^9"
+            },
+            "type": "drupal-module",
+            "extra": {
+                "drupal": {
+                    "version": "2.0.0-beta2",
+                    "datestamp": "1625122061",
+                    "security-coverage": {
+                        "status": "not-covered",
+                        "message": "Beta releases are not covered by Drupal security advisories."
+                    }
+                }
+            },
+            "notification-url": "https://packages.drupal.org/8/downloads",
+            "license": [
+                "GPL-2.0-or-later"
+            ],
+            "authors": [
+                {
+                    "name": "deekayen",
+                    "homepage": "https://www.drupal.org/user/972"
+                },
+                {
+                    "name": "johnennew",
+                    "homepage": "https://www.drupal.org/user/1150042"
+                },
+                {
+                    "name": "suzymasri",
+                    "homepage": "https://www.drupal.org/user/2428842"
+                }
+            ],
+            "description": "Limit simultaneous user sessions.",
+            "homepage": "https://www.drupal.org/project/session_limit",
+            "support": {
+                "source": "https://git.drupalcode.org/project/session_limit"
+            }
+        },
         {
             "name": "drupal/simplenews",
             "version": "2.0.0-beta2",
@@ -21819,6 +21871,7 @@
         "drupal/payment_commerce": 20,
         "drupal/search_api_page": 20,
         "drupal/select_translation": 20,
+        "drupal/session_limit": 10,
         "drupal/simplenews": 10,
         "drupal/strings_i18n_json_export": 20,
         "drupal/swiftmailer": 20,

+ 1 - 0
config/sync/core.extension.yml

@@ -181,6 +181,7 @@ module:
   search_api_solr_admin: 0
   select_translation: 0
   serialization: 0
+  session_limit: 0
   simplenews: 0
   smart_trim: 0
   smtp: 0

+ 19 - 0
config/sync/session_limit.settings.yml

@@ -0,0 +1,19 @@
+session_limit_max: 1
+session_limit_masquerade_ignore: false
+session_limit_behaviour: 1
+session_limit_logged_out_message_severity: warning
+session_limit_roles:
+  unverified: 0
+  authenticated: 0
+  free_user: 0
+  contact_company: 0
+  alpha_testeur: 0
+  student: 0
+  adherent: 0
+  translator: 0
+  admin_showroom: 0
+  admin: -1
+  root: -1
+session_limit_admin_inclusion: 0
+_core:
+  default_config_hash: E99p-j2YC4tVqQ7Gz4-I4cALOq2a8XHkvlQnxoV5EWY

File diff suppressed because it is too large
+ 0 - 0
web/themes/custom/materiotheme/assets/dist/main.js


BIN
web/themes/custom/materiotheme/assets/dist/main.js.gz


File diff suppressed because it is too large
+ 0 - 0
web/themes/custom/materiotheme/assets/dist/module-article.bundle.js


BIN
web/themes/custom/materiotheme/assets/dist/module-article.bundle.js.gz


File diff suppressed because it is too large
+ 0 - 0
web/themes/custom/materiotheme/assets/dist/module-thematique.bundle.js


BIN
web/themes/custom/materiotheme/assets/dist/module-thematique.bundle.js.gz


File diff suppressed because it is too large
+ 1 - 1
web/themes/custom/materiotheme/assets/dist/report.html


+ 1 - 1
web/themes/custom/materiotheme/assets/scripts/main.js

@@ -58,7 +58,7 @@ import 'slim-select/slimselect.min.css'
 import 'theme/assets/styles/main.scss'
 import 'theme/assets/styles/print.scss'
 
-import { MA } from 'vuejs/api/ma-axios'
+import MA from 'vuejs/api/ma-axios'
 
 export let _v_sitebranding_block, _v_user_block, _v_header_menu,
   _v_pagetitle_block, _v_search_block,

+ 17 - 1
web/themes/custom/materiotheme/vuejs/api/graphql-axios.js

@@ -5,7 +5,7 @@ import axios from 'axios'
 // console.log('drupalSettings', drupalSettings)
 console.log(window.location)
 
-export const MGQ = axios.create({
+const MGQ = axios.create({
   baseURL: window.location.origin + '/mgq',
   withCredentials: true,
   headers: {
@@ -15,3 +15,19 @@ export const MGQ = axios.create({
     'Content-Type': 'application/json'
   }
 })
+
+MGQ.interceptors.response.use(
+  response => {
+    return Promise.resolve(response)
+  },
+  error => {
+    const { status } = error.response
+    console.warn('error in graphql-axios', status)
+    if (status === 403) {
+      window.location = '/'
+    }
+    return Promise.reject(error)
+  }
+)
+
+export default MGQ

+ 17 - 1
web/themes/custom/materiotheme/vuejs/api/json-axios.js

@@ -5,7 +5,7 @@ import axios from 'axios'
 // console.log('drupalSettings', drupalSettings)
 console.log(window.location)
 
-export const JSONAPI = axios.create({
+const JSONAPI = axios.create({
   baseURL: window.location.origin+`/jsonapi`,
   withCredentials: true,
   headers: {
@@ -14,3 +14,19 @@ export const JSONAPI = axios.create({
     // 'Content-Type': 'application/json'
   }
 })
+
+JSONAPI.interceptors.response.use(
+  response => {
+    return Promise.resolve(response)
+  },
+  error => {
+    const { status } = error.response
+    console.warn('error in json-axios', status)
+    if (status === 403) {
+      window.location = '/'
+    }
+    return Promise.reject(error)
+  }
+)
+
+export default JSONAPI

+ 19 - 1
web/themes/custom/materiotheme/vuejs/api/ma-axios.js

@@ -4,7 +4,7 @@ import axios from 'axios'
 
 // console.log('drupalSettings', drupalSettings)
 
-export const MA = axios.create({
+const MA = axios.create({
   baseURL: window.location.origin + '/' + drupalSettings.path.pathPrefix,
   withCredentials: true,
   headers: {
@@ -12,3 +12,21 @@ export const MA = axios.create({
     // "X-CSRF-Token": "csrf_token"
   }
 })
+
+MA.interceptors.response.use(
+  response => {
+    // console.log('ma-axios interceptor response', response)
+    return Promise.resolve(response)
+    // return response
+  },
+  error => {
+    const { status } = error.response
+    console.warn('error in ma-axios interceptor', status)
+    if (status === 403) {
+      window.location = '/'
+    }
+    return Promise.reject(error)
+  }
+)
+
+export default MA

+ 17 - 1
web/themes/custom/materiotheme/vuejs/api/rest-axios.js

@@ -5,7 +5,7 @@ import axios from 'axios'
 // console.log('drupalSettings', drupalSettings)
 // console.log('window.location.origin', window.location.origin)
 
-export const REST = axios.create({
+const REST = axios.create({
   baseURL: window.location.origin + '/' + drupalSettings.path.pathPrefix,
   withCredentials: true,
   headers: {
@@ -13,3 +13,19 @@ export const REST = axios.create({
     'Content-Type': 'application/json'
   }
 })
+
+REST.interceptors.response.use(
+  response => {
+    return Promise.resolve(response)
+  },
+  error => {
+    const { status } = error.response
+    console.warn('error in rest-axios', status)
+    if (status === 403) {
+      window.location = '/'
+    }
+    return Promise.reject(error)
+  }
+)
+
+export default REST

+ 1 - 1
web/themes/custom/materiotheme/vuejs/components/Block/SearchBlock.vue

@@ -9,7 +9,7 @@
 <script>
 import SearchForm from 'vuejs/components/Form/SearchForm'
 import { mapState, mapActions } from 'vuex'
-import { MA } from 'vuejs/api/ma-axios'
+import MA from 'vuejs/api/ma-axios'
 
 export default {
   props: ['blockid', 'formhtml'],

+ 1 - 1
web/themes/custom/materiotheme/vuejs/components/Block/UserBlock.vue

@@ -9,7 +9,7 @@ import { mapState, mapActions } from 'vuex'
 import LoginBlock from 'vuejs/components/Block/LoginBlock'
 import UserTools from 'vuejs/components/User/UserTools'
 
-import { MA } from 'vuejs/api/ma-axios'
+import MA from 'vuejs/api/ma-axios'
 
 export default {
   props: ['title', 'loginblock'],

+ 1 - 1
web/themes/custom/materiotheme/vuejs/components/Content/ArticleCard.vue

@@ -23,7 +23,7 @@
 </template>
 
 <script>
-// import { JSONAPI } from 'vuejs/api/json-axios'
+// import JSONAPI from 'vuejs/api/json-axios'
 import router from 'vuejs/route'
 
 let basePath = drupalSettings.path.baseUrl + drupalSettings.path.pathPrefix;

+ 1 - 1
web/themes/custom/materiotheme/vuejs/components/Content/HeaderMenu.vue

@@ -4,7 +4,7 @@ import Vue from 'vue'
 
 import { mapState, mapActions } from 'vuex'
 
-import { MA } from 'vuejs/api/ma-axios'
+import MA from 'vuejs/api/ma-axios'
 import router from 'vuejs/route'
 
 export default {

+ 1 - 1
web/themes/custom/materiotheme/vuejs/components/Content/LeftContent.vue

@@ -10,7 +10,7 @@
 <script>
 import { mapState, mapActions } from 'vuex'
 
-import { MA } from 'vuejs/api/ma-axios'
+import MA from 'vuejs/api/ma-axios'
 import router from 'vuejs/route'
 
 import FlagCollection from 'vuejs/components/User/FlagCollection'

+ 1 - 1
web/themes/custom/materiotheme/vuejs/components/Content/MainContent.vue

@@ -9,7 +9,7 @@
 <script>
 import { mapState, mapActions } from 'vuex'
 
-import { MA } from 'vuejs/api/ma-axios'
+import MA from 'vuejs/api/ma-axios'
 import router from 'vuejs/route'
 
 export default {

+ 2 - 2
web/themes/custom/materiotheme/vuejs/components/Content/ModalCard.vue

@@ -301,8 +301,8 @@ import LinkedMaterialCard from 'vuejs/components/Content/LinkedMaterialCard'
 
 import cardMixins from 'vuejs/components/cardMixins'
 
-import { REST } from 'vuejs/api/rest-axios'
-import { MGQ } from 'vuejs/api/graphql-axios'
+import REST from 'vuejs/api/rest-axios'
+import MGQ from 'vuejs/api/graphql-axios'
 import { print } from 'graphql/language/printer'
 import gql from 'graphql-tag'
 import materiauFields from 'vuejs/api/gql/materiaumodal.fragment.gql'

+ 1 - 1
web/themes/custom/materiotheme/vuejs/components/Content/Showroom.vue

@@ -16,7 +16,7 @@
 </template>
 
 <script>
-// import { JSONAPI } from 'vuejs/api/json-axios'
+// import JSONAPI from 'vuejs/api/json-axios'
 import router from 'vuejs/route'
 
 let basePath = drupalSettings.path.baseUrl + drupalSettings.path.pathPrefix;

+ 1 - 1
web/themes/custom/materiotheme/vuejs/components/Form/LoginForm.vue

@@ -2,7 +2,7 @@
 
 import Vue from 'vue'
 import { mapState, mapActions } from 'vuex'
-import { MA } from 'vuejs/api/ma-axios'
+import MA from 'vuejs/api/ma-axios'
 
 export default {
   name: "LoginForm",

+ 1 - 1
web/themes/custom/materiotheme/vuejs/components/Form/RegisterForm.vue

@@ -2,7 +2,7 @@
 
 import Vue from 'vue'
 import { mapState, mapActions } from 'vuex'
-import { MA } from 'vuejs/api/ma-axios'
+import MA from 'vuejs/api/ma-axios'
 
 import passwordStrength from 'check-password-strength'
 

+ 3 - 3
web/themes/custom/materiotheme/vuejs/components/Pages/Article.vue

@@ -118,9 +118,9 @@
 import router from 'vuejs/route'
 import store from 'vuejs/store'
 
-// import { JSONAPI } from 'vuejs/api/json-axios'
-import { REST } from 'vuejs/api/rest-axios'
-import { MGQ } from 'vuejs/api/graphql-axios'
+// import JSONAPI from 'vuejs/api/json-axios'
+import REST from 'vuejs/api/rest-axios'
+import MGQ from 'vuejs/api/graphql-axios'
 import { print } from 'graphql/language/printer'
 import gql from 'graphql-tag'
 // import materiauFields from 'vuejs/api/gql/materiau.fragment.gql'

+ 3 - 3
web/themes/custom/materiotheme/vuejs/components/Pages/Thematique.vue

@@ -29,9 +29,9 @@
 import router from 'vuejs/route'
 import store from 'vuejs/store'
 
-// import { JSONAPI } from 'vuejs/api/json-axios'
-import { REST } from 'vuejs/api/rest-axios'
-import { MGQ } from 'vuejs/api/graphql-axios'
+// import JSONAPI from 'vuejs/api/json-axios'
+import REST from 'vuejs/api/rest-axios'
+import MGQ from 'vuejs/api/graphql-axios'
 import { print } from 'graphql/language/printer'
 import gql from 'graphql-tag'
 // import materiauFields from 'vuejs/api/gql/materiau.fragment.gql'

+ 1 - 1
web/themes/custom/materiotheme/vuejs/components/productsMixins.js

@@ -1,6 +1,6 @@
 // https://forum.vuejs.org/t/how-to-use-helper-functions-for-imported-modules-in-vuejs-vue-template/6266/5
 
-import { REST } from 'vuejs/api/rest-axios'
+import REST from 'vuejs/api/rest-axios'
 import Modal from 'vuejs/components/Helper/Modal'
 import LoginRegister from 'vuejs/components/Helper/LoginRegister'
 import { mapState } from 'vuex'

+ 2 - 2
web/themes/custom/materiotheme/vuejs/store/index.js

@@ -3,10 +3,10 @@ import Vuex from 'vuex'
 
 import { createStore } from 'vuex-extensions'
 
-// import { JSONAPI } from 'vuejs/api/json-axios'
+// import JSONAPI from 'vuejs/api/json-axios'
 // import qs from 'querystring-es3'
 
-import { MGQ } from 'vuejs/api/graphql-axios'
+import MGQ from 'vuejs/api/graphql-axios'
 import { print } from 'graphql/language/printer'
 import gql from 'graphql-tag'
 // import materiauFields from 'vuejs/api/gql/materiau.fragment.gql'

+ 3 - 3
web/themes/custom/materiotheme/vuejs/store/modules/blabla.js

@@ -1,6 +1,6 @@
-// import { JSONAPI } from 'vuejs/api/json-axios'
-import { REST } from 'vuejs/api/rest-axios'
-// import { MA } from 'vuejs/api/ma-axios'
+// import JSONAPI from 'vuejs/api/json-axios'
+import REST from 'vuejs/api/rest-axios'
+// import MA from 'vuejs/api/ma-axios'
 // import qs from 'querystring-es3'
 
 export default {

+ 2 - 2
web/themes/custom/materiotheme/vuejs/store/modules/common.js

@@ -1,5 +1,5 @@
-// import { REST } from 'vuejs/api/rest-axios'
-// import { JSONAPI } from 'vuejs/api/json-axios'
+// import REST from 'vuejs/api/rest-axios'
+// import JSONAPI from 'vuejs/api/json-axios'
 // import qs from 'querystring-es3'
 
 export default {

+ 2 - 2
web/themes/custom/materiotheme/vuejs/store/modules/pages.js

@@ -1,6 +1,6 @@
-import { REST } from 'vuejs/api/rest-axios'
+import REST from 'vuejs/api/rest-axios'
 
-import { MGQ } from 'vuejs/api/graphql-axios'
+import MGQ from 'vuejs/api/graphql-axios'
 import { print } from 'graphql/language/printer'
 import gql from 'graphql-tag'
 import productsGQL from 'vuejs/api/gql/products.fragment.gql'

+ 4 - 4
web/themes/custom/materiotheme/vuejs/store/modules/search.js

@@ -1,11 +1,11 @@
-// import { REST } from 'vuejs/api/rest-axios'
-// import { JSONAPI } from 'vuejs/api/json-axios'
-import { MA } from 'vuejs/api/ma-axios'
+// import REST from 'vuejs/api/rest-axios'
+// import JSONAPI from 'vuejs/api/json-axios'
+import MA from 'vuejs/api/ma-axios'
 import qs from 'querystring-es3'
 
 import Vue from 'vue'
 
-import { MGQ } from 'vuejs/api/graphql-axios'
+import MGQ from 'vuejs/api/graphql-axios'
 import { print } from 'graphql/language/printer'
 import gql from 'graphql-tag'
 import searchresultGQL from 'vuejs/api/gql/searchresults.fragment.gql'

+ 3 - 3
web/themes/custom/materiotheme/vuejs/store/modules/showrooms.js

@@ -1,6 +1,6 @@
-// import { JSONAPI } from 'vuejs/api/json-axios'
-import { REST } from 'vuejs/api/rest-axios'
-// import { MA } from 'vuejs/api/ma-axios'
+// import JSONAPI from 'vuejs/api/json-axios'
+import REST from 'vuejs/api/rest-axios'
+// import MA from 'vuejs/api/ma-axios'
 // import qs from 'querystring-es3'
 
 export default {

+ 7 - 4
web/themes/custom/materiotheme/vuejs/store/modules/user.js

@@ -1,6 +1,6 @@
-import { REST } from 'vuejs/api/rest-axios'
-// import { JSONAPI } from 'vuejs/api/json-axios'
-import { MA } from 'vuejs/api/ma-axios'
+import REST from 'vuejs/api/rest-axios'
+// import JSONAPI from 'vuejs/api/json-axios'
+import MA from 'vuejs/api/ma-axios'
 import qs from 'querystring-es3'
 
 import materiauGQL from 'vuejs/api/gql/materiauflaglist.fragment.gql'
@@ -46,7 +46,7 @@ export default {
       // state.username = data.username;
       state.mail = data.current_user.mail
       state.csrf_token = data.csrf_token
-      state.isloggedin = true
+      // state.isloggedin = true
       state.logout_token = data.logout_token
     },
     setLoginMessage (state, message) {
@@ -64,6 +64,8 @@ export default {
     setUser (state, data) {
       state.mail = data.mail[0].value
       state.uuid = data.uuid[0].value
+      // with session_limit, only here we are certain that the user is logged
+      state.isloggedin = true
     },
     setRoles (state, roles) {
       console.log('User setRoles', roles)
@@ -235,6 +237,7 @@ export default {
             .then(({ data }) => {
               console.log('user REST getUser data', data)
               console.log('roles', data.roles)
+              // with session_limit, only here we are certain that the user is logged
               commit('setUser', data)
               if (data.roles) {
                 commit('setRoles', data.roles)

Some files were not shown because too many files changed in this diff