[WIP] Добавил авторизированного пользователя и отображение его аватара
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
.flex.flex-col.w-full.h-full.gap-y-2
|
.flex.flex-col.w-full.h-full.gap-y-2
|
||||||
the-header(
|
the-header(
|
||||||
|
:url="url",
|
||||||
:is-open-form="isOpenForm",
|
:is-open-form="isOpenForm",
|
||||||
:close-form="closeForm",
|
:close-form="closeForm",
|
||||||
:open-form="openForm",
|
:open-form="openForm",
|
||||||
|
|||||||
@@ -23,8 +23,9 @@
|
|||||||
button.header-buttons.flex.justify-center.items-center.mr-8.p-0
|
button.header-buttons.flex.justify-center.items-center.mr-8.p-0
|
||||||
.icon-bell.text-xxl
|
.icon-bell.text-xxl
|
||||||
.flex.justify-centflexer.items-center.relative
|
.flex.justify-centflexer.items-center.relative
|
||||||
base-avatar.mr-2(:size="32")
|
base-avatar.mr-2(:size="36", :color="userData.color", v-if="!userData.photo") {{changeName}}
|
||||||
img(:src="avatarSrc", alt="Avatar")
|
base-avatar.mr-2(:size="32", v-else)
|
||||||
|
img.h-full.object-cover(:src="url + userData.photo", alt="Avatar")
|
||||||
button.header-buttons(@click="openPopup")
|
button.header-buttons(@click="openPopup")
|
||||||
.icon-down-arrow.text-xxs.flex.justify-center.items-center.p-0
|
.icon-down-arrow.text-xxs.flex.justify-center.items-center.p-0
|
||||||
base-popup.right-2.top-10(v-if="showPopup", :width="160", v-click-outside="openPopup")
|
base-popup.right-2.top-10(v-if="showPopup", :width="160", v-click-outside="openPopup")
|
||||||
@@ -49,6 +50,7 @@ export default {
|
|||||||
BaseClientFormCreate,
|
BaseClientFormCreate,
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
|
url: String,
|
||||||
openForm: Function,
|
openForm: Function,
|
||||||
closeForm: Function,
|
closeForm: Function,
|
||||||
isOpenForm: Boolean,
|
isOpenForm: Boolean,
|
||||||
@@ -62,8 +64,16 @@ export default {
|
|||||||
name: "Гордеев Николай Степанович",
|
name: "Гордеев Николай Степанович",
|
||||||
},
|
},
|
||||||
showPopup: false,
|
showPopup: false,
|
||||||
|
userData: JSON.parse(localStorage.getItem("userData")),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
changeName() {
|
||||||
|
return `${this.userData.last_name || ""} ${
|
||||||
|
this.userData.first_name || ""
|
||||||
|
} ${this.userData.patronymic || ""}`;
|
||||||
|
},
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
logout() {
|
logout() {
|
||||||
localStorage.removeItem("tokenAccess");
|
localStorage.removeItem("tokenAccess");
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ export default {
|
|||||||
authorized: true,
|
authorized: true,
|
||||||
user: { username: "", password: "" },
|
user: { username: "", password: "" },
|
||||||
redColor: "var(--border-red-color)",
|
redColor: "var(--border-red-color)",
|
||||||
|
userData: {},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -83,6 +84,30 @@ export default {
|
|||||||
localStorage.username = this.user.username;
|
localStorage.username = this.user.username;
|
||||||
localStorage.password = this.user.password;
|
localStorage.password = this.user.password;
|
||||||
},
|
},
|
||||||
|
auth(token) {
|
||||||
|
fetch("http://45.84.227.122:8080/auth/users/me/", {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
return res.json();
|
||||||
|
})
|
||||||
|
.then((data) => {
|
||||||
|
fetch(`http://45.84.227.122:8080/accounts/users/${data.id}/detail`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
return res.json();
|
||||||
|
})
|
||||||
|
.then((data) => {
|
||||||
|
this.userData = data;
|
||||||
|
localStorage.setItem("userData", JSON.stringify(this.userData));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
login() {
|
login() {
|
||||||
const requestOptions = {
|
const requestOptions = {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -103,6 +128,7 @@ export default {
|
|||||||
if (token) {
|
if (token) {
|
||||||
localStorage.setItem("tokenAccess", token.access);
|
localStorage.setItem("tokenAccess", token.access);
|
||||||
this.$router.push("/");
|
this.$router.push("/");
|
||||||
|
this.auth(token.access);
|
||||||
} else {
|
} else {
|
||||||
this.$router.push("/login");
|
this.$router.push("/login");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user