添加登录post和判断逻辑
This commit is contained in:
parent
f07b46f6c4
commit
2fab676fd5
6
app.js
6
app.js
@ -24,10 +24,6 @@ db.on("connected", () => console.log("MongoDB 连接成功"));
|
||||
db.on("error", err => console.error(err, "\nMongoDB 连接错误"));
|
||||
db.on("close", () => console.log("\nMongoDB 连接关闭"));
|
||||
|
||||
// view engine setup
|
||||
app.set('views', path.join(__dirname, 'views'));
|
||||
app.set('view engine', 'jade');
|
||||
|
||||
app.use(cors());
|
||||
app.use(logger('dev'));
|
||||
app.use(express.json());
|
||||
@ -39,7 +35,7 @@ app.use('/', indexRouter);
|
||||
|
||||
// catch 404 and forward to error handler
|
||||
app.use(function (req, res, next) {
|
||||
next(createError(404));
|
||||
// next(createError(404));
|
||||
});
|
||||
|
||||
// error handler
|
||||
|
||||
8
models/session.js
Normal file
8
models/session.js
Normal file
@ -0,0 +1,8 @@
|
||||
const mongoose = require("mongoose");
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const sessionSchema = new Schema({
|
||||
|
||||
});
|
||||
|
||||
module.exports = mongoose.Model("session", sessionSchema);
|
||||
857
package-lock.json
generated
857
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -11,11 +11,11 @@
|
||||
"cors": "^2.8.5",
|
||||
"debug": "~2.6.9",
|
||||
"dotenv": "^16.4.5",
|
||||
"express": "~4.16.1",
|
||||
"express": "^4.19.2",
|
||||
"express-async-handler": "^1.2.0",
|
||||
"express-validator": "^7.0.1",
|
||||
"http-errors": "~1.6.3",
|
||||
"jade": "~1.11.0",
|
||||
"jade": "^1.9.2",
|
||||
"mongoose": "^8.3.4",
|
||||
"morgan": "~1.9.1",
|
||||
"nodemon": "^3.1.0"
|
||||
|
||||
@ -2,6 +2,7 @@ var express = require('express');
|
||||
var router = express.Router();
|
||||
|
||||
const user_controller = require("../controllers/userController");
|
||||
const StringUtils = require("../utils/StringUtil");
|
||||
|
||||
/* GET home page. */
|
||||
router.get('/', function (req, res, next) {
|
||||
@ -9,9 +10,24 @@ router.get('/', function (req, res, next) {
|
||||
});
|
||||
|
||||
router.get('/user', async function (req, res, next) {
|
||||
const us = await user_controller.user_list();
|
||||
console.log(us);
|
||||
let us = await user_controller.user_list();
|
||||
us = JSON.stringify(us);
|
||||
res.send(us);
|
||||
})
|
||||
|
||||
router.post('/login', async function (req, res, next) {
|
||||
let us = await user_controller.user_list();
|
||||
const body = JSON.parse(JSON.stringify(req.body));
|
||||
if (StringUtils.isNotEmpty(body)) {
|
||||
if (body.account === '' || body.account === undefined || body.account === null) {
|
||||
res.send('account is null');
|
||||
}
|
||||
if (body.password === '' || body.password === undefined || body.password === null) {
|
||||
res.send('password is null');
|
||||
}
|
||||
}
|
||||
|
||||
res.send('return ok');
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
20
utils/StringUtil.js
Normal file
20
utils/StringUtil.js
Normal file
@ -0,0 +1,20 @@
|
||||
/**
|
||||
*
|
||||
* @param {*} obj 任意值
|
||||
* @returns true - obj不为空, false - obj为空
|
||||
*/
|
||||
exports.isNotEmpty = function (obj) {
|
||||
if (obj === null || obj === undefined || Object.keys(obj).length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj instanceof String) {
|
||||
return obj === '' ? false : true;
|
||||
}
|
||||
|
||||
if (obj instanceof Array) {
|
||||
return Array.length(obj) === 0 ? false : true;
|
||||
}
|
||||
console.log('111');
|
||||
return true;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user