var express = require('express')
var router = express.Router()
var settings = require('../../settings')
router.get('/', async function(req, res, next) {
settings.dLogo = 'ទំព័រអ្នកប្រើប្រាស់'
if(req.session.user){
const today = new Date()
const date = today.toLocaleDateString('fr-CA')
const time = today.toLocaleTimeString('it-IT')
settings.datetime = date + 'T' + time
const count = await require('../../controllers/users/count')()
settings.message = `ចំនួនអ្នកប្រើប្រាស់សរុបៈ ${count}`
const read = await require('../../controllers/users/read')
settings.items = await read(settings.dItemLimit)
settings.route = 'user'
res.render('users/user', settings)
}else{
res.redirect('/users')
}
})
router.post('/', async function(req, res, next) {
if(req.session.user){
if(req.session.user.role === 'Admin'){
await require('../../controllers/users/create')(req)
}
res.redirect('/users/user')
}else{
res.redirect('/users')
}
})
module.exports = router
const schema = require('./schema')
module.exports = async (req, res) => {
const userSchema = await schema()
const id = (new Date()).getTime().toString(36) + Math.random().toString(36).slice(2)
user = new userSchema({
userid: id,
username: req.body.username,
password: req.body.password,
email: req.body.email,
role: req.body.role,
thumb: req.body.thumb,
info: req.body.info,
date: new Date()
})
return await user.save()
}
GitHub: https://github.com/Sokhavuth/tv
Vercel: https://tv-neon.vercel.app
Responsive: http://www.responsinator.com