Skip to content

Commit 972f441

Browse files
committed
:passport_controll: Done user auth and modify module
1 parent ecd1fcc commit 972f441

File tree

7 files changed

+129
-21
lines changed

7 files changed

+129
-21
lines changed

src/components/UI/BaseDialog.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
<teleport to="body">
33
<div v-if="show" class="backdrop" @click="tryClose"></div>
44
<transition name="dialog">
5-
<dialog v-if="show" open class="m-0 mt-n5 p-0 overflow-hidden border-0">
5+
<dialog
6+
v-if="show"
7+
open
8+
class="m-0 mt-n5 p-0 overflow-hidden border-0"
9+
:class="upper ? 'upper' : ''"
10+
>
611
<header class="w-100 p-3" :class="'bg-' + type">
712
<slot name="header">
813
<h2 class="m-0">{{ title }}</h2>
@@ -12,7 +17,7 @@
1217
<slot></slot>
1318
</section>
1419
<menu
15-
v-if="!fixed"
20+
v-if="!fixed && !footless"
1621
class="m-0 p-3 pt-0 d-flex"
1722
:class="[
1823
btn2Text === '' ? 'justify-content-end' : 'justify-content-between',
@@ -45,6 +50,8 @@ export default {
4550
btn2Text: { type: String, default: '' },
4651
btn2Type: { type: String, default: 'success' },
4752
reverse: { type: Boolean, required: false },
53+
upper: { type: Boolean, required: false },
54+
footless: { type: Boolean, required: false },
4855
},
4956
emits: ['close', 'send'],
5057
methods: {
@@ -84,6 +91,9 @@ dialog {
8491
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
8592
background-color: white;
8693
}
94+
.upper {
95+
top: 10vh;
96+
}
8797
8898
.dialog-enter-from,
8999
.dialog-leave-to {

src/components/UI/BaseTable.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
</tbody>
4242
</table>
4343
</div>
44+
<div v-else>NINCS ADAT</div>
4445
</template>
4546

4647
<script>

src/components/admin/AdminUser.vue

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<template>
2-
<div>Felhasználói fiókok</div>
3-
<div v-if="loading">Loading...</div>
2+
<div class="h3 my-3">Felhasználói fiókok</div>
3+
<base-dialog :show="!!selectedId" upper footless>
4+
<profile :id="selectedId" imported @close="close"></profile>
5+
</base-dialog>
6+
<base-loader v-if="loading">Loading...</base-loader>
47
<base-table
58
v-else
69
:data="users"
@@ -14,11 +17,15 @@
1417

1518
<script>
1619
import { ref } from 'vue';
20+
import roleEnum from '@/config/role.enum';
1721
import axios from '@/config/axios.js';
1822
import moment from 'moment';
23+
import Profile from '../../views/Profile.vue';
1924
export default {
2025
name: 'AdminUser',
26+
components: { Profile },
2127
setup() {
28+
const selectedId = ref(0);
2229
const users = ref();
2330
const loading = ref(true);
2431
@@ -30,10 +37,11 @@ export default {
3037
id: user.id,
3138
Név: user.name,
3239
'E-mail cím': user.email,
40+
Jogosultság: user.role < 6 ? roleEnum[user.role] : user.role,
3341
'Létrehozás dátuma': moment(user.createdAt)
3442
.locale('hu')
3543
.format('ll'),
36-
'Utolsó frissítés dátuma': moment(user.updatedAt)
44+
'Utolsó belépés': moment(user.signedIn)
3745
.locale('hu')
3846
.format('YYYY MMM Do'),
3947
};
@@ -44,13 +52,19 @@ export default {
4452
fetchAll();
4553
4654
function edit(id) {
47-
console.log('EDIT', id);
55+
selectedId.value = id.toString();
56+
}
57+
function close() {
58+
selectedId.value = 0;
59+
fetchAll();
4860
}
4961
function del(id) {
50-
console.log('DELETE', id);
62+
axios.delete('/users/' + id).then(() => {
63+
fetchAll();
64+
});
5165
}
5266
53-
return { users, loading, edit, del };
67+
return { users, loading, edit, del, selectedId, close };
5468
},
5569
};
5670
</script>

src/config/role.enum.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// export default {
2+
// Vendég: 0,
3+
// Felhasználó: 1,
4+
// Szerkesztő: 2,
5+
// Moderátor: 3,
6+
// Admin: 4,
7+
// Superuser: 5,
8+
// };
9+
10+
export default ['Vendég', 'Felhasználó', 'Szerkesztő', 'Moderátor', 'Admin', 'Superuser'];

src/router.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ const routes = [
1111
{ path: '/', name: 'landing', component: Landing, meta: { title: 'Főoldal', role: 0 } },
1212
{ path: '/auth', name: 'auth', component: Auth, meta: { title: 'Bejelentlkezés', role: 0 } },
1313
{ path: '/home', name: 'home', component: Home, meta: { title: 'Főoldal', role: 1 } },
14-
{ path: '/profile', name: 'profile', component: Profile, meta: { title: 'Saját fiók', role: 1 } },
14+
{
15+
path: '/profile',
16+
name: 'profile',
17+
component: Profile,
18+
meta: { title: 'Saját fiók', role: 1 },
19+
props: true,
20+
children: [{ path: ':id', name: 'profileId', component: Profile }],
21+
},
1522
{ path: '/admin', name: 'admin', component: Admin, meta: { title: 'Adminisztráció', role: 2 } },
1623
{ path: '/:notFound(.*)', name: 'notfound', component: NotFound },
1724
];

src/views/Auth.vue

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
11
<template>
22
<div>
3-
<base-dialog :show="!!hiba" title="Hibás kitöltés" btn="info" type="danger" @close="bezar">
3+
<base-dialog
4+
:show="!!hiba"
5+
:title="hiba === 'Tiltás' ? 'Jelenleg ki vagy tiltva az oldalról' : 'Hibás kitöltés'"
6+
btn="info"
7+
type="danger"
8+
@close="bezar"
9+
>
410
<ul v-if="typeof hiba === 'object'" class="list-unstyled pb-3">
511
<li v-for="h in hiba" :key="h" class="p-1">{{ h }}</li>
612
</ul>
7-
<p v-else class="p-1">{{ hiba }}</p>
13+
<p v-else class="p-1">
14+
<span v-if="hiba === 'Tiltás'">
15+
A tiltást valószínűleg egy nem megengedett kihágásodnak köszönheted.
16+
<br />
17+
<br />
18+
<small>
19+
Ha úgy érzed a tiltásod nem szabályos kérjük vedd fel a kapcsolatot az
20+
ügyfélszolgálattal!
21+
</small>
22+
</span>
23+
<span v-else>{{ hiba }}</span>
24+
</p>
825
</base-dialog>
926
<div
1027
v-if="mode"
@@ -91,6 +108,7 @@ export default {
91108
hiba.value = '';
92109
}
93110
//TODO Regisztrációhoz google reCaptcha
111+
//TODO Google belépés
94112
const reg = reactive({
95113
fullName: '',
96114
userName: '',

src/views/Profile.vue

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
<template>
2-
<div class="flex-grow-1 mt-2 px-3">
3-
<h3 class="mb-4">Személyes adatok</h3>
2+
<div class="flex-grow-1 mt-2 px-3 pb-3">
3+
<base-dialog
4+
:show="!!sureDelete"
5+
title="Biztosan törölni akarod?"
6+
type="danger"
7+
close-text="Mégse"
8+
btn="outline-warning"
9+
btn2-text="Törlés"
10+
btn2-type="outline-danger"
11+
reverse
12+
@close="sureDelete = 0"
13+
@send="del"
14+
></base-dialog>
15+
<h3 v-if="!imported" class="mb-4">Személyes adatok</h3>
416
<div
517
v-if="showErr"
618
class="alert alert-dismissible fade position-absolute z-100"
@@ -68,10 +80,10 @@
6880
Telefonszám
6981
</base-input>
7082
<base-select
71-
v-if="myProfile.role > 1"
83+
v-if="role > 1"
7284
v-model="editProfile.role"
7385
icon="user-tag"
74-
:nums="myProfile.role"
86+
:nums="id ? role - 1 : myProfile.role"
7587
:values="roleEnum"
7688
:def="myProfile.role"
7789
class="w-75 my-3"
@@ -82,6 +94,14 @@
8294
<base-button type="warning" class="w-25 align-self-center" @click="megse">
8395
Mégse
8496
</base-button>
97+
<base-button
98+
v-if="!imported"
99+
type="outline-danger"
100+
class="w-25 align-self-center"
101+
@click="sureDelete = 1"
102+
>
103+
Fiók törlése
104+
</base-button>
85105
<base-button type="primary" submit class="w-25 align-self-center">Mentés</base-button>
86106
</div>
87107
</form>
@@ -90,34 +110,39 @@
90110

91111
<script>
92112
import axios from '@/config/axios.js';
113+
import rolesEnum from '@/config/role.enum.js';
93114
import { ref, watch } from 'vue';
94115
import { useStore } from 'vuex';
95116
96117
export default {
97118
name: 'Profile',
98-
setup() {
119+
props: { id: { type: String, default: '' }, imported: { type: Boolean, required: false } },
120+
emits: ['close'],
121+
setup(props, { emit }) {
99122
const store = useStore();
123+
const sureDelete = ref(0);
100124
const error = ref('');
101125
const showErr = ref('');
102-
const roleEnum = ['Vendég', 'Felhasználó', 'Szerkesztő', 'Moderátor', 'Admin', 'Superuser'];
126+
const roleEnum = rolesEnum;
103127
const myProfile = ref();
104128
const editProfile = ref();
105129
function getFromServer() {
106-
axios.get('/users/whoami').then(res => {
130+
axios.get(`/users/whoami/${props.id}`).then(res => {
107131
myProfile.value = { ...res.data, password: '' };
108132
if (!myProfile.value.phoneNumber) myProfile.value.phoneNumber = '';
109133
editProfile.value = JSON.parse(JSON.stringify(myProfile.value));
110134
});
111135
}
112136
function save() {
113137
axios
114-
.patch('/users', editProfile.value)
138+
.patch(`/users/${props.id}`, editProfile.value)
115139
.then(({ data }) => {
116-
store.dispatch('changeAuth', { token: data.accessToken });
140+
if (!props.id) store.dispatch('changeAuth', { token: data.accessToken });
117141
myProfile.value = JSON.parse(JSON.stringify(editProfile.value));
118142
error.value = 'Sikeres mentés!';
119143
setTimeout(() => {
120144
error.value = '';
145+
if (props.imported) emit('close');
121146
}, 3000);
122147
})
123148
.catch(err => {
@@ -129,7 +154,14 @@ export default {
129154
}
130155
function megse() {
131156
editProfile.value = JSON.parse(JSON.stringify(myProfile.value));
157+
if (props.imported) emit('close');
158+
}
159+
function del() {
160+
axios.delete('/users').then(() => {
161+
store.dispatch('logout');
162+
});
132163
}
164+
//TODO Mentés után a select nem kékül vissza
133165
134166
watch(error, val => {
135167
const timer = val ? 0 : 250;
@@ -139,7 +171,23 @@ export default {
139171
});
140172
141173
getFromServer();
142-
return { myProfile, getFromServer, save, roleEnum, editProfile, error, megse, showErr };
174+
return {
175+
myProfile,
176+
getFromServer,
177+
save,
178+
editProfile,
179+
roleEnum,
180+
error,
181+
megse,
182+
showErr,
183+
sureDelete,
184+
del,
185+
};
186+
},
187+
computed: {
188+
role() {
189+
return this.$store.getters['getRole'];
190+
},
143191
},
144192
};
145193
</script>

0 commit comments

Comments
 (0)