mirror of
https://github.com/robonen/metr.git
synced 2026-03-20 10:54:41 +00:00
+Vue +edited backend
This commit is contained in:
|
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 50 KiB |
8
frontend/src/store/index.js
Normal file
8
frontend/src/store/index.js
Normal file
@@ -0,0 +1,8 @@
|
||||
import { createStore } from 'vuex';
|
||||
import auth from '@/store/modules/auth';
|
||||
|
||||
export default createStore({
|
||||
modules: {
|
||||
auth,
|
||||
},
|
||||
});
|
||||
51
frontend/src/store/modules/auth.js
Normal file
51
frontend/src/store/modules/auth.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import authService from '@/services/auth';
|
||||
|
||||
const savedUser = JSON.parse(localStorage.getItem('auth'));
|
||||
|
||||
export const state = {
|
||||
user: savedUser?.data?.data ?? null,
|
||||
token: savedUser?.data?.token ?? null,
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
async login({ commit }, { email, password }) {
|
||||
const { data: user } = await authService.login(email, password);
|
||||
commit('SET_USER', user.data);
|
||||
commit('SET_TOKEN', user.token);
|
||||
},
|
||||
async logout({ commit }) {
|
||||
await authService.logout();
|
||||
commit('SET_USER', null);
|
||||
commit('SET_TOKEN', null);
|
||||
},
|
||||
};
|
||||
|
||||
export const mutations = {
|
||||
SET_USER(state, user) {
|
||||
state.user = user;
|
||||
},
|
||||
SET_TOKEN(state, token) {
|
||||
state.token = token;
|
||||
},
|
||||
};
|
||||
|
||||
export const getters = {
|
||||
user(state) {
|
||||
return state.user;
|
||||
},
|
||||
username(state) {
|
||||
return state.user && state.user.last_name && state.user.first_name
|
||||
? `${state.user.last_name} ${state.user.first_name}`
|
||||
: null;
|
||||
},
|
||||
userAuthenticated(state) {
|
||||
return state.user !== null && state.token !== null;
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
state,
|
||||
actions,
|
||||
mutations,
|
||||
getters,
|
||||
};
|
||||
@@ -1,40 +1,65 @@
|
||||
<template>
|
||||
<div class="container">
|
||||
<div class="logo">
|
||||
<router-link to="/" class="nav__link" href="#">
|
||||
<div class="logoMetr">
|
||||
</div>
|
||||
</router-link>
|
||||
</div>
|
||||
<div class="title">
|
||||
<h2> {{authForm? "Вход" : "Регистрация" }} Метр</h2>
|
||||
<h2> {{authForm ? "Вход" : "Регистрация" }} Метр</h2>
|
||||
</div>
|
||||
<form action="" method="get" class="form__example">
|
||||
<form class="form__example">
|
||||
<div class="form__example">
|
||||
<label for="name"></label>
|
||||
<input class="login" type="text" name="name" id="name" placeholder="Почта" required>
|
||||
<input class="login" type="email" name="name" id="name" placeholder="Почта" required v-model.trim="credentials.email">
|
||||
</div>
|
||||
<div class="form__example">
|
||||
<label for="email"></label>
|
||||
<input class="login" type="email" name="email" id="email" placeholder="Пароль" required>
|
||||
<input class="login" type="password" name="email" id="email" placeholder="Пароль" required v-model.trim="credentials.password">
|
||||
</div>
|
||||
<div class="form__example">
|
||||
<button class="form__input">
|
||||
{{authForm? "Войти" : "Зарегистрироваться" }}
|
||||
<button class="form__input" @click.prevent="auth">
|
||||
{{ authForm ? "Войти" : "Зарегистрироваться" }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="form__example">
|
||||
<button class="form__input" @click="authForm = false" v-if="authForm">
|
||||
Зарегистрироваться
|
||||
Зарегистрироваться
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mapActions } from "vuex";
|
||||
|
||||
export default {
|
||||
data () {
|
||||
return { authForm: true }
|
||||
return {
|
||||
authForm: true,
|
||||
credentials: {
|
||||
email: '',
|
||||
password: '',
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
login() {
|
||||
this.$store.dispatch('login', this.credentials).then(() => {
|
||||
this.$router.push('/profile');
|
||||
});
|
||||
},
|
||||
registration() {
|
||||
|
||||
},
|
||||
auth() {
|
||||
if (this.authForm)
|
||||
this.login();
|
||||
else
|
||||
this.registration();
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<div class="header__block">
|
||||
<div class="header__block__content">
|
||||
<img src="@/assets/images/location.png" alt="">
|
||||
<a class="nav__link_tomsk" href="#">Томск</a>
|
||||
<a class="nav__link_tomsk" href="#"> Томск</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="header__block">
|
||||
|
||||
@@ -81,7 +81,7 @@
|
||||
<div class="other__images">
|
||||
<a href="#"><img src="../assets/images/offer3.png" alt=""></a>
|
||||
<a href="#"><img src="../assets/images/offer2.png" alt=""></a>
|
||||
<a href="#"><img src="@/assets/images/adv4.png" alt=""></a>
|
||||
<a href="#"><img src="../assets/images/offer4.png" alt=""></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user