// models/users.ts
import { bcrypt } from '../deps.ts'
interface UserSchema {
_id: ObjectId;
id: string;
title: string;
content: string;
thumb: string;
postdate: string;
role: string;
email: string;
password: string;
}
class User{
async createRootUser(req){
const id = Date.now() + Math.round(Math.random() * 1E9).toString()
const salt = await bcrypt.genSalt(8)
const hashPassword = bcrypt.hashSync('xxxxxxxxxxxxxxx', salt)
let newUser = {
id: id,
title: 'Sokhavuth',
content: '',
thumb: '',
postdate: '',
role: 'Admin',
email: 'vuthdevelop@gmail.com',
password: hashPassword,
}
const users = req.mydb.collection<UserSchema>("users")
await users.insertOne(newUser)
}
}
export default new User()
// controllers/front/login.jsx
/** @jsx h */
import { h, renderSSR } from "../../deps.ts"
import config from '../../config.js'
import Login_ from '../../views/front/login.jsx'
import users from '../../models/users.ts'
class Login{
async getItem(req, res){
this.config = await config()
this.config.pageTitle = 'ទំព័ចូលក្នុង'
this.config.route = '/login'
users.createRootUser(req)
const str = renderSSR(<Login_ config={this.config} />)
const html = `<!DOCTYPE html>${str}`
res.send(html)
}
}
export default new Login()
GitHub: https://github.com/Sokhavuth/khmerweb-deno
Deno Deploy: https://khmerweb-blog.deno.dev/login