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

This commit is contained in:
Bachir Soussi Chiadmi 2021-09-16 21:40:18 +02:00
parent d26e21b5a5
commit a352b9745b
36 changed files with 197 additions and 54 deletions

View File

@ -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",

55
composer.lock generated
View File

@ -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,

View File

@ -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

View File

@ -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 one or more lines are too long

View File

@ -4,4 +4,4 @@
}
}
${m()}
`;l.E.post("",{query:(0,r.S)(e)}).then((({data:{data:{article:e}}})=>{this.parseDataGQL(e)})).catch((e=>{console.warn("Issue with loadArticle",e),Promise.reject(e)}))},parseDataGQL(e){this.article=e,this.items.length?this.getIndex():this.getItems().then((()=>{this.getIndex()})),this.image_accroche=e.images[0],this.lightbox_items=[];for(let t=0;t<e.images.length;t++)e.images[t].thumb=e.images[t].style_articlecardmedium.url,this.lightbox_items.push(e.images[t]);for(let t=0;t<e.videos.length;t++){let i=e.videos[t].url,n=null,a=null;switch(/https:\/\/(www\.)?(?<provider>youtube|vimeo)\.com\/.+/.exec(i).groups.provider){case"vimeo":n=/https:\/\/vimeo\.com\/(?<id>\d+)/.exec(i).groups.id||null,a="http://blogpeda.ac-poitiers.fr/ent-lyc/files/2015/06/Vimeo_icon_block.png";break;case"youtube":n=/https:\/\/(www\.)?youtube\.com\/watch\?v=(?<id>.+)/.exec(i).groups.id||null,a="http://img.youtube.com/vi/"+n+"/0.jpg"}this.lightbox_items.push({url:i,title:"",description:"",thumb:a})}this.lightbox_items,this.$store.commit("Common/setPagetitle",e.title),this.loading=!1},onPrevNext(e){let t=e.view_node.replace(/^\/\D{2,3}\/blabla\//g,"");this.$router.push({name:"article",params:{alias:t,id:e.nid}})},setLightboxIndex(e){this.lightbox_index=e}},components:{Card:u.Z},watch:{$route(e,t){this.getArticle()}}};var h=(0,i(1900).Z)(g,n,[],!1,null,"74fbee19",null);h.options.__file="web/themes/custom/materiotheme/vuejs/components/Pages/Article.vue";const _=h.exports}}]);
`;l.Z.post("",{query:(0,r.S)(e)}).then((({data:{data:{article:e}}})=>{this.parseDataGQL(e)})).catch((e=>{console.warn("Issue with loadArticle",e),Promise.reject(e)}))},parseDataGQL(e){this.article=e,this.items.length?this.getIndex():this.getItems().then((()=>{this.getIndex()})),this.image_accroche=e.images[0],this.lightbox_items=[];for(let t=0;t<e.images.length;t++)e.images[t].thumb=e.images[t].style_articlecardmedium.url,this.lightbox_items.push(e.images[t]);for(let t=0;t<e.videos.length;t++){let i=e.videos[t].url,n=null,a=null;switch(/https:\/\/(www\.)?(?<provider>youtube|vimeo)\.com\/.+/.exec(i).groups.provider){case"vimeo":n=/https:\/\/vimeo\.com\/(?<id>\d+)/.exec(i).groups.id||null,a="http://blogpeda.ac-poitiers.fr/ent-lyc/files/2015/06/Vimeo_icon_block.png";break;case"youtube":n=/https:\/\/(www\.)?youtube\.com\/watch\?v=(?<id>.+)/.exec(i).groups.id||null,a="http://img.youtube.com/vi/"+n+"/0.jpg"}this.lightbox_items.push({url:i,title:"",description:"",thumb:a})}this.lightbox_items,this.$store.commit("Common/setPagetitle",e.title),this.loading=!1},onPrevNext(e){let t=e.view_node.replace(/^\/\D{2,3}\/blabla\//g,"");this.$router.push({name:"article",params:{alias:t,id:e.nid}})},setLightboxIndex(e){this.lightbox_index=e}},components:{Card:u.Z},watch:{$route(e,t){this.getArticle()}}};var h=(0,i(1900).Z)(g,n,[],!1,null,"74fbee19",null);h.options.__file="web/themes/custom/materiotheme/vuejs/components/Pages/Article.vue";const _=h.exports}}]);

View File

@ -4,4 +4,4 @@
}
}
${c()}
`;l.E.post("",{query:(0,d.S)(e)}).then((({data:{data:{thematique:e}}})=>{this.parseDataGQL(e)})).catch((e=>{console.warn("Issue with loadThematique",e),Promise.reject(e)}))},parseDataGQL(e){e?(this.thematique=e,e.images&&(this.image_accroche=e.images[0]),this.$store.commit("Common/setPagetitle",e.title)):console.warn("Thematique not loaded"),this.loading=!1}},components:{Card:u.Z},watch:{$route(e,t){this.getThematique()}}};var g=(0,i(1900).Z)(h,a,[],!1,null,"128bc334",null);g.options.__file="web/themes/custom/materiotheme/vuejs/components/Pages/Thematique.vue";const _=g.exports}}]);
`;l.Z.post("",{query:(0,d.S)(e)}).then((({data:{data:{thematique:e}}})=>{this.parseDataGQL(e)})).catch((e=>{console.warn("Issue with loadThematique",e),Promise.reject(e)}))},parseDataGQL(e){e?(this.thematique=e,e.images&&(this.image_accroche=e.images[0]),this.$store.commit("Common/setPagetitle",e.title)):console.warn("Thematique not loaded"),this.loading=!1}},components:{Card:u.Z},watch:{$route(e,t){this.getThematique()}}};var g=(0,i(1900).Z)(h,a,[],!1,null,"128bc334",null);g.options.__file="web/themes/custom/materiotheme/vuejs/components/Pages/Thematique.vue";const _=g.exports}}]);

File diff suppressed because one or more lines are too long

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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'],

View File

@ -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'],

View File

@ -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;

View File

@ -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 {

View File

@ -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'

View File

@ -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 {

View File

@ -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'

View File

@ -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;

View File

@ -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",

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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 {

View File

@ -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 {

View File

@ -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'

View File

@ -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'

View File

@ -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 {

View File

@ -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)