display name when available instead of email in header

This commit is contained in:
Bachir Soussi Chiadmi 2022-03-08 22:46:14 +01:00
parent 6707528059
commit d9e5749f39
7 changed files with 33 additions and 3 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -793,6 +793,9 @@ aside.messages{
#content-left{ #content-left{
z-index: 5; z-index: 5;
box-sizing: content-box; box-sizing: content-box;
position:fixed;
max-width:1px; max-width:1px;
overflow-x: hidden; overflow-x: hidden;
transition: all 0.3s ease-in-out; transition: all 0.3s ease-in-out;

View File

@ -4,7 +4,8 @@
> --> > -->
<a class="mdi mdi-account" href="/user"> <a class="mdi mdi-account" href="/user">
<span>{{ mail }}</span> <span v-if="name">{{ name }}</span>
<span v-else>{{ mail }}</span>
</a> </a>
<!-- </h4> --> <!-- </h4> -->
<a href="/admin/content/materials" <a href="/admin/content/materials"
@ -27,6 +28,8 @@ import { mapState, mapActions } from 'vuex'
import UserFlags from 'vuejs/components/User/UserFlags' import UserFlags from 'vuejs/components/User/UserFlags'
export default { export default {
watch: {
},
components: { components: {
UserFlags UserFlags
}, },
@ -38,6 +41,7 @@ export default {
computed: { computed: {
...mapState({ ...mapState({
mail: state => state.User.mail, mail: state => state.User.mail,
name: state => state.User.name,
isAdmin: state => state.User.isAdmin, isAdmin: state => state.User.isAdmin,
isAdherent: state => state.User.isAdherent, isAdherent: state => state.User.isAdherent,
flags: state => state.User.flags flags: state => state.User.flags

View File

@ -16,6 +16,7 @@ export default {
uid: null, uid: null,
// username: '', // username: '',
mail: '', mail: '',
name: null,
csrf_token: null, csrf_token: null,
logout_token: null, logout_token: null,
loginMessage: '', loginMessage: '',
@ -92,6 +93,10 @@ export default {
state.hasDBAccess = true state.hasDBAccess = true
} }
}, },
setName (state, name) {
console.log('setName', name)
state.name = name
},
setLoggedOut (state) { setLoggedOut (state) {
console.log('setLoggedOut state', state) console.log('setLoggedOut state', state)
state.uid = null state.uid = null
@ -243,6 +248,10 @@ export default {
if (data.roles) { if (data.roles) {
commit('setRoles', data.roles) commit('setRoles', data.roles)
} }
console.log('customer_profiles', data.customer_profiles.length)
if (data.customer_profiles.length) {
dispatch('getUserProfiles', data.customer_profiles[data.customer_profiles.length - 1].target_id)
}
dispatch('getUserFlagColls') dispatch('getUserFlagColls')
resolve() resolve()
}) })
@ -253,6 +262,20 @@ export default {
}) })
}) })
}, },
getUserProfiles ({ dispatch, commit, state }, pid) {
const params = {
token: state.csrf_token
}
REST.get(`/profile/${pid}?_format=json`, params).then(({ data }) => {
console.log('profile', data)
if (data.address.length) {
commit('setName', `${data.address[0].given_name} ${data.address[0].family_name} `)
}
}).catch(error => {
console.warn('Issue with getUser', error)
Promise.reject(error)
})
},
getUserFlagColls ({ dispatch, commit, state }) { getUserFlagColls ({ dispatch, commit, state }) {
// flags // flags
// REST.get('/flagging_collection/1?_format=json') // REST.get('/flagging_collection/1?_format=json')