aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/Client.ts4
-rw-r--r--src/server/Message.ts3
-rw-r--r--src/server/ServerUtil.ts3
-rw-r--r--src/server/authentication/config/passport.ts6
-rw-r--r--src/server/authentication/controllers/WorkspacesMenu.tsx4
-rw-r--r--src/server/authentication/controllers/user_controller.ts26
-rw-r--r--src/server/authentication/models/current_user_utils.ts8
-rw-r--r--src/server/authentication/models/user_model.ts2
-rw-r--r--src/server/database.ts34
-rw-r--r--src/server/index.ts88
-rw-r--r--src/server/public/files/upload_a6a70d84ebb65febf7900e29f52cc86d.pdfbin1043556 -> 0 bytes
11 files changed, 91 insertions, 87 deletions
diff --git a/src/server/Client.ts b/src/server/Client.ts
index 6b8841658..02402a5a0 100644
--- a/src/server/Client.ts
+++ b/src/server/Client.ts
@@ -2,14 +2,14 @@ import { computed } from "mobx";
export class Client {
constructor(guid: string) {
- this.guid = guid
+ this.guid = guid;
}
private guid: string;
@computed
public get GUID(): string {
- return this.guid
+ return this.guid;
}
} \ No newline at end of file
diff --git a/src/server/Message.ts b/src/server/Message.ts
index 0274609bb..d22e5c17c 100644
--- a/src/server/Message.ts
+++ b/src/server/Message.ts
@@ -61,7 +61,8 @@ export enum Types {
PDF,
Tuple,
HistogramOp,
- Boolean
+ Boolean,
+ Script,
}
export class DocumentTransfer implements Transferable {
diff --git a/src/server/ServerUtil.ts b/src/server/ServerUtil.ts
index 2c2bfd0c9..0973f82b1 100644
--- a/src/server/ServerUtil.ts
+++ b/src/server/ServerUtil.ts
@@ -18,6 +18,7 @@ import { PDFField } from "../fields/PDFField";
import { TupleField } from "../fields/TupleField";
import { BooleanField } from "../fields/BooleanField";
import { HistogramField } from "../client/northstar/dash-fields/HistogramField";
+import { ScriptField } from "../fields/ScriptField";
export class ServerUtils {
public static prepend(extension: string): string {
@@ -60,6 +61,8 @@ export class ServerUtils {
return new PDFField(new URL(data), id, false);
case Types.List:
return ListField.FromJson(id, data);
+ case Types.Script:
+ return ScriptField.FromJson(id, data);
case Types.Audio:
return new AudioField(new URL(data), id, false);
case Types.Video:
diff --git a/src/server/authentication/config/passport.ts b/src/server/authentication/config/passport.ts
index b6fe15655..d42741410 100644
--- a/src/server/authentication/config/passport.ts
+++ b/src/server/authentication/config/passport.ts
@@ -1,4 +1,4 @@
-import * as passport from 'passport'
+import * as passport from 'passport';
import * as passportLocal from 'passport-local';
import * as mongodb from 'mongodb';
import * as _ from "lodash";
@@ -22,7 +22,7 @@ passport.deserializeUser<any, any>((id, done) => {
passport.use(new LocalStrategy({ usernameField: 'email', passReqToCallback: true }, (req, email, password, done) => {
User.findOne({ email: email.toLowerCase() }, (error: any, user: any) => {
if (error) return done(error);
- if (!user) return done(undefined, false, { message: "Invalid email or password" }) // invalid email
+ if (!user) return done(undefined, false, { message: "Invalid email or password" }); // invalid email
user.comparePassword(password, (error: Error, isMatch: boolean) => {
if (error) return done(error);
if (!isMatch) return done(undefined, false, { message: "Invalid email or password" }); // invalid password
@@ -37,7 +37,7 @@ export let isAuthenticated = (req: Request, res: Response, next: NextFunction) =
return next();
}
return res.redirect(RouteStore.login);
-}
+};
export let isAuthorized = (req: Request, res: Response, next: NextFunction) => {
const provider = req.path.split("/").slice(-1)[0];
diff --git a/src/server/authentication/controllers/WorkspacesMenu.tsx b/src/server/authentication/controllers/WorkspacesMenu.tsx
index 8e14cf98e..b08c1aebe 100644
--- a/src/server/authentication/controllers/WorkspacesMenu.tsx
+++ b/src/server/authentication/controllers/WorkspacesMenu.tsx
@@ -1,7 +1,7 @@
import * as React from 'react';
import { observable, action, configure, reaction, computed, ObservableMap, runInAction } from 'mobx';
import { observer } from "mobx-react";
-import './WorkspacesMenu.css'
+import './WorkspacesMenu.css';
import { Document } from '../../../fields/Document';
import { EditableView } from '../../../client/views/EditableView';
import { KeyStore } from '../../../fields/KeyStore';
@@ -73,7 +73,7 @@ export class WorkspacesMenu extends React.Component<WorkspaceMenuProps> {
<span>{i + 1} - </span>
<EditableView
display={"inline"}
- GetValue={() => { return s.Title }}
+ GetValue={() => s.Title}
SetValue={(title: string): boolean => {
s.SetText(KeyStore.Title, title);
return true;
diff --git a/src/server/authentication/controllers/user_controller.ts b/src/server/authentication/controllers/user_controller.ts
index e365b8dce..1dacdf3fa 100644
--- a/src/server/authentication/controllers/user_controller.ts
+++ b/src/server/authentication/controllers/user_controller.ts
@@ -4,7 +4,7 @@ import * as passport from "passport";
import { IVerifyOptions } from "passport-local";
import "../config/passport";
import * as request from "express-validator";
-const flash = require("express-flash");
+import flash = require("express-flash");
import * as session from "express-session";
import * as pug from 'pug';
import * as async from 'async';
@@ -109,12 +109,12 @@ export let postLogin = (req: Request, res: Response, next: NextFunction) => {
}
passport.authenticate("local", (err: Error, user: DashUserModel, info: IVerifyOptions) => {
- if (err) { return next(err); }
+ if (err) { next(err); return; }
if (!user) {
return res.redirect(RouteStore.signup);
}
req.logIn(user, (err) => {
- if (err) { return next(err); }
+ if (err) { next(err); return; }
res.redirect(RouteStore.home);
});
})(req, res, next);
@@ -132,14 +132,14 @@ export let getLogout = (req: Request, res: Response) => {
sess.destroy((err) => { if (err) { console.log(err); } });
}
res.redirect(RouteStore.login);
-}
+};
export let getForgot = function (req: Request, res: Response) {
res.render("forgot.pug", {
title: "Recover Password",
user: req.user,
});
-}
+};
export let postForgot = function (req: Request, res: Response, next: NextFunction) {
const email = req.body.email;
@@ -152,13 +152,14 @@ export let postForgot = function (req: Request, res: Response, next: NextFunctio
return;
}
done(null, buffer.toString('hex'));
- })
+ });
},
function (token: string, done: any) {
User.findOne({ email }, function (err, user: DashUserModel) {
if (!user) {
// NO ACCOUNT WITH SUBMITTED EMAIL
- return res.redirect(RouteStore.forgot);
+ res.redirect(RouteStore.forgot);
+ return;
}
user.passwordResetToken = token;
user.passwordResetExpires = new Date(Date.now() + 3600000); // 1 HOUR
@@ -192,8 +193,8 @@ export let postForgot = function (req: Request, res: Response, next: NextFunctio
], function (err) {
if (err) return next(err);
res.redirect(RouteStore.forgot);
- })
-}
+ });
+};
export let getReset = function (req: Request, res: Response) {
User.findOne({ passwordResetToken: req.params.token, passwordResetExpires: { $gt: Date.now() } }, function (err, user: DashUserModel) {
@@ -205,7 +206,7 @@ export let getReset = function (req: Request, res: Response) {
user: req.user,
});
});
-}
+};
export let postReset = function (req: Request, res: Response) {
async.waterfall([
@@ -228,7 +229,8 @@ export let postReset = function (req: Request, res: Response) {
user.save(function (err) {
if (err) {
- return res.redirect(RouteStore.login);
+ res.redirect(RouteStore.login);
+ return;
}
req.logIn(user, function (err) {
if (err) {
@@ -261,4 +263,4 @@ export let postReset = function (req: Request, res: Response) {
], function (err) {
res.redirect(RouteStore.login);
});
-} \ No newline at end of file
+}; \ No newline at end of file
diff --git a/src/server/authentication/models/current_user_utils.ts b/src/server/authentication/models/current_user_utils.ts
index 0ac85b446..13eddafbf 100644
--- a/src/server/authentication/models/current_user_utils.ts
+++ b/src/server/authentication/models/current_user_utils.ts
@@ -70,7 +70,7 @@ export class CurrentUserUtils {
let doc = new Document(id);
doc.Set(KeyStore.Workspaces, new ListField<Document>());
- doc.Set(KeyStore.OptionalRightCollection, Documents.SchemaDocument([], { title: "Pending documents" }))
+ doc.Set(KeyStore.OptionalRightCollection, Documents.SchemaDocument([], { title: "Pending documents" }));
return doc;
}
@@ -81,7 +81,7 @@ export class CurrentUserUtils {
CurrentUserUtils.curr_id = obj.id as string;
CurrentUserUtils.curr_email = obj.email as string;
} else {
- throw new Error("There should be a user! Why does Dash think there isn't one?")
+ throw new Error("There should be a user! Why does Dash think there isn't one?");
}
});
let userDocPromise = rp.get(ServerUtils.prepend(RouteStore.getUserDocumentId)).then(id => {
@@ -92,9 +92,9 @@ export class CurrentUserUtils {
} else {
this.user_document = this.createUserDocument(id);
}
- })
+ });
} else {
- throw new Error("There should be a user id! Why does Dash think there isn't one?")
+ throw new Error("There should be a user id! Why does Dash think there isn't one?");
}
});
return Promise.all([userPromise, userDocPromise]);
diff --git a/src/server/authentication/models/user_model.ts b/src/server/authentication/models/user_model.ts
index 81580aad5..1c6926517 100644
--- a/src/server/authentication/models/user_model.ts
+++ b/src/server/authentication/models/user_model.ts
@@ -2,7 +2,7 @@
import * as bcrypt from "bcrypt-nodejs";
//@ts-ignore
import * as mongoose from "mongoose";
-var url = 'mongodb://localhost:27017/Dash'
+var url = 'mongodb://localhost:27017/Dash';
mongoose.connect(url, { useNewUrlParser: true });
diff --git a/src/server/database.ts b/src/server/database.ts
index 415acc09a..0bc806253 100644
--- a/src/server/database.ts
+++ b/src/server/database.ts
@@ -1,15 +1,15 @@
import * as mongodb from 'mongodb';
export class Database {
- public static Instance = new Database()
+ public static Instance = new Database();
private MongoClient = mongodb.MongoClient;
private url = 'mongodb://localhost:27017/Dash';
private db?: mongodb.Db;
constructor() {
this.MongoClient.connect(this.url, (err, client) => {
- this.db = client.db()
- })
+ this.db = client.db();
+ });
}
private currentWrites: { [_id: string]: Promise<void> } = {};
@@ -30,19 +30,19 @@ export class Database {
// console.log(JSON.stringify(res.result));
// }
if (this.currentWrites[id] === promise) {
- delete this.currentWrites[id]
+ delete this.currentWrites[id];
}
if (resolve) {
resolve();
}
callback();
});
- }
+ };
if (prom) {
const newProm: Promise<void> = prom.then(() => run(newProm));
this.currentWrites[id] = newProm;
} else {
- const newProm: Promise<void> = new Promise<void>(res => run(newProm, res))
+ const newProm: Promise<void> = new Promise<void>(res => run(newProm, res));
this.currentWrites[id] = newProm;
}
}
@@ -61,7 +61,7 @@ export class Database {
let collection = this.db.collection(collectionName);
collection.deleteMany({}, res);
}
- })
+ });
}
public insert(kvpairs: any) {
@@ -70,7 +70,7 @@ export class Database {
collection.insertOne(kvpairs, (err: any, res: any) => {
if (err) {
// console.log(err)
- return
+ return;
}
});
}
@@ -81,30 +81,30 @@ export class Database {
if (this.db) {
let collection = this.db.collection('documents');
collection.findOne({ _id: id }, (err: any, res: any) => {
- result = res
+ result = res;
if (!result) {
- fn(undefined)
+ fn(undefined);
}
- fn(result)
- })
- };
+ fn(result);
+ });
+ }
}
public getDocuments(ids: string[], fn: (res: any) => void) {
if (this.db) {
let collection = this.db.collection('documents');
- let cursor = collection.find({ _id: { "$in": ids } })
+ let cursor = collection.find({ _id: { "$in": ids } });
cursor.toArray((err, docs) => {
if (err) {
console.log(err.message);
console.log(err.errmsg);
}
fn(docs);
- })
- };
+ });
+ }
}
public print() {
- console.log("db says hi!")
+ console.log("db says hi!");
}
}
diff --git a/src/server/index.ts b/src/server/index.ts
index 17d7432e0..b9c7448b4 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -1,10 +1,10 @@
-import * as express from 'express'
-const app = express()
-import * as webpack from 'webpack'
+import * as express from 'express';
+const app = express();
+import * as webpack from 'webpack';
import * as wdm from 'webpack-dev-middleware';
import * as whm from 'webpack-hot-middleware';
-import * as path from 'path'
-import * as formidable from 'formidable'
+import * as path from 'path';
+import * as formidable from 'formidable';
import * as passport from 'passport';
import { MessageStore, Transferable } from "./Message";
import { Client } from './Client';
@@ -13,7 +13,7 @@ import { Utils } from '../Utils';
import { ObservableMap } from 'mobx';
import { FieldId, Field } from '../fields/Field';
import { Database } from './database';
-import * as io from 'socket.io'
+import * as io from 'socket.io';
import { getLogin, postLogin, getSignup, postSignup, getLogout, postReset, getForgot, postForgot, getReset } from './authentication/controllers/user_controller';
const config = require('../../webpack.config');
const compiler = webpack(config);
@@ -31,19 +31,19 @@ const MongoStore = require('connect-mongo')(session);
const mongoose = require('mongoose');
import { DashUserModel } from './authentication/models/user_model';
import * as fs from 'fs';
-import * as request from 'request'
+import * as request from 'request';
import { RouteStore } from './RouteStore';
-import { exec } from 'child_process'
+import { exec } from 'child_process';
const download = (url: string, dest: fs.PathLike) => {
request.get(url).pipe(fs.createWriteStream(dest));
-}
+};
const mongoUrl = 'mongodb://localhost:27017/Dash';
-mongoose.connect(mongoUrl)
+mongoose.connect(mongoUrl);
mongoose.connection.on('connected', function () {
console.log("connected");
-})
+});
// SESSION MANAGEMENT AND AUTHENTICATION MIDDLEWARE
// ORDER OF IMPORTS MATTERS
@@ -73,7 +73,7 @@ app.use((req, res, next) => {
app.get("/hello", (req, res) => {
res.send("<p>Hello</p>");
-})
+});
enum Method {
GET,
@@ -98,7 +98,7 @@ function addSecureRoute(method: Method,
const dashUser: DashUserModel = req.user;
if (!dashUser) return onRejection(res);
handler(dashUser, res, req);
- }
+ };
subscribers.forEach(route => {
switch (method) {
case Method.GET:
@@ -116,7 +116,7 @@ function addSecureRoute(method: Method,
let FieldStore: ObservableMap<FieldId, Field> = new ObservableMap();
app.use(express.static(__dirname + RouteStore.public));
-app.use(RouteStore.images, express.static(__dirname + RouteStore.public))
+app.use(RouteStore.images, express.static(__dirname + RouteStore.public));
app.get("/pull", (req, res) => {
exec('"C:\\Program Files\\Git\\git-bash.exe" -c "git pull"', (err, stdout, stderr) => {
@@ -125,7 +125,7 @@ app.get("/pull", (req, res) => {
return;
}
res.redirect("/");
- })
+ });
});
// GETTERS
@@ -143,7 +143,7 @@ addSecureRoute(
Method.GET,
(user, res, req) => {
let detector = new mobileDetect(req.headers['user-agent'] || "");
- if (detector.mobile() != null) {
+ if (detector.mobile() !== null) {
res.sendFile(path.join(__dirname, '../../deploy/mobile/image.html'));
} else {
res.sendFile(path.join(__dirname, '../../deploy/index.html'));
@@ -178,13 +178,13 @@ addSecureRoute(
addSecureRoute(
Method.POST,
(user, res, req) => {
- let form = new formidable.IncomingForm()
- form.uploadDir = __dirname + "/public/files/"
- form.keepExtensions = true
+ let form = new formidable.IncomingForm();
+ form.uploadDir = __dirname + "/public/files/";
+ form.keepExtensions = true;
// let path = req.body.path;
- console.log("upload")
+ console.log("upload");
form.parse(req, (err, fields, files) => {
- console.log("parsing")
+ console.log("parsing");
let names: any[] = [];
for (const name in files) {
let file = files[name];
@@ -211,8 +211,8 @@ app.post(RouteStore.login, postLogin);
app.get(RouteStore.logout, getLogout);
// FORGOT PASSWORD EMAIL HANDLING
-app.get(RouteStore.forgot, getForgot)
-app.post(RouteStore.forgot, postForgot)
+app.get(RouteStore.forgot, getForgot);
+app.post(RouteStore.forgot, postForgot);
// RESET PASSWORD EMAIL HANDLING
app.get(RouteStore.reset, getReset);
@@ -232,43 +232,41 @@ app.get(RouteStore.deleteAll, (req, res) => {
app.use(wdm(compiler, {
publicPath: config.output.publicPath
-}))
+}));
-app.use(whm(compiler))
+app.use(whm(compiler));
// start the Express server
app.listen(port, () => {
console.log(`server started at http://localhost:${port}`);
-})
+});
const server = io();
interface Map {
[key: string]: Client;
}
-let clients: Map = {}
+let clients: Map = {};
server.on("connection", function (socket: Socket) {
- console.log("a user has connected")
+ console.log("a user has connected");
- Utils.Emit(socket, MessageStore.Foo, "handshooken")
+ Utils.Emit(socket, MessageStore.Foo, "handshooken");
- Utils.AddServerHandler(socket, MessageStore.Bar, barReceived)
- Utils.AddServerHandler(socket, MessageStore.SetField, (args) => setField(socket, args))
- Utils.AddServerHandlerCallback(socket, MessageStore.GetField, getField)
- Utils.AddServerHandlerCallback(socket, MessageStore.GetFields, getFields)
- Utils.AddServerHandler(socket, MessageStore.DeleteAll, deleteFields)
-})
+ Utils.AddServerHandler(socket, MessageStore.Bar, barReceived);
+ Utils.AddServerHandler(socket, MessageStore.SetField, (args) => setField(socket, args));
+ Utils.AddServerHandlerCallback(socket, MessageStore.GetField, getField);
+ Utils.AddServerHandlerCallback(socket, MessageStore.GetFields, getFields);
+ Utils.AddServerHandler(socket, MessageStore.DeleteAll, deleteFields);
+});
function deleteFields() {
return Database.Instance.deleteAll();
}
-function deleteAll() {
- return Database.Instance.deleteAll().then(() => {
- return Database.Instance.deleteAll('sessions')
- }).then(() => {
- return Database.Instance.deleteAll('users')
- });
+async function deleteAll() {
+ await Database.Instance.deleteAll();
+ await Database.Instance.deleteAll('sessions');
+ await Database.Instance.deleteAll('users');
}
function barReceived(guid: String) {
@@ -278,12 +276,12 @@ function barReceived(guid: String) {
function getField([id, callback]: [string, (result: any) => void]) {
Database.Instance.getDocument(id, (result: any) => {
if (result) {
- callback(result)
+ callback(result);
}
else {
- callback(undefined)
+ callback(undefined);
}
- })
+ });
}
function getFields([ids, callback]: [string[], (result: any) => void]) {
@@ -293,7 +291,7 @@ function getFields([ids, callback]: [string[], (result: any) => void]) {
function setField(socket: Socket, newValue: Transferable) {
Database.Instance.update(newValue._id, newValue, () => {
socket.broadcast.emit(MessageStore.SetField.Message, newValue);
- })
+ });
}
server.listen(serverPort);
diff --git a/src/server/public/files/upload_a6a70d84ebb65febf7900e29f52cc86d.pdf b/src/server/public/files/upload_a6a70d84ebb65febf7900e29f52cc86d.pdf
deleted file mode 100644
index dfd6ab339..000000000
--- a/src/server/public/files/upload_a6a70d84ebb65febf7900e29f52cc86d.pdf
+++ /dev/null
Binary files differ