feat(owner-vue): 점주용 로그인 - 화면, 헤더 설정
- 이메일, 패스워드 유효성 검사 - 로그인 성공 시 default header 설정
This commit is contained in:
@@ -1,8 +1,30 @@
|
|||||||
import axios from "axios";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
requestRegisterUser(user) {
|
||||||
|
return axios.post("http://localhost:8001/user-service/store-owner", user);
|
||||||
|
},
|
||||||
|
|
||||||
requestRegisterUser(user) {
|
async requestLoginUser(email, password) {
|
||||||
return axios.post("http://localhost:8001/user-service/store-owner", user);
|
const user = {
|
||||||
|
email: email,
|
||||||
|
password: password
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
try {
|
||||||
|
const response = await axios.post("http://localhost:8001/user-service/login", user);
|
||||||
|
console.log(response);
|
||||||
|
const AUTH_TOKEN = response.data.data.access_token;
|
||||||
|
localStorage.setItem('access_token', AUTH_TOKEN);
|
||||||
|
axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (err) {
|
||||||
|
console.log("Error = ", err);
|
||||||
|
alert("로그인 실패!");
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
import axios from "axios";
|
||||||
|
|||||||
61
owner-vue/src/views/LoginUser.vue
Normal file
61
owner-vue/src/views/LoginUser.vue
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<template>
|
||||||
|
<v-card width="800" class="mx-auto mt-5">
|
||||||
|
<v-card-title>
|
||||||
|
<h1>Login</h1>
|
||||||
|
</v-card-title>
|
||||||
|
<v-card-text>
|
||||||
|
<v-form ref="form" lazy-validation>
|
||||||
|
<v-text-field
|
||||||
|
v-model="email"
|
||||||
|
:rules="[v => /.+@.+\..+/.test(v) || 'E-mail must be valid', v => !!v || '이메일은 필수 값입니다']"
|
||||||
|
label="이메일"
|
||||||
|
prepend-icon="mdi-account-circle"
|
||||||
|
></v-text-field>
|
||||||
|
<v-text-field
|
||||||
|
v-model="password"
|
||||||
|
:rules="[v => !!v || '비밀번호는 필수 값입니다']"
|
||||||
|
label="비밀번호"
|
||||||
|
type="Password"
|
||||||
|
prepend-icon="mdi-lock"
|
||||||
|
append-icon="mdi-eye-off"
|
||||||
|
></v-text-field>
|
||||||
|
</v-form>
|
||||||
|
</v-card-text>
|
||||||
|
<v-divider></v-divider>
|
||||||
|
<v-card-actions>
|
||||||
|
<v-btn color="success" v-on:click="links('/register')">Register</v-btn>
|
||||||
|
<v-spacer></v-spacer>
|
||||||
|
<v-btn color="info" v-on:click="login">Login</v-btn>
|
||||||
|
</v-card-actions>
|
||||||
|
</v-card>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import userApi from '../api/user.js'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "LoginUser",
|
||||||
|
data: function() {
|
||||||
|
return {
|
||||||
|
email: 'owner@gmail.com',
|
||||||
|
password: '1234'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
links: function(url) {
|
||||||
|
this.$router.push(url);
|
||||||
|
},
|
||||||
|
login: async function() {
|
||||||
|
if (!this.$refs.form.validate()) return;
|
||||||
|
|
||||||
|
const flag = await userApi.requestLoginUser(this.email, this.password);
|
||||||
|
|
||||||
|
if (flag) await this.$router.push('/prev-order');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user