-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
150 additions
and
30 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
<template> | ||
<div id="app"> | ||
<header> | ||
<h1>PiperChat</h1> | ||
</header> | ||
<main> | ||
<aside class="sidebar"></aside> | ||
<div class="content"></div> | ||
</main> | ||
<div v-if="!userStore.getters.isLoggedIn" class="d-grid gap-2 col-6 mx-auto"> | ||
<FormLogin /> | ||
</div> | ||
<div v-else class="text-center"> | ||
<h2>Welcome, {{ userStore.state.name }}</h2> | ||
<Counter /> | ||
<button class="btn btn-secondary" @click="userStore.logout()"> | ||
Logout | ||
</button> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, onMounted } from 'vue' | ||
import userStore from '@/stores/user' | ||
import FormLogin from '@/components/FormLogin.vue' | ||
export default defineComponent({ | ||
name: 'App', | ||
components: { FormLogin }, | ||
setup() { | ||
onMounted(userStore.getUser) | ||
return { userStore } | ||
} | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<template> | ||
<form @submit.prevent="onSubmit"> | ||
<div class="form-group my-2"> | ||
<label>Username</label> | ||
<input v-model="form.username" class="form-control" placeholder="Username" required /> | ||
</div> | ||
<div class="form-group my-2"> | ||
<label>Password</label> | ||
<input v-model="form.password" class="form-control" type="password" placeholder="Password" required /> | ||
</div> | ||
<div class="text-danger my-2">{{ userStore.state.error }}</div> | ||
<button class="btn btn-success btn-block my-2" type="submit">Login</button> | ||
</form> | ||
</template> | ||
<script lang="ts"> | ||
import { defineComponent, reactive } from 'vue' | ||
import userStore from '@/stores/user' | ||
export default defineComponent({ | ||
setup() { | ||
const form = reactive({ | ||
username: '', | ||
password: '' | ||
}) | ||
const onSubmit = () => { | ||
userStore.login(form.username, form.password) | ||
form.username = '' | ||
form.password = '' | ||
} | ||
return { form, userStore, onSubmit } | ||
} | ||
}) | ||
</script> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { computed, reactive } from 'vue' | ||
import axios from 'axios' | ||
|
||
const state = reactive({ | ||
name: '', | ||
username: '', | ||
|
||
error: '' | ||
}) | ||
|
||
const getters = reactive({ | ||
isLoggedIn: computed(() => state.username !== '') | ||
}) | ||
|
||
const actions = { | ||
async getUser() { | ||
|
||
}, | ||
async login(username: string, password: string) { | ||
|
||
const data = JSON.stringify({ | ||
username: username, | ||
password: password | ||
}) | ||
|
||
const config = { | ||
method: 'post', | ||
maxBodyLength: Infinity, | ||
url: 'http://localhost:3000/auth/login', | ||
headers: { | ||
'Access-Control-Allow-Origin':'*', | ||
'Content-Type': 'application/json', | ||
}, | ||
data: data | ||
} | ||
|
||
axios | ||
.request(config) | ||
.then((response) => { | ||
console.log(JSON.stringify(response.data)) | ||
}) | ||
.catch((error) => { | ||
console.log(error) | ||
}) | ||
} | ||
|
||
|
||
} | ||
|
||
export default { state, getters, ...actions } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters