-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from shampiniony/auth
added login authorization + started registration
- Loading branch information
Showing
8 changed files
with
159 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import axios from 'axios'; | ||
import { auth } from '@/store/auth.store'; | ||
import { apiUrl } from '@/router/router'; | ||
|
||
interface LoginResponse { | ||
access: string; | ||
refresh: string; | ||
} | ||
|
||
export const login = async (email: string, password: string): Promise<LoginResponse> => { | ||
try { | ||
const response = await axios.post<LoginResponse>(`${apiUrl}/api/v1/users/token/`, { | ||
email, | ||
password, | ||
}); | ||
|
||
const { access, refresh } = response.data; | ||
auth.authenticated = true; | ||
auth.accessToken = access; | ||
axios.defaults.headers.common['Authorization'] = `Bearer ${auth.accessToken}`; | ||
|
||
return response.data; | ||
} catch (error) { | ||
console.error('Error during login:', error); | ||
throw new Error('Invalid username or password'); | ||
} | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<template> | ||
<div class="flex justify-center items-center h-screen bg-white"> | ||
<div class="bg-white p-8 rounded w-full max-w-sm"> | ||
<h2 class="text-2xl font-bold mb-6 text-center">LOG IN</h2> | ||
<form @submit.prevent="loginUser"> | ||
<div class="mb-4"> | ||
<label class="block text-gray-700 mb-2" for="username">ЛОГИН</label> | ||
<input v-model="username" type="text" id="username" class="w-full px-3 py-2 border rounded" required> | ||
</div> | ||
<div class="mb-6"> | ||
<label class="block text-gray-700 mb-2" for="password">ПАРОЛЬ</label> | ||
<input v-model="password" type="password" id="password" class="w-full px-3 py-2 border rounded" required> | ||
</div> | ||
<button type="submit" class="w-full bg-logo-blue text-white py-2 rounded">КНОПКА</button> | ||
</form> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { ref } from 'vue'; | ||
import { useRouter } from 'vue-router'; | ||
import { login } from '@/api/login.api'; | ||
const username = ref(''); | ||
const password = ref(''); | ||
const router = useRouter(); | ||
const loginUser = async () => { | ||
try { | ||
await login(username.value, password.value); | ||
router.push({ name: 'Admin' }); | ||
} catch (error) { | ||
console.error(error); | ||
alert('Invalid username or password'); | ||
} | ||
}; | ||
</script> | ||
|
||
<style scoped> | ||
.bg-logo-blue { | ||
background-color: #6193b1; /* вроде тот цвет im not sure */ | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<template> | ||
<div class="flex justify-center items-center h-screen bg-white"> | ||
<div class="bg-white p-8 rounded w-full max-w-sm ml-[200px]"> | ||
<h2 class="text-2xl font-bold mb-6 text-center">СОЗДАТЬ ПОЛЬЗОВАТЕЛЯ</h2> | ||
<form> | ||
<div class="mb-4"> | ||
<label class="block text-gray-700 mb-2" for="surname">ФАМИЛИЯ</label> | ||
<input v-model="surname" type="text" id="surname" class="w-full px-3 py-2 border rounded" required> | ||
</div> | ||
<div class="mb-6"> | ||
<label class="block text-gray-700 mb-2" for="name">ИМЯ</label> | ||
<input v-model="name" type="text" id="name" class="w-full px-3 py-2 border rounded" required> | ||
</div> | ||
<div class="mb-8"> | ||
<label class="block text-gray-700 mb-2" for="patronymic">ОТЧЕСТВО</label> | ||
<input v-model="patronymic" type="text" id="patronymic" class="w-full px-3 py-2 border rounded" required> | ||
</div> | ||
<div class="mb-10"> | ||
<label class="block text-gray-700 mb-2" for="location">МЕСТО</label> | ||
<input v-model="password" type="password" id="location" class="w-full px-3 py-2 border rounded" required> | ||
</div> | ||
<div class="mb-12"> | ||
<label class="block text-gray-700 mb-2" for="password">ID</label> | ||
<input v-model="password" type="password" id="password" class="w-full px-3 py-2 border rounded" required> | ||
</div> | ||
<div class="mb-14"> | ||
<label class="block text-gray-700 mb-2" for="password">ТЕЛЕФОН</label> | ||
<input v-model="password" type="password" id="password" class="w-full px-3 py-2 border rounded" required> | ||
</div> | ||
<div class="mb-16"> | ||
<label class="block text-gray-700 mb-2" for="password">EMAIL</label> | ||
<input v-model="password" type="password" id="password" class="w-full px-3 py-2 border rounded" required> | ||
</div> | ||
<button type="submit" class="w-full bg-logo-blue text-white py-2 rounded">ДОБАВИТЬ</button> | ||
</form> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { ref } from 'vue'; | ||
import { useRouter } from 'vue-router'; | ||
</script> | ||
|
||
<style scoped> | ||
.bg-logo-blue { | ||
background-color: #6193b1; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters