remove user
This commit is contained in:
@@ -5,19 +5,14 @@ const httpPort = 4080;
|
||||
|
||||
const app = express();
|
||||
|
||||
// app.set('views', 'views');
|
||||
// app.set('view engine', 'hbs');
|
||||
|
||||
// import morgan from 'morgan'
|
||||
// app.use(morgan('dev'));
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: false }));
|
||||
app.use(express.static('public'));
|
||||
|
||||
import mainRouter from './routes/main';
|
||||
import apiRouter from './routes/api/apiRouter';
|
||||
|
||||
app.use('/', mainRouter);
|
||||
app.use('/api', apiRouter);
|
||||
|
||||
app.listen(httpPort, () => {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { type Request, type Response } from "express";
|
||||
import UserModel, { values } from '../models/userModel';
|
||||
import MediaModel, { Table, Media } from '../models/mediaModel';
|
||||
import mediaModel from "../models/mediaModel";
|
||||
|
||||
interface omdbRes {
|
||||
Title: string,
|
||||
@@ -13,7 +12,14 @@ interface omdbRes {
|
||||
Year: string,
|
||||
}
|
||||
|
||||
function fromStringToTable(value: string): (Table | undefined) {
|
||||
function fromStringToTable(input: string | string[]): (Table | undefined) {
|
||||
var value = "";
|
||||
if (Array.isArray(input)) {
|
||||
value = input[0];
|
||||
}
|
||||
else {
|
||||
value = input;
|
||||
}
|
||||
if (value.localeCompare("games") == 0) return Table.games;
|
||||
if (value.localeCompare("movies") == 0) return Table.movies;
|
||||
if (value.localeCompare("series") == 0) return Table.series;
|
||||
@@ -218,22 +224,22 @@ async function checkImages() {
|
||||
await checkTableImages(Table.movies);
|
||||
await checkTableImages(Table.series);
|
||||
}
|
||||
function delay(time:number) {
|
||||
|
||||
function delay(time: number) {
|
||||
return new Promise(resolve => setTimeout(resolve, time));
|
||||
}
|
||||
}
|
||||
|
||||
async function checkTableImages(table: Table) {
|
||||
const list = mediaModel.find(table);
|
||||
const list = MediaModel.find(table);
|
||||
|
||||
for (const element of list) {
|
||||
|
||||
const path = "./public/" + element.webImg;
|
||||
const f = Bun.file(path);
|
||||
const exists = await f.exists();
|
||||
if (!exists){
|
||||
if (!exists) {
|
||||
console.log(element.title);
|
||||
await downloadImage(element, table);
|
||||
await delay(1000);
|
||||
await delay(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
import { type Request, type Response } from "express";
|
||||
import UserModel, { values } from '../models/userModel';
|
||||
|
||||
export default {
|
||||
|
||||
render: function (req: Request, res: Response) {
|
||||
res.render('user', { keys: UserModel.namesOfValues });
|
||||
},
|
||||
|
||||
create: function (req: Request, res: Response) {
|
||||
|
||||
const reqPassword: string = req.body.reqPassword;
|
||||
if (!reqPassword) return res.render('user', { keys: UserModel.namesOfValues });
|
||||
|
||||
const password = UserModel.getValue(values.pass);
|
||||
|
||||
// if no password in db save reqPassword
|
||||
if (!password) {
|
||||
const affectedRows = UserModel.updateValue("pass", reqPassword);
|
||||
if (affectedRows > 0) {
|
||||
return res.redirect('/list');
|
||||
}
|
||||
return res.render('user', { keys: UserModel.namesOfValues });
|
||||
}
|
||||
// check if passwords equal
|
||||
if (password != reqPassword) {
|
||||
return res.render('user', { keys: UserModel.namesOfValues });
|
||||
}
|
||||
|
||||
// update
|
||||
const name: string = req.body.name;
|
||||
const value: string = req.body.value;
|
||||
|
||||
if (!name || !value) {
|
||||
return res.render('user', { keys: UserModel.namesOfValues });
|
||||
}
|
||||
|
||||
const affectedRows = UserModel.updateValue(name, value);
|
||||
if (affectedRows == 0) {
|
||||
return res.render('user', { keys: UserModel.namesOfValues });
|
||||
}
|
||||
|
||||
return res.redirect('/list');
|
||||
},
|
||||
|
||||
get: function (req: Request, res: Response) {
|
||||
const usersFound = UserModel.getAll();
|
||||
return res.status(200).json(usersFound);
|
||||
},
|
||||
};
|
||||
@@ -1,10 +0,0 @@
|
||||
import express, { type Request, type Response } from "express";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
|
||||
|
||||
//import userRouter from './user';
|
||||
//router.use('/user', userRouter);
|
||||
|
||||
export default router;
|
||||
@@ -1,14 +0,0 @@
|
||||
import express from "express";
|
||||
import userController from 'backend/controllers/userController';
|
||||
import checkAuthenticated from 'backend/miscellaneous/checkAuthenticated';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
/* GET home page. */
|
||||
router.get('/', userController.render);
|
||||
|
||||
router.post('/', userController.create);
|
||||
|
||||
router.put('/', checkAuthenticated, userController.get);
|
||||
|
||||
export default router;
|
||||
@@ -1,69 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en" data-bs-theme="dark">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="shortcut icon" href="/images/logo.ico" type="image/x-icon">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"
|
||||
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"
|
||||
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
|
||||
crossorigin="anonymous"></script>
|
||||
|
||||
<title>User</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
<form action="/user" method="post">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Name</label>
|
||||
<select name="name" class="form-select">
|
||||
{{#each keys}}
|
||||
<option value="{{this}}">{{this}}</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Value</label>
|
||||
<input type="text" class="form-control" name="value">
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Password</label>
|
||||
<input type="password" class="form-control" name="reqPassword" id="password">
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Add</button>
|
||||
</form>
|
||||
<br>
|
||||
<div class="btn btn-primary" id="get" onclick="getUser()"> Get</div>
|
||||
<br>
|
||||
<div id="text"></div>
|
||||
|
||||
<script>
|
||||
|
||||
async function getUser() {
|
||||
const password = document.getElementById('password').value;
|
||||
const response = await fetch('/user', {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ "pass": password }),
|
||||
})
|
||||
const data = await response.json();
|
||||
document.getElementById('text').textContent = JSON.stringify(data, null, 2);
|
||||
}
|
||||
|
||||
</script>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user