呃呃呃
This commit is contained in:
@@ -3,7 +3,7 @@ module.exports = {
|
||||
connectionLimit : 100,
|
||||
host: 'localhost',
|
||||
user: 'root',
|
||||
password: 'lb714500.',
|
||||
password: 'lb714500',
|
||||
database: 'shop',
|
||||
insecureAuth: true
|
||||
},
|
||||
|
||||
10
项目合集/电商App/shop_backend/package-lock.json
generated
10
项目合集/电商App/shop_backend/package-lock.json
generated
@@ -16,7 +16,6 @@
|
||||
"md5": "^2.2.1",
|
||||
"morgan": "~1.9.1",
|
||||
"mysql2": "^3.12.0",
|
||||
"node-forge": "^1.3.1",
|
||||
"node-rsa": "^1.0.7",
|
||||
"pug": "2.0.0-beta11"
|
||||
}
|
||||
@@ -1148,15 +1147,6 @@
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/node-forge": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz",
|
||||
"integrity": "sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==",
|
||||
"license": "(BSD-3-Clause OR GPL-2.0)",
|
||||
"engines": {
|
||||
"node": ">= 6.13.0"
|
||||
}
|
||||
},
|
||||
"node_modules/node-rsa": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/node-rsa/-/node-rsa-1.1.1.tgz",
|
||||
|
||||
@@ -22,7 +22,7 @@ const _ = require("../import");
|
||||
* @apiVersion 1.0.0
|
||||
*/
|
||||
_.router.post('/addCar', async function(req, res, next) {
|
||||
var shopid = req.headers.data.waresid;
|
||||
var shopid = req.body.waresid;
|
||||
|
||||
var IsAddShopCar = await _.db.query({
|
||||
sql: _.config.sql.selectCarShop,
|
||||
@@ -115,9 +115,9 @@ _.router.post('/getCarList', async function(req, res, next) {
|
||||
* @apiVersion 1.0.0
|
||||
*/
|
||||
_.router.post('/checkCar', async function(req, res, next) {
|
||||
var shopid = req.headers.data.waresid;
|
||||
var shopid = req.body.waresid;
|
||||
|
||||
console.log("req.headers.data: ", req.headers.data);
|
||||
console.log("req.body: ", req.body);
|
||||
|
||||
var IsAddShopCar = await _.db.query({
|
||||
sql: _.config.sql.selectCarShop,
|
||||
@@ -169,7 +169,7 @@ _.router.post('/checkCar', async function(req, res, next) {
|
||||
* @apiVersion 1.0.0
|
||||
*/
|
||||
_.router.post('/deleteCar', async function(req, res, next) {
|
||||
var carid = req.headers.data.carid;
|
||||
var carid = req.body.carid;
|
||||
carid.forEach(async function(val) {
|
||||
var deleteCar = await _.db.query({
|
||||
sql: _.config.sql.deleteCarShop,
|
||||
@@ -208,8 +208,8 @@ _.router.post('/deleteCar', async function(req, res, next) {
|
||||
* @apiVersion 1.0.0
|
||||
*/
|
||||
_.router.post('/updateCarNum', async function(req, res, next) {
|
||||
var carid = req.headers.data.carid;
|
||||
var quantity = req.headers.data.quantity;
|
||||
var carid = req.body.carid;
|
||||
var quantity = req.body.quantity;
|
||||
|
||||
var updateCarNum = await _.db.query({
|
||||
sql: _.config.sql.updateCarNum,
|
||||
@@ -259,7 +259,7 @@ _.router.post('/updateCarNum', async function(req, res, next) {
|
||||
*/
|
||||
_.router.post('/submitCar', async function(req, res, next) {
|
||||
//"{"carList":[{"waresid":113,"goodsnum":2,"goodsprice":1000},{"waresid":114,"goodsnum":1,"goodsprice":1100}]}"
|
||||
var carList = JSON.parse(req.headers.data).carList;
|
||||
var carList = JSON.parse(req.body).carList;
|
||||
|
||||
carList.forEach(async function(val) {
|
||||
val.user_id = _.jwt.decode(req.headers.token).id;
|
||||
|
||||
@@ -155,7 +155,7 @@ _.router.post('/recommend', async function (req, res, next) {
|
||||
* @apiVersion 1.0.0
|
||||
*/
|
||||
_.router.post('/info', async function (req, res, next) {
|
||||
var id = req.headers.data.id;
|
||||
var id = req.body.id;
|
||||
|
||||
var data = (await _.db.query({
|
||||
sql: _.config.sql.getInfo,
|
||||
@@ -192,7 +192,7 @@ _.router.post('/info', async function (req, res, next) {
|
||||
* @apiVersion 1.0.0
|
||||
*/
|
||||
_.router.post('/activity', async function (req, res, next) {
|
||||
var activity_id = req.headers.data.id;
|
||||
var activity_id = req.body.id;
|
||||
|
||||
var data = await _.db.query({
|
||||
sql: _.config.sql.getActivity,
|
||||
@@ -229,7 +229,7 @@ _.router.post('/activity', async function (req, res, next) {
|
||||
* @apiVersion 1.0.0
|
||||
*/
|
||||
_.router.post('/search', async function (req, res, next) {
|
||||
var keyword = req.headers.data.keyword;
|
||||
var keyword = req.body.keyword;
|
||||
console.log("keyword: ", keyword)
|
||||
|
||||
var data = await _.db.query({
|
||||
|
||||
@@ -24,7 +24,7 @@ const _ = require("../import");
|
||||
*/
|
||||
_.router.post('/allOrder', async function(req, res, next) {
|
||||
|
||||
var status = req.headers.data.status, sql = null, params = [];
|
||||
var status = req.body.status, sql = null, params = [];
|
||||
|
||||
if (status == -1) {
|
||||
sql = _.config.sql.getAllOrder
|
||||
@@ -81,7 +81,7 @@ _.router.post('/allOrder', async function(req, res, next) {
|
||||
*/
|
||||
_.router.post('/buyOrder', async function(req, res, next) {
|
||||
|
||||
var goods_id = JSON.parse(req.headers.data.goodsid);
|
||||
var goods_id = JSON.parse(req.body.goodsid);
|
||||
|
||||
goods_id.forEach(async function(val) {
|
||||
var buyOrder = await _.db.query({
|
||||
|
||||
@@ -22,7 +22,7 @@ const _ = require("../import");
|
||||
* @apiVersion 1.0.0
|
||||
*/
|
||||
_.router.post('/list', async function(req, res, next) {
|
||||
var typename = req.headers.data.typename;
|
||||
var typename = req.body.typename;
|
||||
|
||||
var data = await _.db.query({
|
||||
sql: _.config.sql.getTypeList,
|
||||
|
||||
@@ -27,8 +27,8 @@ const _ = require("../import");
|
||||
*/
|
||||
_.router.post('/login', async function (req, res, next) {
|
||||
|
||||
var username = req.headers.data.name,
|
||||
userpwd = req.headers.data.pwd;
|
||||
var username = req.body.name,
|
||||
userpwd = req.body.pwd;
|
||||
|
||||
console.log("username: ", username);
|
||||
console.log("userpwd: ", userpwd);
|
||||
@@ -86,9 +86,9 @@ _.router.post('/login', async function (req, res, next) {
|
||||
*/
|
||||
_.router.post('/add', async function (req, res, next) {
|
||||
|
||||
var username = req.headers.data.name,
|
||||
userpwd = req.headers.data.pwd,
|
||||
userphone = req.headers.data.phone;
|
||||
var username = req.body.name,
|
||||
userpwd = req.body.pwd,
|
||||
userphone = req.body.phone;
|
||||
|
||||
var data = await _.db.query({
|
||||
sql: _.config.sql.addUser,
|
||||
@@ -135,7 +135,7 @@ _.router.post('/add', async function (req, res, next) {
|
||||
*/
|
||||
_.router.post('/like', async function (req, res, next) {
|
||||
|
||||
var like_shop = req.headers.data.shopid;
|
||||
var like_shop = req.body.shopid;
|
||||
var IsLike = await _.db.query({
|
||||
sql: _.config.sql.selectLike,
|
||||
data: [like_shop,_.jwt.decode(req.headers.token).id]
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
Navicat MySQL Data Transfer
|
||||
|
||||
Source Server : dwqdwqdwqdwq
|
||||
Source Server Version : 80017
|
||||
Source Host : localhost:3306
|
||||
Source Database : shop
|
||||
|
||||
Target Server Type : MYSQL
|
||||
Target Server Version : 80017
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 2019-12-05 20:09:55
|
||||
*/
|
||||
|
||||
SET FOREIGN_KEY_CHECKS=0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for user
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `user`;
|
||||
CREATE TABLE `user` (
|
||||
`user_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`user_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
`user_pwd` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
`user_token` varchar(255) DEFAULT NULL,
|
||||
`user_time` varchar(15) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户注册时间',
|
||||
`user_money` double(255,0) NOT NULL DEFAULT '99999999',
|
||||
`user_pic` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '用户头像',
|
||||
`user_address` varchar(255) DEFAULT NULL COMMENT '用户地址',
|
||||
`user_phone` varchar(12) DEFAULT NULL COMMENT '手机号',
|
||||
PRIMARY KEY (`user_id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of user
|
||||
-- ----------------------------
|
||||
INSERT INTO `user` VALUES ('1', 'bmy', '1234567890', null, '2019-12-05', '99999999', 'https://s1.mi-img.com/mfsv2/avatar/fdsc3/p0150oOutJBA/7hMzk9F1340hoX.jpg', '安徽省,合肥市,蜀山区,信旺华府骏苑', '15155145354');
|
||||
7
项目合集/电商App/shop_backend/test.http
Normal file
7
项目合集/电商App/shop_backend/test.http
Normal file
@@ -0,0 +1,7 @@
|
||||
POST http://127.0.0.1:9090/home/search HTTP/1.1
|
||||
content-type: application/json
|
||||
token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTMsInVzZXJuYW1lIjoibGIiLCJpYXQiOjE3NDQ0MjYzNDUsImV4cCI6MTc0NDQzNzE0NX0.3YyQ8x7Nxj4f77szklO9h7iIBVMqZUXu5HZe1PvVirY
|
||||
|
||||
{
|
||||
"keyword": "小米"
|
||||
}
|
||||
@@ -7,44 +7,28 @@ const jwt = require('jsonwebtoken');
|
||||
*/
|
||||
module.exports = {
|
||||
Validator(req, res, next) {
|
||||
if(req.headers.hasOwnProperty("data")) {
|
||||
try {
|
||||
req.headers.data = rsa.PrivateKeyDecryption(req.headers.data)
|
||||
// console.log("req.headers.data: ", req.headers.data);
|
||||
if(req.url == config.filter.login || req.url == config.filter.add
|
||||
|| req.url == config.filter.home
|
||||
) {
|
||||
next()
|
||||
} else {
|
||||
if(req.headers.hasOwnProperty("token")) {
|
||||
jwt.verify(req.headers.token,config.jwt,function(err,decode){
|
||||
if(err){
|
||||
res.json({
|
||||
status: 403,
|
||||
message: `身份凭证失效或不存在,请登录!${err.message}`
|
||||
})
|
||||
}else{
|
||||
next();
|
||||
}
|
||||
});
|
||||
} else { // 无token
|
||||
if (req.url == config.filter.login || req.url == config.filter.add
|
||||
|| req.url == config.filter.home
|
||||
) {
|
||||
next()
|
||||
} else {
|
||||
if (req.headers.hasOwnProperty("token")) {
|
||||
jwt.verify(req.headers.token, config.jwt, function (err, decode) {
|
||||
if (err) {
|
||||
res.json({
|
||||
status: 403,
|
||||
message: '无权限访问接口,您需要先登录才能使用!'
|
||||
message: `身份凭证失效或不存在,请登录!${err.message}`
|
||||
})
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
});
|
||||
} else { // 无token
|
||||
res.json({
|
||||
status: 500,
|
||||
message: `抱歉,私钥解密出错!错误信息:${e.message}`
|
||||
status: 403,
|
||||
message: '无权限访问接口,您需要先登录才能使用!'
|
||||
})
|
||||
}
|
||||
} else {
|
||||
res.json({
|
||||
status: 500,
|
||||
message: '请求头中缺少data字段'
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user