Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Commit da7709c2 authored by Poupart-Lafarge Axel's avatar Poupart-Lafarge Axel

Initial commit

parents
Pipeline #6322 failed with stages
{
"repoId": "bdcb759e-4c2f-426a-92b0-cd3d4f09b275",
"lastSync": 0
}
\ No newline at end of file
.vscode/
frontend/node_modules/
frontend/package-lock.json
backend/node_modules/
{
"presets": ["env"]
}
\ No newline at end of file
import mongoose from 'mongoose';
const Schema = mongoose.Schema;
let Issue = new Schema({
title: {
type: String
},
responsible: {
type: String
},
description: {
type: String
},
severity: {
type: String
},
status: {
type: String,
default: 'Open'
}
});
export default mongoose.model('Issue', Issue);
import mongoose from 'mongoose';
const Schema = mongoose.Schema;
let UserSchema = new Schema({
name: {
type: String
},
password: {
type: String
},
manager: {
type: String
},
status: {
type: String
}
});
const User = module.exports = mongoose.model('User', UserSchema);
module.exports.getUserById = function(id, callback){
User.findById(id, callback);
}
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "babel-watch server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-watch": "^2.0.7"
},
"dependencies": {
"bcrypt": "^3.0.2",
"cors": "^2.8.4",
"express": "^4.16.3",
"jsonwebtoken": "^8.3.0",
"mongoose": "^5.2.4",
"multer": "^1.3.1",
"multer-gridfs-storage": "^3.0.1",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0"
}
}
const JwtStrategy = require('passport-jwt').Strategy;
const ExtractJwt = require('passport-jwt').ExtractJwt;
const User = require('./models/User');
module.exports = function(passport){
var opts = {}
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken();
opts.secretOrKey = 'secret';
//opts.issuer = 'accounts.examplesoft.com';
//opts.audience = 'yoursite.net';
passport.use(new JwtStrategy(opts, function(jwt_payload, done) {
console.log(jwt_payload);
User.getUserById({_id: jwt_payload._id}, function(err, user) {
if (err) {
return done(err, false);
}
if (user) {
return done(null, user);
} else {
return done(null, false);
// or you could create a new account
}
});
}));
}
import express from 'express';
import cors from 'cors';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import multer from 'multer';
import passport from 'passport';
import bcrypt from 'bcrypt';
import jwt from 'jsonwebtoken';
import Issue from './models/Issue';
import User from './models/User';
import { INSPECT_MAX_BYTES } from 'buffer';
import { runInNewContext } from 'vm';
//Connect to mongoDB server
mongoose.connect('mongodb://localhost/back-issues');
mongoose.set('debug', true);
const connection = mongoose.connection;
connection.once('open', () => {
console.log('MongoDB database connection established successfully!')
});
const app = express();
const router = express.Router();
app.use(cors());
app.use(bodyParser.json());
app.use(express.static('public'));
app.use(passport.initialize());
app.use(passport.session());
require('./passport')(passport)
//_____________Issues__________________//
router.route('/back-issues/issues').get((req, res) => {
Issue.find((err, issues) => {
if (err)
console.log(err);
else
res.json(issues);
});
});
router.route('/back-issues/issues/:id').get((req, res) => {
Issue.findById(req.params.id, (err, issue) => {
if (err)
console.log(err);
else
res.json(issue);
});
});
router.route(`/back-issues/issues/search-user/:user`).get( (req, res) => {
const user = req.params.user;
Issue.find( {responsible: user}, (err, issue) => {
if (err)
console.log(err);
else
res.json(issue);
});
});
router.route(`/back-issues/issues/search-title/:term`).get((req, res) => {
const term = req.params.term;
Issue.find( {title: { $regex: term, $options: 'i'} }, (err, issue) => {
if (err)
console.log(err);
else
res.json(issue);
});
});
router.route('/back-issues/issues/add').post((req, res) => {
let issue = new Issue(req.body);
issue.save()
.then(issue => {
res.status(200).json({'issue': 'Added successfully!'});
})
.catch(err => {
res.status(400).send('Failed to create new record');
});
});
router.route('/back-issues/issues/update/:id').post((req, res) => {
Issue.findById(req.params.id, (err, issue) => {
if (!issue)
return next(new Error('Could not load document'));
else {
issue.title = req.body.title;
issue.responsible = req.body.responsible;
issue.description = req.body.description;
issue.severity = req.body.severity;
issue.status = req.body.status;
issue.save().then(issue => {
res.json('Update done');
}).catch(err => {
res.status(400).send('Update failed');
});
}
});
});
router.route('/back-issues/issues/delete/:id').get((req, res) => {
Issue.findByIdAndRemove({_id: req.params.id}, (err, issue) => {
if (err)
res.json(err);
else
res.json('Remove successfully');
});
});
//__________________________________________________________________//
//____________________________Users_________________________________//
router.post('/back-issues/authenticate', (req, res) => {
const name = req.body.name;
const password = req.body.password;
User.findOne( {name: name}, (err, user) => {
if (err)
console.log(err);
if (!user) {
return res.json({success: false, msg: 'No user found'});
}
const currentUser = user;
const hash = currentUser.password;
const currentPassword = password;
bcrypt.compare(currentPassword, hash, (err, isMatch) => {
if (err)
console.log(err);
if (isMatch){
const token = jwt.sign(currentUser.toJSON(), 'secret', {
expiresIn: 604800 //1 week
});
res.json({
success: true,
token: token,
user: {
_id: user._id,
name: user.name,
manager: user.manager,
status: user.status
},
msg: 'COnnected successfully'
});
}
else {
return res.json({success: false, msg: 'Wrong password'});
}
});
});
})
router.route('/back-issues/users').get((req, res) => {
User.find((err, user) => {
if (err)
console.log(err);
else
res.json(user);
});
});
router.route('/back-issues/users/:id').get((req, res) => {
User.findById(req.params.id, (err, user) => {
if (err)
console.log(err);
else
res.json(user);
});
});
router.route(`/back-issues/users/search-name/:name`).get((req, res) => {
const name = req.params.name;
User.find( {name: name}, (err, user) => {
if (err)
console.log(err);
else
res.json(user);
});
});
router.route(`/back-issues/users/search-manager/:manager`).get((req, res) => {
const manager = req.params.manager;
User.find( {manager: manager}, (err, user) => {
if (err)
console.log(err);
else
res.json(user);
});
});
router.route('/back-issues/users/add').post((req, res) => {
let newUser = new User(req.body);
bcrypt.genSalt(10, (err, salt) => {
bcrypt.hash(newUser.password, salt, (err, hash) => {
if (err) throw err;
newUser.password = hash;
newUser.save()
.then(user => {
res.status(200).json({'user': 'Added successfully!'});
})
.catch(err => {
res.status(400).send('Failed to create new record');
});
})
})
});
router.route('/back-issues/users/update/:id').post((req, res) => {
User.findById(req.params.id, (err, user) => {
if (!user)
return next(new Error('Could not load document'));
else {
user.name = req.body.name;
user.password = req.body.password;
user.manager = req.body.manager;
user.status = req.body.status;
user.save().then(user => {
res.json('Update done');
}).catch(err => {
res.status(400).send('Update failed');
});
}
});
});
router.route('/back-issues/users/delete/:id').get((req, res) => {
User.findByIdAndRemove({_id: req.params.id}, (err, user) => {
if (err)
res.json(err);
else
res.json('Remove successfully');
});
});
//__________________________________________________________________//
//___________________Upload Files__________________________________//
const mul = multer();
// set the directory for the uploads to the uploaded to
var DIR = './uploads/';
//define the type of upload multer would be doing and pass in its destination, in our case, its a single file with the name photo
var upload = multer({dest: DIR}).single('document');
// Create a storage object with a given configuration
const storage = require('multer-gridfs-storage')({
url: 'mongodb://yourhost:27017/database'
});
// Set multer storage engine to the newly created object
//const upload = multer({ storage: storage });
// Upload your files as usual
//const sUpload = upload.single('avatar');
//app.post('/profile', sUpload, (req, res, next) => {
/*....*/
//})
//our file upload function.
router.route('/back-issues/upload').post((req, res, next) => {
var path = '';
upload(req, res, function (err) {
if (err) {
// An error occurred when uploading
console.log(err);
return res.status(422).send("an Error occured")
}
// No error occured.
path = req.file.path;
return res.send("Upload Completed for "+path);
});
})
//create a cors middleware
app.use(function(req, res, next) {
//set headers to allow cross origin request.
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.use('/', router);
app.listen(4000, () => console.log('Express server running on port 4000'));
# Editor configuration, see http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
max_line_length = off
trim_trailing_whitespace = false
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/tmp
/out-tsc
# dependencies
/node_modules
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
yarn-error.log
testem.log
/typings
# System Files
.DS_Store
Thumbs.db
# Frontend
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 6.0.8.
## Development server
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
## Code scaffolding
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
## Build
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.
## Running unit tests
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
## Running end-to-end tests
Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
## Further help
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"frontend": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/frontend",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
{
"input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css"
},
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "frontend:build"
},
"configurations": {
"production": {
"browserTarget": "frontend:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "frontend:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"styles": [
{
"input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css"
},
"src/styles.css"
],
"scripts": [],
"assets": [
"src/favicon.ico",
"src/assets"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
"frontend-e2e": {
"root": "e2e/",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "frontend:serve"
},
"configurations": {
"production": {
"devServerTarget": "frontend:serve:production"
}
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": "e2e/tsconfig.e2e.json",
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "frontend"
}
\ No newline at end of file
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const { SpecReporter } = require('jasmine-spec-reporter');
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
require('ts-node').register({
project: require('path').join(__dirname, './tsconfig.e2e.json')
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}