formatting

This commit is contained in:
leejinseok
2020-02-06 15:23:49 +09:00
parent 7dfac23726
commit c4a0ce9992
16 changed files with 418 additions and 497 deletions

View File

@@ -1,5 +1,4 @@
import axios from 'axios';
import commonUtil from "../utils/commonUtil";
export default {
getArticles({page = 0, size = 10, q = ''}, authorization) {

View File

@@ -1,10 +1,8 @@
import axios from "axios";
import commonUtil from "../utils/commonUtil";
export default {
login(data) {
const { email, password } = data;
const {email, password} = data;
return axios({
method: 'post',
url: '/api/auth/login',
@@ -24,7 +22,7 @@ export default {
});
},
register(data) {
const { email, name, password } = data;
const {email, name, password} = data;
return axios({
method: 'post',
url: '/api/auth/register',

View File

@@ -1,58 +0,0 @@
<template>
<div class="hello">
<h1>{{ msg }}</h1>
<p>
For a guide and recipes on how to configure / customize this project,<br>
check out the
<a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
</p>
<h3>Installed CLI Plugins</h3>
<ul>
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint" target="_blank" rel="noopener">eslint</a></li>
</ul>
<h3>Essential Links</h3>
<ul>
<li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li>
<li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li>
<li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li>
<li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li>
<li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li>
</ul>
<h3>Ecosystem</h3>
<ul>
<li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
<li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
<li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
<li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
<li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
</ul>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
props: {
msg: String
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
margin: 40px 0 0;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>

View File

@@ -1,20 +0,0 @@
import axios from "axios";
import commonUtil from "../utils/commonUtil";
export default {
async session() {
try {
await axios({
method: 'get',
url: '/api/users',
headers: {
'Authorization': commonUtil.getAuthenticationHeaderBearer(this.$cookie.get('accessToken'))
}
});
} catch (e) {
alert('토큰이 존재하지 않거나 유효하지 않은 토큰입니다.');
await this.$router.replace('/');
}
}
}

View File

@@ -1,7 +1,9 @@
<template>
<div>
<router-link to="/auth/login">로그인</router-link> <br>
<router-link to="/auth/register">회원가입</router-link> <br>
<router-link to="/auth/login">로그인</router-link>
<br/>
<router-link to="/auth/register">회원가입</router-link>
<br/>
</div>
</template>
@@ -16,14 +18,13 @@
async created() {
try {
await authApi.session();
await this.$router.replace('/articles');
await this.$router.replace("/articles");
} catch (e) {
console.log(e);
}
}
}
};
</script>
<style scoped>
</style>

View File

@@ -1,16 +1,18 @@
<template>
<div>
<div></div>
<div>
title :
<span>{{ article.title }}</span>
</div>
<div>
title : <span>{{ article.title }}</span>
</div>
<div>
content: <p>{{ article.content }}</p>
content:
<p>{{ article.content }}</p>
</div>
<div v-if="init">
createdAt: <span>{{ article.createdAt }}</span>
createdAt:
<span>{{ article.createdAt }}</span>
</div>
<div v-if="article.isOwn">
@@ -30,11 +32,13 @@
return {
article: {},
init: false,
test: ''
}
test: ""
};
},
async beforeCreate() {
authService.banishIfUserUnAuthenticated = authService.banishIfUserUnAuthenticated.bind(this);
authService.banishIfUserUnAuthenticated = authService.banishIfUserUnAuthenticated.bind(
this
);
articleService.getArticle = articleService.getArticle.bind(this);
articleService.removeArticle = articleService.removeArticle.bind(this);
},
@@ -45,14 +49,13 @@
methods: {
async remove() {
const articleId = this.$route.params.id;
if(!confirm('정말 삭제하시겠습니까?')) return;
if (!confirm("정말 삭제하시겠습니까?")) return;
await articleService.removeArticle(articleId);
},
}
}
};
</script>
<style scoped>
</style>

View File

@@ -7,7 +7,7 @@
<span @click="clickUser">{{ article.user.name }}</span>
</article>
<br>
<br/>
<div>
<router-link to="/articles/write">글쓰기</router-link>
@@ -33,12 +33,14 @@
return {
articles: [],
pending: true
}
};
},
async beforeCreate() {
articleService.getArticles = articleService.getArticles.bind(this);
authService.logout = authService.logout.bind(this);
authService.banishIfUserUnAuthenticated = authService.banishIfUserUnAuthenticated.bind(this);
authService.banishIfUserUnAuthenticated = authService.banishIfUserUnAuthenticated.bind(
this
);
},
async created() {
await authService.banishIfUserUnAuthenticated();
@@ -47,16 +49,15 @@
},
methods: {
async logout() {
if (!confirm('정말 로그아웃 하시겠습니까?')) return;
if (!confirm("정말 로그아웃 하시겠습니까?")) return;
await authService.logout();
},
clickUser(evt) {
console.log(evt.target);
}
}
}
};
</script>
<style scoped>
</style>

View File

@@ -3,7 +3,7 @@
<form @submit="isEdit ? update($event) : create($event)">
<div class="row">
<label for="title">Title</label>
<input type="text" id="title" v-model="title">
<input type="text" id="title" v-model="title"/>
</div>
<div class="row">
<label for="content">Content</label>
@@ -24,24 +24,27 @@
name: "Write",
data() {
return {
title: '',
content: '',
title: "",
content: "",
isEdit: false
}
};
},
async beforeCreate() {
authService.banishIfUserUnAuthenticated = authService.banishIfUserUnAuthenticated.bind(this);
authService.banishIfUserUnAuthenticated = authService.banishIfUserUnAuthenticated.bind(
this
);
articleService.postArticle = articleService.postArticle.bind(this);
articleService.updateArticle = articleService.updateArticle.bind(this);
articleService.getArticle = articleService.getArticle.bind(this);
articleService.doseSessionHasPermission = articleService.doseSessionHasPermission.bind(this);
articleService.doseSessionHasPermission = articleService.doseSessionHasPermission.bind(
this
);
},
async created() {
const id = this.$route.query.id;
if (id) {
await authService.banishIfUserUnAuthenticated();
const { title, content, user } = await articleService.getArticle(id);
const {title, content, user} = await articleService.getArticle(id);
await articleService.doseSessionHasPermission(user);
this.title = title;
@@ -58,10 +61,13 @@
async update(evt) {
evt.preventDefault();
const {title, content} = this;
await articleService.updateArticle(this.$route.query.id, {title, content});
}
await articleService.updateArticle(this.$route.query.id, {
title,
content
});
}
}
};
</script>
<style scoped>

View File

@@ -2,8 +2,8 @@
<div>
<router-link to="/">home</router-link>
<form @submit="submit">
<input type="email" v-model="email">
<input type="password" v-model="password">
<input type="email" v-model="email"/>
<input type="password" v-model="password"/>
<button type="submit">확인</button>
</form>
</div>
@@ -17,9 +17,9 @@
name: "Login",
data() {
return {
email: '',
password: ''
}
email: "",
password: ""
};
},
beforeCreate() {
authApi.session = authApi.session.bind(this);
@@ -28,21 +28,20 @@
async created() {
try {
await authApi.session();
await this.$router.replace('/articles');
await this.$router.replace("/articles");
} catch (e) {
console.log(e);
}
},
methods: {
submit: async function(evt) {
submit: async function (evt) {
evt.preventDefault();
const { email, password } = this;
await authService.login(email,password);
},
const {email, password} = this;
await authService.login(email, password);
}
}
};
</script>
<style scoped>
</style>

View File

@@ -1,9 +1,9 @@
<template>
<div>
<form @submit="register">
<input type="email" v-model="email" placeholder="Email">
<input type="text" v-model="name" placeholder="Name">
<input type="password" v-model="password" placeholder="Password">
<input type="email" v-model="email" placeholder="Email"/>
<input type="text" v-model="name" placeholder="Name"/>
<input type="password" v-model="password" placeholder="Password"/>
<button type="submit">확인</button>
</form>
</div>
@@ -17,10 +17,10 @@
name: "Register",
data() {
return {
email: '',
name: '',
password: ''
}
email: "",
name: "",
password: ""
};
},
beforeCreate() {
authApi.register = authApi.register.bind(this);
@@ -37,23 +37,14 @@
}
},
methods: {
register: async function(evt) {
register: async function (evt) {
evt.preventDefault();
const { email, name, password } = this;
const {email, name, password} = this;
await authService.register({email, name, password});
// try {
// await authApi.register({email, name, password});
// } catch (err) {
// if (err.response.status === 409) {
// alert('이미 존재하는 이메일입니다.');
// }
// }
}
}
}
};
</script>
<style scoped>
</style>

View File

@@ -28,21 +28,20 @@
return {
user: null,
init: false
}
};
},
async beforeCreate() {
authApi.bind(this);
try {
const { data } = await authApi.session();
const {data} = await authApi.session();
this.user = data;
} catch (err) {
await this.$router.replace('/auth/login');
}
await this.$router.replace("/auth/login");
}
}
};
</script>
<style scoped>
</style>

View File

@@ -5,7 +5,10 @@ import authApi from "../api/authApi";
export default {
async getArticles({page = 0, size = 10}) {
try {
const result = await articleApi.getArticles({page, size}, commonUtil.getAuthenticationHeaderBearer(this.$cookie.get('accessToken')));
const result = await articleApi.getArticles({
page,
size
}, commonUtil.getAuthenticationHeaderBearer(this.$cookie.get('accessToken')));
return result.data;
} catch (err) {
alert('문제가 발생하였습니다.');

View File

@@ -5,7 +5,7 @@ export default {
async login(email, password) {
try {
const result = await authApi.login({email, password});
const { token } = result.data;
const {token} = result.data;
this.$cookie.set('accessToken', token, 1000);
await this.$router.push('/articles');
} catch (err) {

View File

@@ -1,4 +1,3 @@
export default {
getAuthenticationHeaderBearer(accessToken) {
return 'Bearer ' + accessToken;