Skip to content

Commit

Permalink
Inital commit
Browse files Browse the repository at this point in the history
  • Loading branch information
CamileDahdah committed Apr 17, 2018
0 parents commit fb338ce
Show file tree
Hide file tree
Showing 2,458 changed files with 343,829 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .idea/events.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

599 changes: 599 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const config = {
jwtKey: 'MRePUBWaNW7wvNKMcOCkGlo6ZipKs4HKiRq2yAYV33FroszPKV0kOsnbtaIM',
databaseUrl: 'mongodb://localhost:27017/myproject'
};

module.exports = config;
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.3'

services:
mongo:
image: mongo:3.4.10
expose:
- 27017
ports:
- "27017:27017"
volumes:
- eventslocaldb:/data/db

volumes:
eventslocaldb:
69 changes: 69 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const path = require('path');
const hapi = require('hapi');
const mongoose = require('mongoose');
const _ = require('lodash');

const config = require(path.resolve('config/config'));

mongoose.connect(config.databaseUrl);

require(path.resolve('./models/users'));

const User = mongoose.model('User');

const init = async () => {
// Create a server with a host and port
const server = hapi.server({
port: 3000
});

await server.register([require('vision'), require('inert'), require('lout'), require('hapi-auth-jwt2')]);

server.auth.strategy('jwt', 'jwt',
{
key: config.jwtKey,
validate: async function (decoded, request) {
try {
const user = await User
.findOne({email: decoded.email})
.exec();
if (!user) {
return {isValid: false};
}
request.user = user;
return {isValid: true};
} catch (e) {
return {isValid: false};
}
},
verifyOptions: {algorithms: ['HS256']}
});

server.auth.default('jwt');

let routes = [];
const authenticationRoutes = require(path.resolve('routes/authentication'));
const profileRoutes = require(path.resolve('routes/profile'));
const eventsRoutes = require(path.resolve('routes/events'));

routes.push(authenticationRoutes);
routes.push(profileRoutes);
routes.push(eventsRoutes);

routes = _.flatMapDeep(routes, (route) => {
return route
});

// Add the routes
server.route(routes);

await server.start();
return server;
};


init().then(server => {
console.log('Server running at:', server.info.uri);
}).catch(error => {
console.log(error);
});
14 changes: 14 additions & 0 deletions models/user_event_schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const mongoose = require('mongoose');

const UserEventSchema = new mongoose.Schema({
name: {
type: String,
required: true
},
location: {
type: String,
required: true
}
});

module.exports = UserEventSchema;
40 changes: 40 additions & 0 deletions models/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const mongoose = require('mongoose');
const crypto = require('crypto');
const path = require('path');

const UserEventSchema = require(path.resolve('models/user_event_schema'))

const UserSchema = new mongoose.Schema({
name: {
type: String
},
email: {
type: String,
unique: true
},
password: {
type: String
},
salt: {
type: String
},
events: [UserEventSchema]
});

UserSchema.pre('save', function (next) {
if (this.password && this.isModified('password')) {
this.salt = crypto.randomBytes(16).toString('base64');
this.password = this.hashPassword(this.password)
}
next();
});

UserSchema.methods.hashPassword = function (password) {
if (this.salt && password) {
return crypto.pbkdf2Sync(password, this.salt, 10000, 64, 'sha1').toString('base64');
} else {
return password;
}
};

module.exports = mongoose.model('User', UserSchema);
1 change: 1 addition & 0 deletions node_modules/.bin/handlebars

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/uglifyjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions node_modules/accept/.npmignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions node_modules/accept/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/accept/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fb338ce

Please sign in to comment.