diff --git a/WEB/src/api/users/changeUserPassword.js b/WEB/src/api/users/changeUserPassword.js new file mode 100644 index 0000000..c53c041 --- /dev/null +++ b/WEB/src/api/users/changeUserPassword.js @@ -0,0 +1,27 @@ +import axios from "axios"; +import CONFIG from "@/core/config.js"; + +const changeUserPassword = async (userId, newPasswordData) => { + try { + const token = localStorage.getItem("access_token"); + const response = await axios.patch( + `${CONFIG.BASE_URL}/users/${userId}/password`, + newPasswordData, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + return response.data; + } catch (error) { + if (error.response?.status === 400) { + throw new Error(error.response.data.detail); + } else if (error.response?.status === 403) { + throw new Error("Доступ запрещён (403)"); + } + throw new Error(error.message); + } +}; + +export default changeUserPassword; \ No newline at end of file diff --git a/WEB/src/api/users/getUsers.js b/WEB/src/api/users/getUsers.js deleted file mode 100644 index 5411f49..0000000 --- a/WEB/src/api/users/getUsers.js +++ /dev/null @@ -1,18 +0,0 @@ -import axios from "axios"; -import CONFIG from "@/core/config.js"; - -const fetchUsers = async () => { - try { - const response = await axios.get(`${CONFIG.BASE_URL}/users`, { - withCredentials: true, - }); - return response.data; - } catch (error) { - if (error.response?.status === 401) { - throw new Error("Нет доступа к пользователям (401)"); - } - throw new Error(error.message); - } -}; - -export default fetchUsers; diff --git a/WEB/src/api/users/registerUser.js b/WEB/src/api/users/registerUser.js new file mode 100644 index 0000000..462f85e --- /dev/null +++ b/WEB/src/api/users/registerUser.js @@ -0,0 +1,19 @@ +import axios from "axios"; +import CONFIG from "@/core/config.js"; + +const registerUser = async (userData) => { + try { + const response = await axios.post( + `${CONFIG.BASE_URL}/users/register`, + userData + ); + return response.data; + } catch (error) { + if (error.response?.status === 400) { + throw new Error(error.response.data.detail); + } + throw new Error(error.message); + } +}; + +export default registerUser; \ No newline at end of file diff --git a/WEB/src/pages/AdminPage.vue b/WEB/src/pages/AdminPage.vue index b4e3209..80f6cc5 100644 --- a/WEB/src/pages/AdminPage.vue +++ b/WEB/src/pages/AdminPage.vue @@ -143,6 +143,7 @@ +