我正在开发我的第一个真实生活应用程序。它有几种类型的用户:1。正常,2。管理员和单个超级用户。
我处于两难选择之中:
创建一个猫鼬字符串枚举字段以保存每个级别(所有用户都有1个模型)
创建两个不同的模型,一个用于用户,一个用于admin + Supers(2个不同的模型)
EDIT1:
以下是整个app.js:
var express = require('express'),
path = require('path'),
mongoose = require('mongoose'),
app = express(),
passport = require('passport'),
LocalStrategy = require('passport-local');
var indexRoutes = require(path.join( __dirname, "routes" )),
User = require(path.join( __dirname, "models", "user"));
mongoose.connect("mongodb://localhost/**-**");
// Passport configuration.
app.use(require("express-session")({
secret: "Secret!",
resave: false,
saveUninitialized: false
}));
app.use(passport.initialize());
app.use(passport.session());
passport.use(new LocalStrategy(User.authenticate()));
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
app.use("/", indexRoutes);
app.listen(3000, () => {
console.log("Server has started!");
});