2024-10-22 19:28:45 +03:00
|
|
|
<script>
|
2024-10-26 22:08:51 +03:00
|
|
|
import {useUserStore} from "../../store/user.js";
|
2024-10-27 09:05:23 +03:00
|
|
|
import {rules} from "../../js/rules.js";
|
2024-10-22 19:28:45 +03:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: "Registration",
|
|
|
|
data: () => ({
|
2024-10-26 22:08:51 +03:00
|
|
|
userStore: useUserStore(),
|
2024-10-28 12:59:00 +03:00
|
|
|
isWide: window.innerWidth >= 800,
|
2024-10-22 19:28:45 +03:00
|
|
|
valid: false,
|
2024-10-27 20:08:10 +03:00
|
|
|
login: null,
|
|
|
|
email: null,
|
|
|
|
password: null,
|
|
|
|
repeatPassword: null,
|
2024-10-22 19:28:45 +03:00
|
|
|
errorMessage: '',
|
2024-10-27 09:05:23 +03:00
|
|
|
errorMessageContainerStyle: 'display: none;',
|
|
|
|
showPassword: false,
|
2024-10-28 11:36:45 +03:00
|
|
|
showRepeatPassword: false,
|
|
|
|
loading: false
|
2024-10-22 19:28:45 +03:00
|
|
|
}),
|
2024-10-27 09:05:23 +03:00
|
|
|
computed: {
|
|
|
|
rules() {
|
|
|
|
return rules
|
|
|
|
}
|
|
|
|
},
|
2024-10-22 19:28:45 +03:00
|
|
|
methods: {
|
2024-10-27 20:08:10 +03:00
|
|
|
validate(){
|
|
|
|
let emailValidation = rules.email(this.email);
|
|
|
|
let loginValidation = rules.notNull(this.login);
|
|
|
|
let passwordValidation = rules.notNull(this.password);
|
|
|
|
let repeatPasswordValidation = rules.notNull(this.repeatPassword);
|
|
|
|
let validation = [emailValidation, loginValidation, passwordValidation, repeatPasswordValidation];
|
|
|
|
let check = null;
|
|
|
|
validation.forEach((element)=>{
|
|
|
|
if (typeof element !== "boolean"){
|
|
|
|
check = element;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return check === null ? true : check;
|
|
|
|
},
|
2024-10-22 19:28:45 +03:00
|
|
|
registrationAction(){
|
2024-10-28 11:36:45 +03:00
|
|
|
this.loading = true;
|
2024-10-27 20:08:10 +03:00
|
|
|
let validation = this.validate();
|
|
|
|
if (validation !== true){
|
|
|
|
alert(validation);
|
2024-11-15 22:14:38 +03:00
|
|
|
this.loading = false;
|
2024-10-27 20:08:10 +03:00
|
|
|
return;
|
|
|
|
}
|
2024-10-26 22:55:29 +03:00
|
|
|
this.userStore.registration(this.login, this.email, this.password, this.repeatPassword).then((isRegistred)=>{
|
2024-10-28 11:36:45 +03:00
|
|
|
this.loading = false;
|
2024-10-26 22:55:29 +03:00
|
|
|
if (typeof isRegistred == "boolean") {
|
|
|
|
if (isRegistred){
|
|
|
|
this.errorMessage = '';
|
|
|
|
this.errorMessageContainerStyle = 'display: none;';
|
|
|
|
this.$router.push('/');
|
|
|
|
} else {
|
|
|
|
this.errorMessage = 'Registration error';
|
|
|
|
this.errorMessageContainerStyle = '';
|
|
|
|
}
|
|
|
|
} else if (typeof isRegistred == "string") {
|
|
|
|
this.errorMessage = isRegistred;
|
|
|
|
this.errorMessageContainerStyle = '';
|
|
|
|
}
|
|
|
|
});
|
2024-10-22 19:28:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2024-10-28 12:59:00 +03:00
|
|
|
<div class="d-flex flex-column justify-center align-center" :class="isWide ? 'w-33' : 'w-100'">
|
2024-10-22 19:28:45 +03:00
|
|
|
<v-text-field class="w-100"
|
|
|
|
v-model="login"
|
|
|
|
label="Логин"
|
2024-10-27 09:05:23 +03:00
|
|
|
v-on:keyup.enter="this.registrationAction"
|
|
|
|
:rules="[rules.notNull]"
|
2024-10-22 19:28:45 +03:00
|
|
|
required
|
|
|
|
></v-text-field>
|
|
|
|
<v-text-field class="w-100"
|
|
|
|
v-model="email"
|
|
|
|
label="E-mail"
|
2024-10-27 09:05:23 +03:00
|
|
|
type="email"
|
|
|
|
v-on:keyup.enter="this.registrationAction"
|
|
|
|
:rules="[rules.email]"
|
2024-10-22 19:28:45 +03:00
|
|
|
required
|
|
|
|
></v-text-field>
|
|
|
|
<v-text-field class="w-100"
|
|
|
|
v-model="password"
|
|
|
|
label="Пароль"
|
2024-10-27 09:05:23 +03:00
|
|
|
:type="showPassword ? 'text' : 'password'"
|
|
|
|
:append-icon="showPassword ? 'mdi-eye' : 'mdi-eye-off'"
|
|
|
|
@click:append="showPassword = !showPassword"
|
|
|
|
v-on:keyup.enter="this.registrationAction"
|
|
|
|
:rules="[rules.notNull]"
|
2024-10-22 19:28:45 +03:00
|
|
|
required
|
|
|
|
></v-text-field>
|
|
|
|
<v-text-field class="w-100"
|
|
|
|
v-model="repeatPassword"
|
|
|
|
label="Повторите пароль"
|
2024-10-27 09:05:23 +03:00
|
|
|
:type="showRepeatPassword ? 'text' : 'password'"
|
|
|
|
:append-icon="showRepeatPassword ? 'mdi-eye' : 'mdi-eye-off'"
|
|
|
|
@click:append="showRepeatPassword = !showRepeatPassword"
|
|
|
|
v-on:keyup.enter="this.registrationAction"
|
|
|
|
:rules="[rules.notNull]"
|
2024-10-22 19:28:45 +03:00
|
|
|
required
|
|
|
|
></v-text-field>
|
|
|
|
<v-label :style="errorMessageContainerStyle">{{ errorMessage }}</v-label>
|
2024-10-28 11:36:45 +03:00
|
|
|
<v-btn @click="this.registrationAction" :loading="loading">Регистрация</v-btn>
|
2024-10-22 19:28:45 +03:00
|
|
|
</div>
|
|
|
|
<!-- <v-form v-model="valid" @submit.prevent>-->
|
|
|
|
<!-- -->
|
|
|
|
<!-- </v-form>-->
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
|
|
</style>
|