diff --git a/src/views/LandingPages/SignIn/BasicRegister.vue b/src/views/LandingPages/SignIn/BasicRegister.vue index 8775585..bbd6d93 100644 --- a/src/views/LandingPages/SignIn/BasicRegister.vue +++ b/src/views/LandingPages/SignIn/BasicRegister.vue @@ -13,31 +13,38 @@ import setMaterialInput from "@/assets/js/material-input"; const username = ref(''); const password = ref(''); +const email = ref(''); // Add email const errorMessage = ref(''); const isAuthenticated = computed(() => !!sessionStorage.getItem('access_token')); // Computed property to check if the user is authenticated -const login = async () => { - if (!username.value || !password.value) { - errorMessage.value = "Please fill in both fields."; + + +// New register function +const register = async () => { + if (!username.value || !password.value || !email.value) { + errorMessage.value = "Please fill in all fields."; } else { - const url = 'http://somebodyhire.me/api/token/'; + const url = 'http://somebodyhire.me/api/register/'; const headers = { 'Content-Type': 'application/json', }; const body = { username: username.value, password: password.value, + email: email.value, // include email in the request body + is_staff: false }; try { const response = await axios.post(url, body, { headers }); - errorMessage.value = `Request:\nPOST ${url}\nHeaders: ${JSON.stringify(headers)}\nBody: ${JSON.stringify(body)}\n\nResponse:\nStatus: ${response.status}\nHeaders: ${JSON.stringify(response.headers)}\nBody: ${JSON.stringify(response.data)}`; - sessionStorage.setItem('access_token', response.data.access); // Save the access token in sessionStorage (new line) + errorMessage.value = `Registration successful. Welcome ${response.data.username}!`; // Display success message + sessionStorage.setItem('access_token', response.data.token); // Save the access token in sessionStorage } catch (error) { if (error.response) { - // The request was made and the server responded with a status code that falls out of the range of 2xx + // The request was made and the server responded with a status code + // that falls out of the range of 2xx errorMessage.value = `Request:\nPOST ${url}\nHeaders: ${JSON.stringify(headers)}\nBody: ${JSON.stringify(body)}\n\nResponse:\nStatus: ${error.response.status}\nHeaders: ${JSON.stringify(error.response.headers)}\nBody: ${JSON.stringify(error.response.data)}`; } else if (error.request) { // The request was made but no response was received @@ -50,11 +57,6 @@ const login = async () => { } }; -const logout = () => { // Method to logout the user by clearing the session storage (new function) - sessionStorage.removeItem('access_token'); -}; - - onMounted(() => { setMaterialInput(); }); @@ -66,17 +68,16 @@ export default { return { username: '', password: '', + email: '', errorMessage: '', }; }, methods: { - login() { - if (!this.username || !this.password) { - this.errorMessage = "Please fill in both fields."; - } else { - // Implement login logic here - this.errorMessage = `Can't login now, you are trying to sign in with login: ${this.username} and password: ${this.password}`; - } + register() { + this.username = username.value; + this.password = password.value; + this.email = email.value; + register(); // Call the register function }, }, }; @@ -115,15 +116,10 @@ export default {
-
- -

Опять Ты!

- -
- -
+
-

Ты с какого района?

+

Пожалуйста, зарегистрируйтесь

+

Пароль должен быть не менее 8 символов, и не быть похожим на имя пользователя или адрес почты

@@ -132,6 +128,11 @@ export default {
+
+ +
+ +
@@ -139,12 +140,12 @@ export default {
+ type="button" + class="btn bg-gradient-dark w-100 my-4 mb-2" + @click="register" +> + Зарегистрироваться +