Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
54a26ea
Sequelize and MySQL2 installed
Feb 28, 2019
f6d604b
Installed sequelize-cli, used to generate Sequelize files
Feb 28, 2019
1397225
www includes models
Feb 28, 2019
fe7ec6b
Database configuration, temp user model, user model used in route
Feb 28, 2019
ad78f79
Default view now displays usernames of all existing users in database
Feb 28, 2019
54c0b22
Configuration and instructions
Mar 1, 2019
20c049b
Merge branch 'master' of git://github.com/jharvey8/SoftwareEngineering
Mar 23, 2019
d2ecdc4
Installed passport, passport-local
Mar 23, 2019
00586ed
users model altered for use with passport
Mar 23, 2019
ee54ec3
passport.js config
Mar 23, 2019
9c77659
authorization options
Mar 23, 2019
586e421
Users API - creation, authentication, etc.
Mar 28, 2019
99a3488
login
Mar 28, 2019
1a752e0
Marker model, relationship with User
Mar 28, 2019
81899f8
Base API constructed
Apr 7, 2019
31af321
API Readme
Apr 7, 2019
b09781c
Formatting edits
Apr 7, 2019
305100d
Another quick edit
Apr 7, 2019
884d671
More edits
Apr 7, 2019
2bd1ca1
Create index2.pug
ceguez Apr 12, 2019
af3095f
Create UserProfile.pug
ceguez Apr 12, 2019
73a02aa
Merge pull request #1 from CaroRoquita/patch-1
Apr 12, 2019
73e4615
Merge pull request #2 from CaroRoquita/patch-2
Apr 12, 2019
31d1a60
Create style.css
rkinoshi Apr 12, 2019
9106533
Merge pull request #3 from rkinoshi/patch-2
Apr 12, 2019
bc1c06b
Move style.css to directory
Apr 12, 2019
6054495
User login system implemented on frontend
Apr 12, 2019
1afee1f
Consolidated existing javascript
Apr 12, 2019
52f894a
Google Maps successfully integrated
Apr 13, 2019
0f1568b
Responsiveness tweaks
Apr 13, 2019
6787e6f
Messages close automatically
Apr 13, 2019
80a45a8
App title
Apr 13, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions GhoulAlert/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ var logger = require('morgan');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');

require('./config/passport');
var apiV1IndexRouter = require('./routes/apiV1/index');
var apiV1UsersRouter = require('./routes/apiV1/users');

var app = express();

// view engine setup
Expand All @@ -21,6 +25,8 @@ app.use(express.static(path.join(__dirname, 'public')));

app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/apiV1', apiV1IndexRouter);
app.use('/apiV1/users', apiV1UsersRouter);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
Expand Down
15 changes: 9 additions & 6 deletions GhoulAlert/bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
var app = require('../app');
var debug = require('debug')('ghoulalert:server');
var http = require('http');
var models = require('../models');

/**
* Get port from environment and store in Express.
Expand All @@ -21,13 +22,15 @@ app.set('port', port);

var server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/
models.sequelize.sync().then(function(){
/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
})

/**
* Normalize a port into a number, string, or false.
Expand Down
23 changes: 23 additions & 0 deletions GhoulAlert/config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"development": {
"username": "ghoul",
"password": "ghoul_user!61",
"database": "ghoul_development",
"host": "127.0.0.1",
"dialect": "mysql"
},
"test": {
"username": "ghoul",
"password": "ghoul_user!61",
"database": "ghoul_test",
"host": "127.0.0.1",
"dialect": "mysql"
},
"production": {
"username": "root",
"password": null,
"database": "ghoul_production",
"host": "127.0.0.1",
"dialect": "mysql"
}
}
19 changes: 19 additions & 0 deletions GhoulAlert/config/passport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

var models = require('../models');
var passport = require('passport');
var localStrat = require('passport-local');

var User = models.User;

passport.use(new localStrat({
usernameField: 'username',
passwordField: 'password',
}, (username, password, done) => {
User.findOne({ where: { username: username } }).then((user) => {
if(!user || !user.validatePassword(password)) {
return done(null, false, { errors: {'username or password': 'is invalid'}});
}
return done(null, user);
}).catch(done);
}));
41 changes: 41 additions & 0 deletions GhoulAlert/models/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/config.json')[env];
const db = {};

let sequelize;
if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
sequelize = new Sequelize(config.database, config.username, config.password, config);
}

fs
.readdirSync(__dirname)
.filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(file => {
const model = sequelize['import'](path.join(__dirname, file));
db[model.name] = model;
});

Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});

// Relationships go here
db.User.hasMany(db.Marker);
db.Marker.belongsTo(db.User);

db.sequelize = sequelize;
db.Sequelize = Sequelize;

module.exports = db;
46 changes: 46 additions & 0 deletions GhoulAlert/models/marker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';

module.exports = (sequelize, DataTypes) => {
var Marker = sequelize.define('Marker', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},

latitude: {
type: DataTypes.FLOAT,
allowNull: false,
validate: {
notEmpty: true
}
},

longitude: {
type: DataTypes.FLOAT,
allowNull: false,
validate: {
notEmpty: true
}
},

name: {
type: DataTypes.STRING,
allowNull: false,
unique: {
args: true,
msg: "Name of the marker must be unique"
},
validate: {
notEmpty: true
}
},

description: {
type: DataTypes.STRING,
allowNull: true,
}
});

return Marker;
}
67 changes: 67 additions & 0 deletions GhoulAlert/models/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use strict';
const crypto = require('crypto');
const jwt = require('jsonwebtoken');

module.exports = (sequelize, DataTypes) => {
// Define the user model
var User = sequelize.define('User', {
// The user has an id, which identifies them and acts as a primary key
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
// The user has a "username", of the string datatype, that is unique
username: {
type: DataTypes.STRING,
allowNull: false,
unique: {
args: true,
msg: "Username already exists; it must be unique."
}
},

// The user has a "password", composed of a hash and salt
hash: DataTypes.TEXT('long'),
salt: DataTypes.TEXT('long')
})

User.prototype.setPassword = function(password) {
this.salt = crypto.randomBytes(16).toString('hex');
this.hash = crypto.pbkdf2Sync(password, this.salt, 10000, 512, 'sha512').toString('hex');
}

User.prototype.validatePassword = function(password) {
const hash = crypto.pbkdf2Sync(password, this.salt, 10000, 512, 'sha512').toString('hex');
return this.hash === hash;
}

User.prototype.generateJWT = function() {
const today = new Date();
const expires = new Date(today);
expires.setDate(today.getDate() + 30);

return jwt.sign({
username: this.username,
id: this.id,
exp: parseInt(expires.getTime() / 1000, 10),
}, 'secret');
}

User.prototype.toAuthJSON = function() {
return {
id: this.id,
username: this.username,
token: this.generateJWT()
};
}

User.prototype.toJSON = function() {
return {
id: this.id,
username: this.username
}
}

return User;
}
Loading