register blah

This commit is contained in:
newtbot
2024-01-19 16:04:50 +08:00
parent 8dd917e541
commit e63bcf1734
9 changed files with 417 additions and 160 deletions

View File

@ -51,6 +51,11 @@ router.get('/news', function(req, res, next) {
res.render('news');
});
//login / register page
router.get('/login', function(req, res, next) {
res.render('signuplogin');
});
//404 page
router.get('*', function(req, res, next) {
res.render('404');

View File

@ -18,8 +18,9 @@ router.get("/", async (req, res, next) => {
// /user/register
router.post("/register", async (req, res, next) => {
try {
//await addUser(req.body);
res.sendStatus(200);
console.log("this is " , req.body);
await addUser(req.body);
res.status(200).json({ register: true });
} catch (error) {
console.error(error);
next(error);
@ -33,3 +34,48 @@ router.post("/register", async (req, res, next) => {
//getbyid
module.exports = router;
/*
curl localhost/api/v0/user/register -H "Content-Type: application/json" -X POST -d '{"username":
"testuser123", "password": "thisisthesystemuserpasswordnoob", "email": "testuser123@ecosaver.com", "address":
"Nanyang Polytechnic 180 Ang Mo Kio Avenue 8 Singapore 569830", "phone": "12345678"}'
'use strict';
const router = require('express').Router();
const {User} = require('../models/user');
router.get('/', async function(req, res, next){
try{
return res.json({
results: await User[req.query.detail ? "listDetail" : "list"]()
});
}catch(error){
next(error);
}
});
router.get('/me', async function(req, res, next){
try{
return res.json(await User.get({uid: req.user.uid}));
}catch(error){
next(error);
}
});
router.get('/:uid', async function(req, res, next){
try{
return res.json({
results: await User.get(req.params.uid),
});
}catch(error){
next(error);
}
});
module.exports = router;
*/