2025-12-12 13:30:09 +03:00
|
|
|
<template>
|
|
|
|
|
<div class="auth-page">
|
|
|
|
|
<div class="auth-card card">
|
|
|
|
|
<h2>Вход</h2>
|
|
|
|
|
<form @submit.prevent="handleLogin">
|
|
|
|
|
<div class="form-group">
|
2025-12-19 19:22:35 +03:00
|
|
|
<label>Имя пользователя</label>
|
|
|
|
|
<input type="text" v-model="username" required />
|
2025-12-12 13:30:09 +03:00
|
|
|
</div>
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<label>Пароль</label>
|
|
|
|
|
<input type="password" v-model="password" required />
|
|
|
|
|
</div>
|
|
|
|
|
<p v-if="error" class="error-message">{{ error }}</p>
|
|
|
|
|
<button type="submit" class="btn-primary" :disabled="loading">
|
|
|
|
|
{{ loading ? 'Вход...' : 'Войти' }}
|
|
|
|
|
</button>
|
|
|
|
|
</form>
|
|
|
|
|
<p class="auth-link">
|
|
|
|
|
Нет аккаунта? <router-link to="/register">Зарегистрироваться</router-link>
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
import { ref } from 'vue'
|
|
|
|
|
import { useRouter } from 'vue-router'
|
|
|
|
|
import { useAuthStore } from '../stores/auth'
|
|
|
|
|
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
const authStore = useAuthStore()
|
|
|
|
|
|
2025-12-19 19:22:35 +03:00
|
|
|
const username = ref('')
|
2025-12-12 13:30:09 +03:00
|
|
|
const password = ref('')
|
|
|
|
|
const error = ref('')
|
|
|
|
|
const loading = ref(false)
|
|
|
|
|
|
|
|
|
|
async function handleLogin() {
|
|
|
|
|
error.value = ''
|
|
|
|
|
loading.value = true
|
|
|
|
|
|
|
|
|
|
try {
|
2025-12-19 19:22:35 +03:00
|
|
|
await authStore.login(username.value, password.value)
|
2025-12-12 13:30:09 +03:00
|
|
|
router.push('/')
|
|
|
|
|
} catch (e) {
|
|
|
|
|
error.value = e.response?.data?.detail || 'Ошибка входа'
|
|
|
|
|
} finally {
|
|
|
|
|
loading.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
.auth-page {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
align-items: center;
|
|
|
|
|
min-height: calc(100vh - 100px);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.auth-card {
|
|
|
|
|
width: 100%;
|
|
|
|
|
max-width: 400px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.auth-card h2 {
|
|
|
|
|
margin-bottom: 24px;
|
|
|
|
|
text-align: center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.auth-card button {
|
|
|
|
|
width: 100%;
|
|
|
|
|
margin-top: 8px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.auth-link {
|
|
|
|
|
text-align: center;
|
|
|
|
|
margin-top: 16px;
|
|
|
|
|
color: #aaa;
|
|
|
|
|
}
|
|
|
|
|
</style>
|