page for list of rooms

This commit is contained in:
2026-03-19 00:32:48 +00:00
parent 00d9d4023c
commit 8677176706
7 changed files with 83 additions and 11 deletions

View File

@@ -13,12 +13,16 @@ app.use(e.json());
app.use(bodyParser.json()); app.use(bodyParser.json());
app.get('/', (req, res) => { app.get('/', (req, res) => {
res.send("Hello World"); res.send("Nothing Here");
}); });
app.get('/currentRooms', (req, res) => { app.get('/currentRooms', (req, res) => {
// req has no data // req has no data
// res has all room at current time // res has all room at current time
let stmt = db.prepare(`SELECT * FROM TimeSlots`);
let records = stmt.all();
res.status(200).json({records: records});
console.log("currentRooms");
}); });
app.get('/addTimeslot', (req, res) => { app.get('/addTimeslot', (req, res) => {
@@ -50,6 +54,7 @@ app.post('/createUser', async (req, res) => {
stmt = db.prepare(`INSERT INTO Users (Email, Pass, Username, Submissions) VALUES ('${body.email}', '${generatedHash}', '${body.name}', 0)`); stmt = db.prepare(`INSERT INTO Users (Email, Pass, Username, Submissions) VALUES ('${body.email}', '${generatedHash}', '${body.name}', 0)`);
stmt.run(); stmt.run();
res.status(200).send("account created"); res.status(200).send("account created");
console.log("sign up");
}); });
app.post('/login', async (req, res) => { app.post('/login', async (req, res) => {
@@ -64,6 +69,7 @@ app.post('/login', async (req, res) => {
} }
if (await bcrypt.compare(body.pass, storedHash.Pass)){ if (await bcrypt.compare(body.pass, storedHash.Pass)){
res.send(200); res.send(200);
console.log("login");
} else { } else {
res.status(400).send("incorrect password"); res.status(400).send("incorrect password");
} }

View File

@@ -8,7 +8,8 @@
"name": "frontend", "name": "frontend",
"version": "0.0.0", "version": "0.0.0",
"dependencies": { "dependencies": {
"vue": "^3.5.30" "vue": "^3.5.30",
"vue-cookies": "^1.8.6"
}, },
"devDependencies": { "devDependencies": {
"@types/bcrypt": "^6.0.0", "@types/bcrypt": "^6.0.0",
@@ -1243,6 +1244,12 @@
} }
} }
}, },
"node_modules/vue-cookies": {
"version": "1.8.6",
"resolved": "https://registry.npmjs.org/vue-cookies/-/vue-cookies-1.8.6.tgz",
"integrity": "sha512-e2kYaHj1Y/zVsBSM3KWlOoVJ5o3l4QZjytNU7xdCgmkw3521CMUerqHekBGZKXXC1oRxYljBeeOK2SCel6cKuw==",
"license": "MIT"
},
"node_modules/vue-tsc": { "node_modules/vue-tsc": {
"version": "3.2.6", "version": "3.2.6",
"resolved": "https://registry.npmjs.org/vue-tsc/-/vue-tsc-3.2.6.tgz", "resolved": "https://registry.npmjs.org/vue-tsc/-/vue-tsc-3.2.6.tgz",

View File

@@ -9,7 +9,8 @@
"preview": "vite preview" "preview": "vite preview"
}, },
"dependencies": { "dependencies": {
"vue": "^3.5.30" "vue": "^3.5.30",
"vue-cookies": "^1.8.6"
}, },
"devDependencies": { "devDependencies": {
"@types/bcrypt": "^6.0.0", "@types/bcrypt": "^6.0.0",

View File

@@ -1,7 +1,19 @@
<script setup lang="ts"> <script setup lang="ts">
import { onBeforeMount, ref } from 'vue';
import Login from './components/Login.vue'; import Login from './components/Login.vue';
import HomePage from './components/HomePage.vue';
const page = ref<number>(0);
onBeforeMount(async () => {
const loggedIn = await cookieStore.get("loggedIn");
if (loggedIn?.value == "true") {
page.value = 1;
}
})
</script> </script>
<template> <template>
<Login /> <Login v-if="page == 0" @next-page="page++"/>
<HomePage v-if="page == 1" @add-slot="page++"/>
</template> </template>

View File

@@ -0,0 +1,27 @@
<script setup lang="ts">
import { onBeforeMount, ref } from 'vue';
const rooms = ref();
defineEmits(['addSlot']);
onBeforeMount(async () => {
const res = await fetch("http://localhost:3000/currentRooms", {
method: "GET",
headers: new Headers({'content-type': 'application/json'})
});
rooms.value = await res.json();
});
</script>
<template>
<header>
<h1>What's free in my free?</h1>
<button @click="$emit('addSlot')">Add new slot</button>
</header>
<article>
<h2>Free Rooms:</h2>
<p v-if="rooms.records.length == 0">No free rooms right now</p>
<ul v-for="(slot, index) in rooms.records">
<li :id="index">{{ slot }}</li>
</ul>
</article>
</template>

View File

@@ -3,23 +3,40 @@ import { ref } from 'vue';
const email = ref<string>(""); const email = ref<string>("");
const pass = ref<string>(""); const pass = ref<string>("");
const text = ref<string>("");
function login(e: SubmitEvent) { const emit = defineEmits(['nextPage']);
async function login(e: SubmitEvent) {
text.value = "";
e.preventDefault(); e.preventDefault();
fetch("http://localhost:3000/login", { const res = await fetch("http://localhost:3000/login", {
method: "POST", method: "POST",
body: JSON.stringify({ email: email.value, pass: pass.value }), body: JSON.stringify({ email: email.value, pass: pass.value }),
headers: new Headers({'content-type': 'application/json'}) headers: new Headers({'content-type': 'application/json'})
}); });
if (res.ok) {
cookieStore.set("loggedIn", "true");
emit('nextPage');
} else {
text.value = await res.text();
}
} }
function signup(e: Event) { async function signup(e: Event) {
text.value = "";
e.preventDefault(); e.preventDefault();
fetch("http://localhost:3000/createUser", { const res = await fetch("http://localhost:3000/createUser", {
method: "POST", method: "POST",
body: JSON.stringify({ email: email.value, pass: pass.value, name: email.value.split("@")[0] }), body: JSON.stringify({ email: email.value, pass: pass.value, name: email.value.split("@")[0] }),
headers: new Headers({'content-type': 'application/json'}) headers: new Headers({'content-type': 'application/json'})
}); });
if (res.ok) {
cookieStore.set("loggedIn", "true");
emit('nextPage');
} else {
text.value = await res.text();
}
} }
</script> </script>
@@ -32,5 +49,6 @@ function signup(e: Event) {
<input type="password" id="pass" v-model="pass"/> <br> <input type="password" id="pass" v-model="pass"/> <br>
<button type="submit">Sign in</button> <br> <button type="submit">Sign in</button> <br>
<button type="button" @click="signup">Sign up</button> <button type="button" @click="signup">Sign up</button>
<p>{{ text }}</p>
</form> </form>
</template> </template>

View File

@@ -1,5 +1,6 @@
import { createApp } from 'vue' import { createApp } from 'vue';
// import './style.css' // import './style.css'
import App from './App.vue' import App from './App.vue';
import VueCookies from 'vue-cookies';
createApp(App).mount('#app') createApp(App).use(VueCookies).mount('#app');