-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into contribution-#26
- Loading branch information
Showing
63 changed files
with
581 additions
and
1,496 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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { createGetByIdRoute } from 'falcor-saddle'; | ||
|
||
import { CachedUser } from '../models/index'; | ||
|
||
export default [ | ||
createGetByIdRoute( | ||
'users', | ||
['createdAt', 'updatedAt', 'userId', 'email', | ||
'emailVerified', 'picture', 'name', 'nickname', | ||
'identities', 'loginsCount', 'blockedFor'], | ||
async (id) => CachedUser.getUserByUserId(id), | ||
(model, id) => model[id], | ||
'userId' | ||
), | ||
{ | ||
route: 'users.updateCacheWithToken', | ||
call: async (callPath, args) => { | ||
const [ idToken ] = args; | ||
const aUser = await CachedUser.updateWithToken(idToken); | ||
|
||
return [ | ||
{ | ||
path: ['users.updateCacheWithToken'], | ||
value: aUser.userId | ||
}, | ||
]; | ||
} | ||
} | ||
]; |
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import Database from './database'; | ||
import { AuthenticationClient } from 'auth0'; | ||
import config from '../../config/config'; | ||
|
||
const type = Database.type; | ||
const auth0 = new AuthenticationClient({ | ||
domain: config.auth0.domain, | ||
clientId: config.auth0.audience, | ||
}); | ||
|
||
export const CachedUser = Database.createModel('CachedUser', { | ||
// locally set: | ||
id: type.string(), | ||
cachedAt: type.date(), | ||
cacheExpiresAt: type.date().default(Database.r.now()), | ||
// from auth0: | ||
createdAt: type.date(), | ||
updatedAt: type.date(), | ||
userId: type.string(), | ||
email: type.string().email(), | ||
emailVerified: type.boolean().default(false), | ||
picture: type.string(), | ||
name: type.string(), | ||
nickname: type.string(), | ||
identities: type.array().default([]), | ||
loginsCount: type.number(), | ||
blockedFor: type.array().default([]) | ||
}); | ||
|
||
CachedUser.ensureIndex('userId'); | ||
|
||
function getUserByUserId(userId) { | ||
return new Promise( (resolve, reject) => { | ||
CachedUser.getAll(userId, { index: 'userId'}).limit(1) | ||
.then((result) => { | ||
// TODO: handle cache expiration here | ||
resolve(result[0]); | ||
}) | ||
.catch((error) => { | ||
reject(error); | ||
}); | ||
}); | ||
} | ||
|
||
CachedUser.defineStatic('getUserByUserId', getUserByUserId); | ||
|
||
async function updateWithToken(idToken) { | ||
const userInfo = await auth0.tokens.getInfo(idToken); | ||
let aUser = await CachedUser.getUserByUserId(userInfo.user_id); | ||
|
||
const fieldData = { | ||
createdAt: userInfo.created_at, | ||
updatedAt: userInfo.updated_at, | ||
userId: userInfo.user_id, | ||
email: userInfo.email, | ||
emailVerified: userInfo.email_verified, | ||
picture: userInfo.picture, | ||
name: userInfo.name, | ||
nickname: userInfo.nickname, | ||
identities: userInfo.identities, | ||
loginsCount: userInfo.logins_count, | ||
blockedFor: userInfo.blocked_for | ||
}; | ||
|
||
if (!aUser) { | ||
aUser = new CachedUser(fieldData); | ||
} else { | ||
await aUser.merge(fieldData); | ||
} | ||
await aUser.save(); | ||
|
||
return aUser; | ||
} | ||
|
||
CachedUser.defineStatic('updateWithToken', updateWithToken); |
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,3 +1,4 @@ | ||
|
||
export Database from './database'; | ||
export Meeting from './meeting'; | ||
export { Meeting } from './meeting'; | ||
export { CachedUser } from './cached_users'; |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
exports.up = (r, connection) => { // eslint-disable-line id-length | ||
r.tableCreate('Meeting').run(connection); | ||
return r.tableCreate('Session').run(connection); | ||
}; | ||
|
||
exports.down = (r, connection) => { // eslint-disable-line id-length | ||
r.tableDrop('Session').run(connection); | ||
return r.tableDrop('Meeting').run(connection); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
exports.up = function (r, connection) { | ||
return r.tableCreate('CachedUser').run(connection); | ||
}; | ||
|
||
exports.down = function (r, connection) { | ||
return r.tableDrop('CachedUser').run(connection); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/bin/bash | ||
|
||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
MIGRATE="${DIR}/../node_modules/.bin/rethink-migrate" | ||
|
||
development () | ||
{ | ||
source ${DIR}/../config/env/development.sh | ||
} | ||
|
||
production () | ||
{ | ||
source ${DIR}/../config/env/production.sh | ||
} | ||
|
||
case $NODE_ENV in | ||
development) | ||
echo "node development environment found" | ||
development | ||
;; | ||
production) | ||
echo "node production environment found" | ||
production | ||
;; | ||
*) | ||
echo "defaulting to node development environment" | ||
development | ||
;; | ||
esac | ||
|
||
case $1 in | ||
down) | ||
echo "will migrate down one" | ||
MIGRATE_ARGS="down" | ||
;; | ||
down-all) | ||
echo "will migrate down all" | ||
MIGRATE_ARGS="down -a" | ||
;; | ||
up) | ||
echo "will migrate up one" | ||
MIGRATE_ARGS="up" | ||
;; | ||
up-all) | ||
echo "will migrate up all" | ||
MIGRATE_ARGS="up -a" | ||
;; # no fallthough in bash < 4.0 | ||
*) | ||
echo "will migrate up all" | ||
MIGRATE_ARGS="up -a" | ||
;; | ||
esac | ||
|
||
${MIGRATE} ${MIGRATE_ARGS} -a --host $RETHINK_DB_HOST --port $RETHINK_DB_PORT \ | ||
--db $RETHINK_DB_NAME -r ${DIR}/../api/models/ | ||
|
Oops, something went wrong.