[WIP] Добавил отображение сотрудников на графике, поправил стили, изменил запросы логина

This commit is contained in:
megavrilinvv
2022-12-22 18:18:43 +03:00
parent 838266c0e9
commit 3773c15ad5
6 changed files with 145 additions and 104 deletions

View File

@@ -36,6 +36,7 @@
</template>
<script>
import { fetchWrapper } from "@/shared/fetchWrapper";
import BaseInput from "@/components/base/BaseInput";
import BaseButton from "@/components/base/BaseButton";
import viewPasswordIcon from "@/assets/icons/eye.svg";
@@ -84,46 +85,28 @@ export default {
localStorage.username = this.user.username;
localStorage.password = this.user.password;
},
async auth(token) {
let res = await fetch("https://astra-dev.dopcore.com/auth/users/me/", {
headers: {
Authorization: `Bearer ${token}`,
},
});
res = await res.json();
let data = await fetch(
`https://astra-dev.dopcore.com/accounts/users/${res.id}/detail`,
{
headers: {
Authorization: `Bearer ${token}`,
},
}
);
data = await data.json();
async auth() {
let res = await fetchWrapper.get("auth/users/me/");
res = await res;
let data = await fetchWrapper.get(`accounts/users/${res.id}/detail`);
data = await data;
this.userData = data;
localStorage.setItem("userData", JSON.stringify(this.userData));
},
login() {
const requestOptions = {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(this.user),
};
fetch("https://astra-dev.dopcore.com/auth/jwt/create/", requestOptions)
.then((result) => {
if (result.status === 200) {
return result.json();
fetchWrapper
.post("auth/jwt/create/", {
username: this.user.username,
password: this.user.password,
})
.then((token) => {
if (token.access) {
localStorage.setItem("tokenAccess", token.access);
this.auth().then(() => this.$router.push("/"));
} else {
this.authorized = false;
this.user.username = "";
this.user.password = "";
}
})
.then((token) => {
if (token) {
localStorage.setItem("tokenAccess", token.access);
this.auth(token.access).then(() => this.$router.push("/"));
} else {
this.$router.push("/login");
}
});