Skip to content

Commit

Permalink
changed sessions to be stored in database, fixes #259
Browse files Browse the repository at this point in the history
various logging cleanups
  • Loading branch information
bsears90 committed Apr 4, 2018
1 parent 92b93d6 commit a1a68b5
Show file tree
Hide file tree
Showing 14 changed files with 11 additions and 40 deletions.
4 changes: 0 additions & 4 deletions api/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ module.exports = function(app, passport) {
app.post('/api/v1/auth/token', passport.authenticate('local-login', {session:false}), function(req, res) {
console.log(req.user);
let token = jwt.sign({ uid: req.user.data.id }, process.env.SECRET_KEY, { expiresIn: '3h' });
console.log(token);
console.log(jwt.verify(token, process.env.SECRET_KEY));
res.json({token:token});
});

Expand Down Expand Up @@ -65,7 +63,6 @@ module.exports = function(app, passport) {
});

app.get("/api/v1/auth/reset-password/:uid/:token", function(req, res, next){
console.log(bcrypt.hashSync(req.params.token, 10));
ResetRequest.findOne("user_id", req.params.uid, function(result){
if(result.data && bcrypt.compareSync(req.params.token, result.get("hash"))){
res.status(200).json({isValid: true});
Expand All @@ -88,7 +85,6 @@ module.exports = function(app, passport) {
// user.set("password", password);
res.json({"message" : "Password successfully reset"});
result.delete(function(r){
console.log("reset request deleted");

})
})
Expand Down
4 changes: 2 additions & 2 deletions api/invoices.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function(router) {
Invoice.fetchUserInvoices(user).then(function (result) {
next();
}).catch(function (err) {
console.log(err);
console.error(err);
next();
//res.status(400).json({error: err});
});
Expand All @@ -34,7 +34,7 @@ module.exports = function(router) {
Invoice.fetchUserInvoices(user).then(function (result) {
next();
}).catch(function (err) {
console.log(err);
console.error(err);
next();
//res.status(400).json({error: err});
});
Expand Down
3 changes: 0 additions & 3 deletions api/notification-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,19 @@ module.exports = function(router) {
model.getSchema(true, false, function(result){
let template = res.locals.valid_object;
template["schema"] = result;
console.log(template);
res.json(template);
});
});

router.get("/notification-templates/:id(\\d+)/roles", validate(NotificationTemplate), auth(), function(req, res, next){
res.locals.valid_object.getRoles(function(roles){
console.log(roles);
res.locals.json = roles;
next();
})
});

router.put("/notification-templates/:id(\\d+)/roles", validate(NotificationTemplate), auth(), function(req, res, next) {
res.locals.valid_object.setRoles(req.body, function(result){
console.log(result);
res.locals.json = result;
next();
})
Expand Down
4 changes: 0 additions & 4 deletions api/service-instances.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ module.exports = function(router) {
});

router.post('/service-instances/:id/files', validate(ServiceInstance), auth(null, ServiceInstance), multer({ storage:serviceStorage, limits : {fileSize : uploadLimit()} }).array('files'), function(req, res, next) {
console.log(req.files);
let filesToInsert = req.files.map(function(file){
if(req.user) {
file.user_id = req.user.data.id;
Expand All @@ -183,17 +182,14 @@ module.exports = function(router) {
file.name = file.originalname;
return file
});
console.log(filesToInsert);
File.batchCreate(filesToInsert, function(files){
console.log(files);
EventLogs.logEvent(req.user.get('id'), `service-instances ${req.params.id} had files added by user ${req.user.get('email')}`);
res.json(files);
});
});

router.get('/service-instances/:id/files',auth(null, ServiceInstance), function(req, res, next) {
File.findFile(serviceFilePath, req.params.id, function(files){
console.log(files);
res.json(files);
})
});
Expand Down
7 changes: 1 addition & 6 deletions api/service-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,11 @@ module.exports = function (router) {
acc[handler.name] = handler.handler;
return acc;
}, {});
console.log(handlers, "HANDLERS!");
//this is true when user can override things
let hasPermission = (permission_array.some(p => p.get("permission_name") === "can_administrate" || p.get("permission_name") === "can_manage"));
let templatePrice = serviceTemplate.get("amount");
let price = hasPermission ? (req_body.amount || templatePrice) : templatePrice;
let trialPeriod = serviceTemplate.get("trial_period_days");
console.log("TRIAL PERIOD DAYSS " + trialPeriod)

//todo: this doesn't do anthing yet, needs to check the "passed" props not the ones on the original...
// let validationResult = props ? validateProperties(props, handlers) : [];
Expand Down Expand Up @@ -545,10 +543,8 @@ module.exports = function (router) {
new Promise((resolve, reject) => {
//Get the list of templates and apply order from query if requested
if (req.query.order_by) {
console.log(`Query sent with order by ${req.query.order_by}`);
let order = 'ASC';
if (req.query.order) {
console.log(`Query sent with order ${req.query.order}`);
if (req.query.order.toUpperCase() === 'DESC') {
order = 'DESC';
}
Expand Down Expand Up @@ -577,9 +573,8 @@ module.exports = function (router) {
//Apply the query limit to the array of templates
return new Promise((resolve, reject) => {
if (req.query.limit) {
console.log(`Query sent with limit ${req.query.limit}`);
if (isNaN(req.query.limit)) {
console.log(`limit ${req.query.limit} is not a number`);
console.error(`limit ${req.query.limit} is not a number`);
reject(`limit ${req.query.limit} must be a number`)
}
else {
Expand Down
3 changes: 0 additions & 3 deletions api/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ module.exports = function (router, passport) {
let token = req.query.token;
if (token) {
Invitation.findOne("token", token, function (foundInvitation) {
console.log(foundInvitation);
if (!foundInvitation.data) {
res.status(500).send({error: "invalid token specified"})
} else {
Expand All @@ -101,7 +100,6 @@ module.exports = function (router, passport) {
newUser.set("status", "active");
newUser.update(function (err, updatedUser) {
foundInvitation.delete(function (response) {
console.log("invitation deleted");
EventLogs.logEvent(updatedUser.get('id'), `user ${updatedUser.get('id')} ${updatedUser.get('email')} registered`);
res.locals.json = updatedUser.data;
res.locals.valid_object = updatedUser;
Expand Down Expand Up @@ -140,7 +138,6 @@ module.exports = function (router, passport) {
}, function (req, res, next) {
req.logIn(res.locals.valid_object, {session: true}, function (err) {
if (!err) {
console.log("user logged in!");
next();
} else {
console.error("Issue logging in: ", err)
Expand Down
4 changes: 1 addition & 3 deletions lib/mailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ let sendMail = function (address, message, subject) {
text: message, // plaintext body
html: message // html body
};
console.log("MAILING!");
console.log(mailOptions)
// send mail with defined transport object
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
return console.log(error);
return console.error(error);
}
console.log('Message sent: ' + info.response);
});
Expand Down
1 change: 0 additions & 1 deletion lib/stripeValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ let async = require("async");

let validateStripe = function(publishable, secret, cb){
if(!publishable || !secret){
console.log(publishable, secret);
return cb("Stripe keys must be entered!");
}
async.series([
Expand Down
1 change: 0 additions & 1 deletion middleware/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var validateRequest = function (model=User, correlation_id="id", params_name="id
model.findOne(params_name, id, function(result){
if(result.data){
//If the object exist, return it as well as continuing the process:
console.log("Valid Request!");
res.locals.valid_object = result;
return next();
} else {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"body-parser": "^1.18.2",
"chart.js": "^2.7.0",
"connect-flash": "^0.1.1",
"connect-session-knex": "^1.4.0",
"cookie-parser": "^1.4.3",
"crypto": "0.0.3",
"css-loader": "^0.26.4",
Expand Down
1 change: 0 additions & 1 deletion plugins/analytics/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ module.exports = {
console.error(err);
return reject(err);
}
console.log(results);
resolve(results);
});
// whatever
Expand Down
7 changes: 5 additions & 2 deletions plugins/api-gateway/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var express = require('express');
var expressSession = require('express-session');
const knexSession = require("connect-session-knex")(expressSession);
var flash = require('connect-flash');
var swaggerJSDoc = require('swagger-jsdoc');
var logger = require('morgan');
Expand Down Expand Up @@ -101,12 +102,14 @@ module.exports = {
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));


let KnexStore = new knexSession({knex: database});
//todo: move this into a plugin
app.use(expressSession({
secret: process.env.SECRET_KEY,
resave: true,
saveUninitialized: true
saveUninitialized: true,
store: KnexStore

}));

app.use(passport.initialize());
Expand Down
9 changes: 0 additions & 9 deletions views/router.jsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
import React from 'react';
import {render} from 'react-dom';
import {Router, Route, IndexRoute, IndexRedirect, browserHistory} from 'react-router';
import {connect} from "react-redux";
import Promise from "promise-polyfill";
import {setOptions, setUid, setUser, fetchUsers, initializeState} from "./components/utilities/actions"
import {pluginbot} from "./store"
import {Provider} from 'react-redux'
import {StripeProvider} from 'react-stripe-elements';
import PluginbotProvider from "pluginbot-react/dist/provider"
import cookie from 'react-cookie';
import consume from "pluginbot-react/dist/consume"

// App
import App from "./components/app.jsx";
import Home from "./components/pages/home.jsx";
import AllServices from "./components/pages/all-services.jsx";
// Dashboard (My Services)
import MyServices from './components/pages/my-services.jsx';
import ModalInvoice from './components/elements/modals/modal-invoice.jsx';
import ServiceInstance from './components/pages/service-instance.jsx';
import ServiceRequest from './components/pages/service-request.jsx';
import ServiceCatalog from './components/pages/service-catalog.jsx';
Expand Down
2 changes: 1 addition & 1 deletion views/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ let initialize = async function () {

let app = await PluginbotClient.createPluginbot();
let middleware = [rootReducer, thunk];
if(process.env.NODE_ENV === "development" ){
if(process.env.NODE_ENV === "development"){
const { logger } = require(`redux-logger`);
middleware.push(logger);
}
Expand Down

0 comments on commit a1a68b5

Please sign in to comment.