mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2025-04-04 19:10:56 -04:00
trying stuff out
This commit is contained in:
parent
245597c494
commit
4be0ea5870
9 changed files with 50 additions and 37 deletions
|
@ -4,13 +4,15 @@
|
|||
"": {
|
||||
"name": "KeyNotes.App",
|
||||
"dependencies": {
|
||||
"connect-sqlite3": "^0.9.15",
|
||||
"ejs": "^3.1.10",
|
||||
"express": "^4.21.2",
|
||||
"express-session": "^1.18.1",
|
||||
"express-validator": "^7.2.1",
|
||||
"passport": "^0.7.0",
|
||||
"passport-local": "^1.0.0",
|
||||
"KeyNotes.App": ".",
|
||||
"bcryptjs": "latest",
|
||||
"connect-sqlite3": "latest",
|
||||
"ejs": "latest",
|
||||
"express": "latest",
|
||||
"express-session": "latest",
|
||||
"express-validator": "latest",
|
||||
"passport": "latest",
|
||||
"passport-local": "latest",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -23,6 +25,8 @@
|
|||
|
||||
"@tootallnate/once": ["@tootallnate/once@1.1.2", "", {}, "sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw=="],
|
||||
|
||||
"KeyNotes.App": ["KeyNotes.App@file:", { "dependencies": { "KeyNotes.App": ".", "bcryptjs": "^3.0.2", "connect-sqlite3": "^0.9.15", "ejs": "^3.1.10", "express": "^4.21.2", "express-session": "^1.18.1", "express-validator": "^7.2.1", "passport": "^0.7.0", "passport-local": "^1.0.0" } }],
|
||||
|
||||
"abbrev": ["abbrev@1.1.1", "", {}, "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q=="],
|
||||
|
||||
"accepts": ["accepts@1.3.8", "", { "dependencies": { "mime-types": "~2.1.34", "negotiator": "0.6.3" } }, "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw=="],
|
||||
|
@ -49,6 +53,8 @@
|
|||
|
||||
"base64-js": ["base64-js@1.5.1", "", {}, "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA=="],
|
||||
|
||||
"bcryptjs": ["bcryptjs@3.0.2", "", { "bin": { "bcrypt": "bin/bcrypt" } }, "sha512-k38b3XOZKv60C4E2hVsXTolJWfkGRMbILBIe2IBITXciy5bOsTKot5kDrf3ZfufQtQOUN5mXceUEpU1rTl9Uog=="],
|
||||
|
||||
"bindings": ["bindings@1.5.0", "", { "dependencies": { "file-uri-to-path": "1.0.0" } }, "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ=="],
|
||||
|
||||
"bl": ["bl@4.1.0", "", { "dependencies": { "buffer": "^5.5.0", "inherits": "^2.0.4", "readable-stream": "^3.4.0" } }, "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w=="],
|
||||
|
@ -421,6 +427,8 @@
|
|||
|
||||
"yallist": ["yallist@4.0.0", "", {}, "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="],
|
||||
|
||||
"KeyNotes.App/KeyNotes.App": ["KeyNotes.App@file:.", {}],
|
||||
|
||||
"agent-base/debug": ["debug@4.4.0", "", { "dependencies": { "ms": "^2.1.3" } }, "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA=="],
|
||||
|
||||
"cacache/minipass": ["minipass@3.3.6", "", { "dependencies": { "yallist": "^4.0.0" } }, "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw=="],
|
||||
|
|
5
messages/cookies.txt
Normal file
5
messages/cookies.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Netscape HTTP Cookie File
|
||||
# https://curl.se/docs/http-cookies.html
|
||||
# This file was generated by libcurl! Edit at your own risk.
|
||||
|
||||
#HttpOnly_localhost FALSE / FALSE 1743975320 connect.sid s%3Af8SoTtWAPvSfsvf-HvFZAE8ZZlwI2QDl.57i%2FjcW237eV8Q3d8Q3PrNJzpoC0I%2BQ6K%2BNacTtOqJI
|
|
@ -2,6 +2,8 @@
|
|||
"name": "KeyNotes.App",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"KeyNotes.App": ".",
|
||||
"bcryptjs": "^3.0.2",
|
||||
"connect-sqlite3": "^0.9.15",
|
||||
"ejs": "^3.1.10",
|
||||
"express": "^4.21.2",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
function usernameValidation(username) {
|
||||
const errors = [];
|
||||
if (username.length < 5) {
|
||||
errors.push("*username must be at least 8 characters");
|
||||
errors.push("*username must be at least 5 characters");
|
||||
}
|
||||
|
||||
if (username.includes(" ")) {
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
const fs = require("node:fs");
|
||||
const { logging } = require("./middlewares/logging");
|
||||
const path = require("node:path");
|
||||
const express = require("express");
|
||||
const passport = require("passport");
|
||||
const passport = require("./middlewares/auth");
|
||||
const session = require("express-session");
|
||||
const SQLiteStore = require("connect-sqlite3")(session);
|
||||
|
||||
|
@ -17,25 +16,24 @@ app.use(express.static(assetsPath));
|
|||
|
||||
app.set("views", path.join(__dirname, "views"));
|
||||
app.set("view engine", "ejs");
|
||||
|
||||
app.use(
|
||||
session({
|
||||
store: new SQLiteStore({ dir: "./src/db/", db: "keynotes.db" }),
|
||||
secret: "keynotes.app",
|
||||
cookie: { maxAge: 7 * 24 * 60 * 60 * 1000 },
|
||||
secret: "keynotes",
|
||||
cookie: { maxAge: 7 * 24 * 60 * 60 * 1000, sameSite: "strict" },
|
||||
saveUninitialized: false,
|
||||
resave: false,
|
||||
}),
|
||||
);
|
||||
|
||||
app.use(passport.session());
|
||||
// app.use(passport.session());
|
||||
app.use(passport.authenticate("session"));
|
||||
app.use(express.urlencoded({ extended: false }));
|
||||
app.use(logging);
|
||||
app.use((req, res, next) => {
|
||||
res.locals.currentUser = req.user;
|
||||
next();
|
||||
});
|
||||
|
||||
app.use("/", indexRouter);
|
||||
app.use("/auth", authRouter);
|
||||
|
||||
|
|
|
@ -3,6 +3,11 @@ const db = require("../models/query");
|
|||
const { validationResult } = require("express-validator");
|
||||
|
||||
function loginGet(req, res, next) {
|
||||
console.log(req.user, req.session.cookie);
|
||||
console.table(req.session);
|
||||
if (!req.user && req.session.id) {
|
||||
req.session.id = null;
|
||||
}
|
||||
res.render("login", {
|
||||
pageTitle: "InspiredCliches | Login",
|
||||
errors: req.session.messages,
|
||||
|
@ -10,6 +15,7 @@ function loginGet(req, res, next) {
|
|||
}
|
||||
|
||||
function logOut(req, res, next) {
|
||||
res.clearCookie("connect.sid", { path: "/" });
|
||||
req.logout((err) => {
|
||||
if (err) return next(err);
|
||||
});
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
const db = require("../models/query");
|
||||
|
||||
function indexGet(req, res, next) {
|
||||
function indexGet(req, res) {
|
||||
if (res.locals.currentUser) {
|
||||
const keynotes = db.getEveryNote();
|
||||
const userLikedPosts = db.getLikesByUser(res.locals.currentUser.user_id);
|
||||
|
||||
res.render("feed", {
|
||||
return res.render("feed", {
|
||||
pageTitle: "InspiredCliches | Feed",
|
||||
keynotes: keynotes,
|
||||
userLikedPosts: userLikedPosts,
|
||||
|
@ -14,7 +14,7 @@ function indexGet(req, res, next) {
|
|||
res.render("home", { pageTitle: "InspiredCliches" });
|
||||
}
|
||||
|
||||
function addLike(req, res, next) {
|
||||
function addLike(req, res) {
|
||||
const { noteId } = req.query;
|
||||
|
||||
const noteExits = noteId ? db.getNoteById(noteId) : null;
|
||||
|
@ -30,15 +30,14 @@ function addLike(req, res, next) {
|
|||
res.redirect("/");
|
||||
}
|
||||
|
||||
function addNotePost(req, res, next) {
|
||||
function addNotePost(req, res) {
|
||||
const { message, media } = req.body;
|
||||
console.log("add note post");
|
||||
|
||||
if (res.locals.currentUser) {
|
||||
const userId = res.locals.currentUser.user_id;
|
||||
|
||||
db.putNewNote({ message: message, media: null, userId: userId });
|
||||
}
|
||||
|
||||
res.redirect("/");
|
||||
}
|
||||
|
||||
|
@ -55,11 +54,14 @@ function deleteNote(req, res) {
|
|||
}
|
||||
}
|
||||
|
||||
function addNoteGet(req, res, next) {
|
||||
res.render("note-form", { pageTitle: "InspiredCliches | New Note" });
|
||||
function addNoteGet(req, res) {
|
||||
if (res.locals.currentUser)
|
||||
return res.render("note-form", { pageTitle: "InspiredCliches | New Note" });
|
||||
|
||||
res.redirect("/");
|
||||
}
|
||||
|
||||
function getProfile(req, res, next) {
|
||||
function getProfile(req, res) {
|
||||
const { userId } = req.query;
|
||||
|
||||
const userExists = userId ? db.getUserById(userId) : null;
|
||||
|
|
|
@ -1,24 +1,15 @@
|
|||
const { Database } = require("bun:sqlite");
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
const { mkdir } = require("node:fs/promises");
|
||||
const { stat } = require("node:fs");
|
||||
|
||||
const dbDirPath = path.join(path.dirname(__dirname), "/db");
|
||||
const dbDirPath = path.join(path.dirname(__dirname), "db");
|
||||
const dbPath = path.join(dbDirPath, "/keynotes.db");
|
||||
|
||||
async function makeDirectory(path) {
|
||||
const dirCreation = await mkdir(path);
|
||||
return dirCreation;
|
||||
if (!fs.existsSync(dbDirPath)) {
|
||||
fs.mkdirSync(dbDirPath);
|
||||
console.log(`Created DB Directory at ${dbDirPath}`);
|
||||
}
|
||||
|
||||
// Make sure DB path exists
|
||||
stat(dbDirPath, (err, stats) => {
|
||||
if (err !== null) {
|
||||
makeDirectory(dbDirPath);
|
||||
}
|
||||
});
|
||||
|
||||
const db = new Database(dbPath);
|
||||
// Enable WAL Mode
|
||||
db.exec("PRAGMA journal_mode = WAL;");
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const db = require("./db");
|
||||
console.log(`${db.filename} test`);
|
||||
|
||||
function getEveryNote() {
|
||||
try {
|
||||
|
|
Loading…
Add table
Reference in a new issue