mirror of
https://github.com/Spythere/station-manager-2.0.git
synced 2026-05-03 13:38:13 +00:00
poprawki bezpieczeństwa
This commit is contained in:
+23
-16
@@ -1,11 +1,11 @@
|
||||
<template>
|
||||
<div class="login" v-if="store.authState == AuthState.UNAUTHORIZED">
|
||||
<div class="login">
|
||||
<div class="login-header">
|
||||
<img src="/icon-logo.svg" alt="logo" />
|
||||
<h1>Stacjownik Station Manager</h1>
|
||||
</div>
|
||||
|
||||
<form @submit="signIn">
|
||||
<form @submit.prevent="signIn">
|
||||
<label for="name">Nick</label>
|
||||
<br />
|
||||
<input type="text" id="name" v-model="name" />
|
||||
@@ -22,8 +22,9 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { useStore } from '../store';
|
||||
import { useStore, baseURL } from '../store';
|
||||
import { AuthState } from '../types/types';
|
||||
import axios, { HttpStatusCode } from 'axios';
|
||||
|
||||
enum LoginState {
|
||||
INITIALIZED = 0,
|
||||
@@ -52,27 +53,33 @@ export default defineComponent({
|
||||
|
||||
methods: {
|
||||
async signIn(e: Event) {
|
||||
e.preventDefault();
|
||||
this.loginState = LoginState.LOADING;
|
||||
// this.loginState = LoginState.LOADING;
|
||||
|
||||
try {
|
||||
const loginData = (await this.store.login(this.name, this.password)).data;
|
||||
// const loginData = (await this.store.login(this.name, this.password)).data;
|
||||
const response = await axios.post(
|
||||
'auth/login',
|
||||
{ username: this.name, password: this.password },
|
||||
{
|
||||
baseURL,
|
||||
withCredentials: true,
|
||||
}
|
||||
);
|
||||
|
||||
this.store.authState = AuthState.AUTHORIZED;
|
||||
this.loginState = LoginState.LOADED;
|
||||
// this.store.authState = AuthState.AUTHORIZED;
|
||||
// this.loginState = LoginState.LOADED;
|
||||
|
||||
this.store.token = loginData.token;
|
||||
this.store.user = loginData.user;
|
||||
// this.store.token = loginData.token;
|
||||
// this.store.user = loginData.user;
|
||||
|
||||
window.localStorage.setItem('auth-token', this.store.token);
|
||||
window.localStorage.setItem('user', JSON.stringify(this.store.user));
|
||||
// window.localStorage.setItem('auth-token', this.store.token);
|
||||
// window.localStorage.setItem('user', JSON.stringify(this.store.user));
|
||||
|
||||
this.store.user = response.data;
|
||||
this.$router.push('/');
|
||||
|
||||
this.store.fetchSceneriesData();
|
||||
} catch (e: any) {
|
||||
this.store.authState = AuthState.UNAUTHORIZED;
|
||||
this.loginState = LoginState.LOADED;
|
||||
|
||||
if (!e.response || e.response.status === undefined) {
|
||||
this.errorMessage = 'Wystąpił błąd podczas łączenia z serwerem!';
|
||||
return false;
|
||||
@@ -81,7 +88,7 @@ export default defineComponent({
|
||||
const response = e.response;
|
||||
const status: number = response.status;
|
||||
|
||||
if (status == 401) {
|
||||
if (status == 400) {
|
||||
this.errorMessage = 'Nieprawidłowe dane!';
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="manager" v-if="store.authState == AuthState.AUTHORIZED">
|
||||
<div class="manager">
|
||||
<RoutesModal v-if="store.currentStation" />
|
||||
<UpdateCard v-if="store.changesResponse.length > 0" />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user