Commit 4a5c02fd authored by Arthur.Pautrel's avatar Arthur.Pautrel
Browse files

Initial commit

parents
const mongoose = require('mongoose');
module.exports = async () => {
try {
await mongoose.connect('mongodb://127.0.0.1:27017/internet_programming', {
autoIndex: true,
serverSelectionTimeoutMS: 30000 //default 30 seconds
});
console.log("MongoDB connected");
} catch (err) {
console.log("Mongoose: ", err);
}
}
\ No newline at end of file
const express = require('express');
const cors = require('cors')
const bodyParser = require("body-parser");
var session = require('express-session');
const app = express();
app.use(cors({
origin: "http://localhost:3000"
}))
app.set('trust proxy', 1) //trust first proxy
app.use(session({
secret: 'my-secret',
resave: true,
rolling: true,
saveUninitialized: true,
name: 'accesstoken',
cookie: {
maxeAge: 1000 * 60 * 60 * 2,
sameSite: true,
secure: false}
}))
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
// Connect the mongoDB here
require('./configs/db')();
app.use(require('./routes'));
app.listen(3001, () => console.log('App available on http://localhost/3001'));
const jwt = require("jsonwebtoken");
const config = process.env;
const currentUser = (req, res, next) => {
if (!req.session.jwt) {
return res.send("You must log in");
}
const user = jwt.verify(req.session.jwt, 'jwt-secret');
req.currentUser = user;
next();
};
const ensureSignedOut = (req, res, next) => {
if (req.session.jwt) {
return res.send("You are already logged in");
}
next();
};
const ensureSignedIn = (req, res, next) => {
if (!req.session.jwt) {
return res.send("You must log in");
}
next();
};
module.exports = {
ensureSignedIn,
ensureSignedOut,
currentUser
}
\ No newline at end of file
const joiValidation = (schema) => {
return async (req, res, next) => {
try {
const body = req.body;
await schema.validateAsync(body);
} catch (err) {
return res.json({ success: false, error: err})
}
next();
}
}
module.exports = joiValidation;
\ No newline at end of file
var mongoose = require('mongoose');
var categorySchema = new mongoose.Schema({
name: {
type: String,
required: true
},
desc: String,
imageUrl: String
}, {
timestamps: true,
});
var Categories = mongoose.model('Categories', categorySchema);
module.exports = Categories;
\ No newline at end of file
var mongoose = require('mongoose');
var itemSchema = new mongoose.Schema({
name: {
type: String,
required: true
},
category: {
type: Schema.Types.ObjectId,
ref: "Categories"
},
desc: String
}, {
timestamps: true,
});
var Items = mongoose.model('Items', itemSchema);
module.exports = Items;
\ No newline at end of file
var mongoose = require('mongoose');
var productSchema = new mongoose.Schema({
title: {
type: String,
required: true
},
category: {
type: Schema.Types.ObjectId,
ref: "Categories"
},
item: {
type: Schema.Types.ObjectId,
ref: "Items"
},
user: {
type: Schema.Types.ObjectId,
ref: "Users"
},
desc: String,
imageUrl: String
}, {
timestamps: true,
});
var Products = mongoose.model('Products', productSchema);
module.exports = Products;
\ No newline at end of file
const bcrypt = require('bcryptjs/dist/bcrypt');
var mongoose = require('mongoose');
var userSchema = new mongoose.Schema({
email: {
type: String,
unique: true,
required: true,
validate: {
validator: async val => Users.doesntExist({username: val}),
message: ({value}) => `Username ${value} already taken.`
}
},
username: {
type: String,
unique: true,
required: true
},
firstName: {
type: String,
required: true
},
lastName: {
type: String,
required: true
},
password: {
type: String,
required: true
},
}, {
timestamps: true,
});
// userSchema.pre('save', function (next) {
// if (this.isModified('password')) {
// var salt = bcrypt.genSaltSync(10);
// this.password = bcrypt.hashSync(this.password, salt);
// }
// next();
// });
userSchema.methods.matchesPasswords = function (password) {
return bcrypt.compareSync(password, this.password);
};
userSchema.statics.doesntExist = async function (options) {
return (await this.where(options).countDocuments()) === 0;
};
var Users = mongoose.model('Users', userSchema);
module.exports = Users;
\ No newline at end of file
../mime/cli.js
\ No newline at end of file
../nanoid/bin/nanoid.cjs
\ No newline at end of file
../@babel/parser/bin/babel-parser.js
\ No newline at end of file
../semver/bin/semver
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
Copyright (C) 2012-2014 by various contributors (see AUTHORS)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
# @babel/parser
> A JavaScript parser
See our website [@babel/parser](https://babeljs.io/docs/en/babel-parser) for more information or the [issues](https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20parser%20(babylon)%22+is%3Aopen) associated with this package.
## Install
Using npm:
```sh
npm install --save-dev @babel/parser
```
or using yarn:
```sh
yarn add @babel/parser --dev
```
#!/usr/bin/env node
/* eslint no-var: 0 */
var parser = require("..");
var fs = require("fs");
var filename = process.argv[2];
if (!filename) {
console.error("no filename specified");
} else {
var file = fs.readFileSync(filename, "utf8");
var ast = parser.parse(file);
console.log(JSON.stringify(ast, null, " "));
}
This diff is collapsed.
This diff is collapsed.
{
"name": "@babel/parser",
"version": "7.17.3",
"description": "A JavaScript parser",
"author": "The Babel Team (https://babel.dev/team)",
"homepage": "https://babel.dev/docs/en/next/babel-parser",
"bugs": "https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A+parser+%28babylon%29%22+is%3Aopen",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"keywords": [
"babel",
"javascript",
"parser",
"tc39",
"ecmascript",
"@babel/parser"
],
"repository": {
"type": "git",
"url": "https://github.com/babel/babel.git",
"directory": "packages/babel-parser"
},
"main": "./lib/index.js",
"types": "./typings/babel-parser.d.ts",
"files": [
"bin",
"lib",
"typings"
],
"engines": {
"node": ">=6.0.0"
},
"devDependencies": {
"@babel/code-frame": "^7.16.7",
"@babel/helper-fixtures": "^7.17.0",
"@babel/helper-validator-identifier": "^7.16.7",
"charcodes": "^0.2.0"
},
"bin": "./bin/babel-parser.js"
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment