mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-28 23:42:58 -04:00
[admin] impersonation (@example only)
This commit is contained in:
parent
532a0ee0e2
commit
4431d1d1b7
@ -132,6 +132,11 @@
|
|||||||
<Icon v="trash-alt"/>
|
<Icon v="trash-alt"/>
|
||||||
<T>user.deleteAccount</T>
|
<T>user.deleteAccount</T>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
<a v-if="impersonationActive" href="#" class="badge bg-light text-dark border border-primary" @click.prevent="stopImpersonation">
|
||||||
|
<Icon v="user-secret"/>
|
||||||
|
Stop impersonation
|
||||||
|
</a>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
@ -177,6 +182,8 @@
|
|||||||
universalDomains: process.env.ALL_LOCALES_URLS.split(',').filter(x => x !== process.env.BASE_URL),
|
universalDomains: process.env.ALL_LOCALES_URLS.split(',').filter(x => x !== process.env.BASE_URL),
|
||||||
|
|
||||||
logoutInProgress: false,
|
logoutInProgress: false,
|
||||||
|
|
||||||
|
impersonationActive: !!this.$cookies.get('impersonator')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
@ -284,6 +291,11 @@
|
|||||||
async uploaded(ids) {
|
async uploaded(ids) {
|
||||||
await this.setAvatar(`${process.env.BUCKET}/images/${ids[0]}-thumb.png`);
|
await this.setAvatar(`${process.env.BUCKET}/images/${ids[0]}-thumb.png`);
|
||||||
},
|
},
|
||||||
|
async stopImpersonation() {
|
||||||
|
this.$cookies.set('token', this.$cookies.get('impersonator'));
|
||||||
|
this.$cookies.remove('impersonator');
|
||||||
|
window.location.reload();
|
||||||
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState([
|
...mapState([
|
||||||
|
@ -96,6 +96,11 @@
|
|||||||
{{ stats.cardsQueue }}
|
{{ stats.cardsQueue }}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<Icon v="user-secret"/>
|
||||||
|
Impersonate <button class="btn btn-primary btn-sm" @click="impersonate('example@pronouns.page')">@example</button>
|
||||||
|
</section>
|
||||||
|
|
||||||
<section v-if="$isGranted('users')">
|
<section v-if="$isGranted('users')">
|
||||||
<h3>
|
<h3>
|
||||||
<Icon v="siren-on"/>
|
<Icon v="siren-on"/>
|
||||||
@ -237,6 +242,13 @@
|
|||||||
return r;
|
return r;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
async impersonate(email) {
|
||||||
|
const { token } = await this.$axios.$get(`/admin/impersonate/${encodeURIComponent(email)}`);
|
||||||
|
this.$cookies.set('impersonator', this.$cookies.get('token'));
|
||||||
|
this.$cookies.set('token', token);
|
||||||
|
this.$router.push('/' + this.config.user.route);
|
||||||
|
setTimeout(() => window.location.reload(), 500);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
profilesByLocale() {
|
profilesByLocale() {
|
||||||
|
@ -499,4 +499,12 @@ router.get('/user/logout-universal', handleErrorAsync(async (req, res) => {
|
|||||||
return res.json('Token removed');
|
return res.json('Token removed');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
router.get('/admin/impersonate/:email', handleErrorAsync(async (req, res) => {
|
||||||
|
if (!req.isGranted('users') || !['example@pronouns.page'].includes(req.params.email)) {
|
||||||
|
return res.status(401).json({error: 'Unauthorised'});
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json({token: await issueAuthentication(req.db, {email: req.params.email})});
|
||||||
|
}));
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user