This repository has been archived by the owner on Aug 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
logger updated, better transports, creating logfiles. 🧦 upgrading 🧦 w…
…ebsockets 🧦 - allowing for rooms based on any resource id + type - backwards compat for existing streamId based approaches
- Loading branch information
1 parent
3fbb851
commit f091c37
Showing
50 changed files
with
203 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,36 @@ | ||
const jwt = require( 'jsonwebtoken' ) | ||
|
||
const winston = require( '../../../config/logger' ) | ||
const User = require( '../../../models/User' ) | ||
|
||
module.exports = function ( req, res ) { | ||
if ( !req.body.email ) return res.send( { success: false, message: 'Do not fuck with us' } ) | ||
if ( !req.body.password ) return res.send( { success: false, message: 'Do not fuck with us' } ) | ||
module.exports = function( req, res ) { | ||
if ( !req.body.email ) return res.status( 401 ).send( { success: false, message: 'Invalid credentials.' } ) | ||
if ( !req.body.password ) return res.status( 401 ).send( { success: false, message: 'Invalid credentials.' } ) | ||
|
||
let sessionSecret = process.env.SESSION_SECRET | ||
|
||
User.findOne( { 'email': req.body.email.toLowerCase() } ) | ||
User.findOne( { 'email': req.body.email.toLowerCase( ) } ) | ||
.then( myUser => { | ||
if ( !myUser ) throw new Error( 'Invalid credentials.' ) | ||
if ( !myUser ) { | ||
winston.error( 'Invalid credentials.' ) | ||
return res.status( 401 ).send( { success: false, message: 'Invalid credentials.' } ) | ||
} | ||
myUser.validatePassword( req.body.password, myUser.password, match => { | ||
if ( match === false ) { | ||
res.status( 401 ) | ||
return res.send( { success: false, message: 'Invalid credentials.' } ) | ||
winston.error( 'Invalid credentials.' ) | ||
return res.status( 401 ).send( { success: false, message: 'Invalid credentials.' } ) | ||
} | ||
myUser.logins.push( { date: Date.now() } ) | ||
myUser.save() | ||
myUser.logins.push( { date: Date.now( ) } ) | ||
myUser.save( ) | ||
let token = 'JWT ' + jwt.sign( { _id: myUser._id, name: myUser.name }, sessionSecret, { expiresIn: '24h' } ) | ||
let userObject = myUser.toObject() | ||
let userObject = myUser.toObject( ) | ||
userObject.token = token | ||
delete userObject[ 'password' ] | ||
res.send( { success: true, message: 'You have logged in.', resource: userObject } ) | ||
} ) | ||
} ) | ||
.catch( err => { | ||
res.status( 401 ) | ||
res.send( { success: false, message: err } ) | ||
winston.error( err ) | ||
res.status( 401 ).send( { success: false, message: err } ) | ||
} ) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,33 @@ | ||
'use strict' | ||
const winston = require( 'winston' ) | ||
const winston = require( '../../../config/logger' ) | ||
|
||
const User = require( '../../../models/User' ) | ||
|
||
// from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions | ||
const escapeRegExp = ( string ) => string.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' ) // $& means the whole matched string | ||
|
||
module.exports = function ( req, res ) { | ||
let conditions = {} | ||
if ( req.body.name ) conditions.name = { '$regex': escapeRegExp( req.body.name ), '$options': 'i' } | ||
if ( req.body.surname ) conditions.surname = { '$regex': escapeRegExp( req.body.surname ), '$options': 'i' } | ||
if ( req.body.company ) conditions.company = { '$regex': escapeRegExp( req.body.company ), '$options': 'i' } | ||
module.exports = function( req, res ) { | ||
let conditions = [ ] | ||
if ( !req.body.searchString || req.body.searchString === '' || req.body.searchString.length < 3 ) { | ||
return res.status( 400 ).send( { success: false, message: 'no search criteria present, or too short search string (must be > 2).' } ) | ||
} | ||
|
||
let projection = '_id name surname company' + ( req.app.get( 'expose emails' ) ? ' email' : '' ) | ||
if ( req.body.searchString ) { | ||
conditions.push( { name: { '$regex': escapeRegExp( req.body.searchString ), '$options': 'i' } } ) | ||
conditions.push( { surname: { '$regex': escapeRegExp( req.body.searchString ), '$options': 'i' } } ) | ||
conditions.push( { company: { '$regex': escapeRegExp( req.body.searchString ), '$options': 'i' } } ) | ||
} | ||
|
||
User.find( conditions, projection ).limit( 5 ) | ||
let projection = '_id name surname company' + ( process.env.EXPOSE_EMAILS ? ' email' : '' ) | ||
|
||
User.find( { $or: conditions }, projection ).limit( 10 ) | ||
.then( myUsers => { | ||
if ( !myUsers ) throw new Error( 'no users found.' ) | ||
res.send( { success: true, resources: myUsers } ) | ||
} ) | ||
.catch( err => { | ||
winston.error( err ) | ||
res.status( 400 ) | ||
res.send( { success: false, message: err.toString() } ) | ||
res.send( { success: false, message: err.toString( ) } ) | ||
} ) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.