Commit 1dd41086 authored by Django Janny's avatar Django Janny
Browse files

UNOTOPLYS-301 - Gestion du cas d'un utilisateur n'ayant aucun droit

parent 379c31ab
......@@ -5,7 +5,9 @@
<div class="alert alert-danger">{{ errorMessage }}</div>
</div>
<div v-if="error403" class="alert alert-danger">{{ $t('error.http.403') }}</div>
<div v-if="error403" class="alert"><a href="/login">Page d'accueil</a></div>
<div v-if="error403" class="alert">
<a href="/logout">{{ $t('error.home') }}</a>
</div>
<div v-if="error404" class="alert alert-warning">{{ $t('error.http.404') }}</div>
</div>
</template>
......
import { ROUTES } from '@/router/routes-constants';
const Login = () => import('@/views/account/login/login.vue');
const Logout = () => import('@/views/account/logout/logout.vue');
const ResetPasswordInit = () => import('@/views/account/reset-password/init/reset-password-init.vue');
const ResetPasswordFinish = () => import('@/views/account/reset-password/finish/reset-password-finish.vue');
......@@ -10,6 +11,11 @@ export default [
name: ROUTES.login.name,
component: Login,
},
{
path: ROUTES.logout.path,
name: ROUTES.logout.name,
component: Logout,
},
{
path: '/account/reset/request',
name: 'ResetPasswordInit',
......
......@@ -7,6 +7,10 @@ export const ROUTES = {
path: '/login',
name: 'Login',
},
logout: {
path: '/logout',
name: 'Logout',
},
notFound: {
path: '/not-found',
name: 'NotFound',
......
......@@ -53,9 +53,21 @@ export default class AccountService {
}
if (!this.token || !this.authenticated || !this.userAuthorities) {
return this.checkAuth();
return this.checkAuth().then(connected => {
if (connected) {
return this.checkAuthority(authorities);
} else {
return new Promise(resolve => {
resolve(false);
});
}
});
} else {
return this.checkAuthority(authorities);
}
}
private checkAuthority(authorities: any): Promise<boolean> {
for (let i = 0; i < authorities.length; i++) {
if (this.userAuthorities.includes(authorities[i])) {
return new Promise(resolve => {
......@@ -63,7 +75,6 @@ export default class AccountService {
});
}
}
return new Promise(resolve => {
resolve(false);
});
......@@ -93,14 +104,17 @@ export default class AccountService {
if (this.router.getRoutes().find(r => r.path === path) && !this.router.getRoutes().find(r => r.path === path).meta.authorities) {
return true;
}
for (let authority of this.userAuthorities) {
if (
this.router
.getRoutes()
.find(r => r.path === path)
?.meta?.authorities?.includes(authority)
) {
return true;
if (this.store.getters.account) {
for (let authority of this.userAuthorities) {
if (
this.router
.getRoutes()
.find(r => r.path === path)
?.meta?.authorities?.includes(authority)
) {
return true;
}
}
}
return false;
......
import { mixins } from 'vue-class-component';
import { Component } from 'vue-property-decorator';
import AdminMixin from '@/views/account/account.mixin';
import AccountMixin from '@/views/account/account.mixin';
@Component
export default class Login extends mixins(AdminMixin) {
export default class Login extends mixins(AccountMixin) {
public authenticationError = null;
public login = null;
......
import { mixins } from 'vue-class-component';
import { Component } from 'vue-property-decorator';
import AccountMixin from '@/views/account/account.mixin';
@Component
export default class Logout extends mixins(AccountMixin) {
beforeRouteEnter(to, from, next) {
next(vm => {
vm.doLogout();
});
}
public doLogout(): void {
this.getAccountService().logout();
}
}
<template>
<section class="max-w-xl mx-auto px-6 py-9 bg-white border border-gray-200">
<div class="block flex justify-center mb-8">
<img src="/content/images/icons/icon-aplly.svg" class="icon-aplly" />
</div>
<div class="m-8 text-center">
<router-link
class="px-6 py-4 m-1 text-base font-bold text-white bg-blue-600 rounded-full hover:bg-blue-800 focus:bg-blue-900 focus:ring"
:to="{ name: 'Login' }"
>{{ $t('global.menu.account.login') }}</router-link
>
</div>
</section>
</template>
<script lang="ts" src="./logout.component.ts" />
......@@ -2,7 +2,7 @@ import { mixins } from 'vue-class-component';
import { Component } from 'vue-property-decorator';
import { email, maxLength, minLength, required } from 'vuelidate/lib/validators';
import AdminMixin from '@/views/account/account.mixin';
import AccountMixin from '@/views/account/account.mixin';
const validations = {
resetAccount: {
......@@ -22,7 +22,7 @@ interface ResetAccount {
@Component({
validations,
})
export default class ResetPasswordInit extends mixins(AdminMixin) {
export default class ResetPasswordInit extends mixins(AccountMixin) {
public success: boolean = null;
public error: string = null;
public resetAccount: ResetAccount = {
......
......@@ -9,6 +9,7 @@
"500": "Erreur interne du serveur."
},
"concurrencyFailure": "Un autre utilisateur a modifié ces données en même temps que vous. Vos changements n'ont pas été sauvegardés.",
"validation": "Erreur de validation côté serveur."
"validation": "Erreur de validation côté serveur.",
"home": "Page d'accueil"
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment