mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 19:53:21 +02:00
Login page implementation
This commit is contained in:
@@ -1,77 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
// import EditorJS from '@editorjs/editorjs';
|
||||
import { pingApi } from '@/utils/ping';
|
||||
import { onMounted, ref } from 'vue';
|
||||
|
||||
const inputArticleID = ref('')
|
||||
const username = ref('')
|
||||
const password = ref('')
|
||||
|
||||
onMounted(async function() {
|
||||
console.log('ping...')
|
||||
const pong = await pingApi()
|
||||
console.log(pong)
|
||||
})
|
||||
|
||||
function addArticle() {
|
||||
fetch(`http://localhost:8080/articles/${Math.random() * 100}`, {
|
||||
method: "POST",
|
||||
headers: {"Authorization" : `Basic ${btoa(`${username.value}:${password.value}`)}`},
|
||||
body: JSON.stringify({
|
||||
content: {},
|
||||
date: new Date().getTime()
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(result => console.log(result))
|
||||
}
|
||||
|
||||
function deleteArticle(articleID: String) {
|
||||
fetch(`http://localhost:8080/articles/${articleID}`, {
|
||||
method: "DELETE",
|
||||
headers: {"Authorization" : `Basic ${btoa(`${username.value}:${password.value}`)}`},
|
||||
body: JSON.stringify({
|
||||
id_name: articleID
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(result => console.log(result))
|
||||
}
|
||||
|
||||
function getArticle(articleID: String) {
|
||||
fetch(`http://localhost:8080/articles/${articleID}`, {
|
||||
headers: {"Authorization" : `Basic ${btoa(`${username.value}:${password.value}`)}`},
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(result => console.log(result))
|
||||
}
|
||||
|
||||
function auth(type: string, username: string, password: string) {
|
||||
fetch(`http://localhost:8080/${type}`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
email: username,
|
||||
password: password
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(result => console.log(result))
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<p>Salut à tous</p>
|
||||
<button @click="addArticle">add rand article</button>
|
||||
<button @click="getArticle('')">display articles in console</button> <br>
|
||||
<label for="articleIDinput"></label>
|
||||
<input id="articleIDinput" name="articleIDinput" type="text" placeholder="article ID" v-model="inputArticleID">
|
||||
<button @click="deleteArticle(inputArticleID)">delete this article</button>
|
||||
<button @click="getArticle(inputArticleID)">get this article</button> <br>
|
||||
|
||||
<input type="text" name="username" id="username" v-model="username" placeholder="username">
|
||||
<input type="text" name="password" id="password" v-model="password" placeholder="password">
|
||||
<button @click="auth('login', username, password)">login</button>
|
||||
<button @click="auth('logout', username, password)">logout</button>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user