mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
фикс авторизации
This commit is contained in:
@@ -11,9 +11,9 @@ from ..utils.auth import verify_password
|
||||
from ..utils.jwt import create_and_save_token
|
||||
|
||||
router = APIRouter()
|
||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="login")
|
||||
|
||||
@router.post("/token", response_model=Token)
|
||||
@router.post("/login", response_model=Token)
|
||||
async def login_for_access_token(
|
||||
form_data: OAuth2PasswordRequestForm = Depends(),
|
||||
db: Session = Depends(get_db)
|
||||
@@ -35,7 +35,7 @@ async def login_for_access_token(
|
||||
"token_type": "bearer"
|
||||
}
|
||||
|
||||
@router.post("/admin/token", response_model=Token)
|
||||
@router.post("/admin/login", response_model=Token)
|
||||
async def admin_login(
|
||||
form_data: OAuth2PasswordRequestForm = Depends(),
|
||||
db: Session = Depends(get_db)
|
||||
|
@@ -18,12 +18,13 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
|
||||
async function login(lastName: string, password: string): Promise<boolean> {
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('username', lastName);
|
||||
formData.append('password', password);
|
||||
|
||||
const response = await fetch('/api/auth/login', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ lastName, password }),
|
||||
body: formData
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -41,12 +42,13 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
|
||||
async function adminLogin(username: string, password: string): Promise<boolean> {
|
||||
try {
|
||||
const response = await fetch('/api/auth/admin', {
|
||||
const formData = new FormData();
|
||||
formData.append('username', username);
|
||||
formData.append('password', password);
|
||||
|
||||
const response = await fetch('/api/auth/admin/login', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ username, password }),
|
||||
body: formData
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
|
@@ -97,10 +97,11 @@ const handleLogin = async () => {
|
||||
|
||||
try {
|
||||
console.log('Отправка запроса на авторизацию...')
|
||||
const response = await axios.post('/api/auth/login', {
|
||||
last_name: lastName.value,
|
||||
password: password.value
|
||||
})
|
||||
const formData = new FormData()
|
||||
formData.append('username', lastName.value)
|
||||
formData.append('password', password.value)
|
||||
|
||||
const response = await axios.post('/api/auth/login', formData)
|
||||
console.log('Ответ от сервера:', response.data)
|
||||
|
||||
// Сохраняем данные сотрудника и токен
|
||||
|
@@ -60,10 +60,11 @@ export default {
|
||||
this.isLoading = true
|
||||
|
||||
try {
|
||||
const response = await axios.post('/api/auth/admin/login', {
|
||||
username: this.username,
|
||||
password: this.password
|
||||
})
|
||||
const formData = new FormData()
|
||||
formData.append('username', this.username)
|
||||
formData.append('password', this.password)
|
||||
|
||||
const response = await axios.post('/api/auth/admin/login', formData)
|
||||
|
||||
localStorage.setItem('admin_token', response.data.access_token)
|
||||
this.$router.push('/admin/dashboard')
|
||||
|
Reference in New Issue
Block a user