From 33aef7433ca6fa14565809f21422398f0409892f Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 9 Sep 2018 11:06:26 +0200 Subject: [PATCH 01/16] Logging in working again. --- client/src/auth/index.js | 2 +- client/src/components/LoggedInUser.js | 3 +++ client/src/components/NavBar.js | 15 ++------------- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/client/src/auth/index.js b/client/src/auth/index.js index e7d84336c..a8528584d 100644 --- a/client/src/auth/index.js +++ b/client/src/auth/index.js @@ -128,7 +128,7 @@ class Auth { }) console.log('signinOrCreateAccount auth: ', await data) - setItem('user', data.data.authenticate.authId) + setItem('user', JSON.stringify(data.data.authenticate)) if (window.location.href.includes(`callback`)) { window.location.href = '/' } else { diff --git a/client/src/components/LoggedInUser.js b/client/src/components/LoggedInUser.js index 71c3e6ab4..196618322 100644 --- a/client/src/components/LoggedInUser.js +++ b/client/src/components/LoggedInUser.js @@ -11,6 +11,9 @@ class LoggedInUser extends Component { const user = this.props.data.userByAuthId; + console.log('loggedInUser'); + console.log(user); + if(user){ console.log(user.firstName); diff --git a/client/src/components/NavBar.js b/client/src/components/NavBar.js index b590ef192..dca0cce59 100644 --- a/client/src/components/NavBar.js +++ b/client/src/components/NavBar.js @@ -49,24 +49,13 @@ class NavBar extends Component { } componentDidMount() { - /* - this._asyncRequest = window.localStorage.getItem('user').then( - response => { - this._asyncRequest = null; - let user = JSON.parse(response) - if (user) { - const authId = user.sub; - this.setState({ authId: authId }); - } - } - ); - */ + const userStored = localStorage.getItem('user'); console.log(userStored); if (userStored !== null && userStored !== undefined && userStored !== 'undefined') { const user = JSON.parse(userStored); - const authId = user.sub; + const authId = user.authId; this.setState({ authId: authId }); } } From 5858ec16249104cfd2a9d0c95d910b7b7ef30983 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 9 Sep 2018 11:09:28 +0200 Subject: [PATCH 02/16] Refactoring file name to Auth --- client/src/App.js | 2 +- client/src/auth/{index.js => Auth.js} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename client/src/auth/{index.js => Auth.js} (100%) diff --git a/client/src/App.js b/client/src/App.js index 0d9c6428a..03c3cd676 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -24,7 +24,7 @@ import Post from './components/Post'; import Footer from './components/Footer'; import Callback from './components/Callback'; -import Auth from './auth/index'; +import Auth from './auth/Auth'; // Apollo Client Setup const httpLink = new HttpLink({ uri: 'http://localhost:4000/graphql', changeOrigin: true }) diff --git a/client/src/auth/index.js b/client/src/auth/Auth.js similarity index 100% rename from client/src/auth/index.js rename to client/src/auth/Auth.js From 67c1dba5d80f25fec71efb5200c56fac24a01deb Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 9 Sep 2018 11:23:46 +0200 Subject: [PATCH 03/16] Really logging out now. --- client/src/components/Logout.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/src/components/Logout.js b/client/src/components/Logout.js index 4876ab330..0989985f7 100644 --- a/client/src/components/Logout.js +++ b/client/src/components/Logout.js @@ -1,9 +1,11 @@ import React, { Component } from 'react'; import {Redirect} from 'react-router'; +import {auth} from '../App'; class Logout extends Component { render() { - window.localStorage.removeItem("user"); + //window.localStorage.removeItem("user"); + auth.logout(); return } From 4f4447f1424b817545146428af60daefa9e75a30 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 9 Sep 2018 11:36:02 +0200 Subject: [PATCH 04/16] Cleaninig sample code --- client/src/hoc/Rainbow.js | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 client/src/hoc/Rainbow.js diff --git a/client/src/hoc/Rainbow.js b/client/src/hoc/Rainbow.js deleted file mode 100644 index 9af9ca298..000000000 --- a/client/src/hoc/Rainbow.js +++ /dev/null @@ -1,17 +0,0 @@ -import React from 'react' - -const Rainbow = (WrappedComponent) => { - - const colours = ['red', 'pink', 'orange', 'blue', 'green', 'yellow']; - const randomColour = colours[Math.floor(Math.random() * 6)]; - const className = randomColour + '-text'; - - return (props) => ( -
- -
- ) - -} - -export default Rainbow From 76da420e2afd070d6891b1f011c5e5a3f51a5a4a Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 9 Sep 2018 11:57:28 +0200 Subject: [PATCH 05/16] Saving relevant data to MongoDb --- server/schema/schema.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/server/schema/schema.js b/server/schema/schema.js index c7e0c2326..104437fdc 100644 --- a/server/schema/schema.js +++ b/server/schema/schema.js @@ -133,17 +133,23 @@ const Mutation = new GraphQLObjectType({ let userToken = null; return validateParseIdToken(idToken) - .then(result => { - console.log('validateParseIdToken', result); - const authId = result.sub; - const alias = result.nickname; + .then(authProviderResponse => { + + console.log('validateParseIdToken', authProviderResponse); + + const authId = authProviderResponse.sub; + const alias = authProviderResponse.nickname; + const email = authProviderResponse.email; + const emailVerified = authProviderResponse.email_verified; let user = new User({ - alias: alias, - authId: authId, + alias: authId, + authId: alias, + email: email, + emailVerified: emailVerified, roleId: "1" }); - console.log(authId, alias); + user.save(); return { authId, alias }; }) From 4490041a8abc28d3ae1c03e1d2f7a3475b90996b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 9 Sep 2018 19:46:24 +0200 Subject: [PATCH 06/16] No more promises except the needed ones --- client/src/components/LoggedInUser.js | 4 +- client/src/components/NavBar.js | 4 +- server/app.js | 36 +++++- server/auth/TokenDecoder.js | 91 +++++++++++++ server/auth/directives.js | 69 ---------- server/schema/schema.js | 176 +++++++++++++++++++------- 6 files changed, 258 insertions(+), 122 deletions(-) create mode 100644 server/auth/TokenDecoder.js delete mode 100644 server/auth/directives.js diff --git a/client/src/components/LoggedInUser.js b/client/src/components/LoggedInUser.js index 196618322..1405419f1 100644 --- a/client/src/components/LoggedInUser.js +++ b/client/src/components/LoggedInUser.js @@ -11,8 +11,8 @@ class LoggedInUser extends Component { const user = this.props.data.userByAuthId; - console.log('loggedInUser'); - console.log(user); + console.log('loggedInUser data', this.props.data); + console.log('loggedInUser', user); if(user){ diff --git a/client/src/components/NavBar.js b/client/src/components/NavBar.js index dca0cce59..c89223a71 100644 --- a/client/src/components/NavBar.js +++ b/client/src/components/NavBar.js @@ -55,7 +55,9 @@ class NavBar extends Component { if (userStored !== null && userStored !== undefined && userStored !== 'undefined') { const user = JSON.parse(userStored); - const authId = user.authId; + const authId = user.sub; + console.log("user", user); + console.log("authid", authId); this.setState({ authId: authId }); } } diff --git a/server/app.js b/server/app.js index d97f8fc1d..f60c91372 100644 --- a/server/app.js +++ b/server/app.js @@ -1,3 +1,35 @@ +/* Debugging */ + +global.INFO_LOG = true; +global.ERROR_LOG = true; + +/* Callbacks default responses. */ + +global.DEFAULT_OK_RESPONSE = { + result: "Ok", + message: "Operation Succeeded" +}; + +global.DEFAULT_FAIL_RESPONSE = { + result: "Fail", + message: "Operation Failed" +}; + +global.DEFAULT_RETRY_RESPONSE = { + result: "Retry", + message: "Retry Later" +}; + +global.CUSTOM_OK_RESPONSE = { + result: "Ok, but check Message", + message: "Custom Message" +}; + +global.CUSTOM_FAIL_RESPONSE = { + result: "Fail Because", + message: "Custom Message" +}; + const express = require('express'); const graphqlHTTP = require('express-graphql'); const schema = require('./schema/schema'); @@ -19,6 +51,8 @@ mongoose.connection.once('open', () => { console.log('Connected to database'); }) +/* Here we bind all requests to this endpoint to be procecced by the GraphQL Library. */ + app.get('/graphql', graphqlHTTP({ schema, graphiql: true @@ -39,8 +73,6 @@ app.post('/graphql', checkJwt, (err, req, res, next) => { app.post('/graphql', (req, res, done) => getUser(req, res, done)); - - app.listen(4000,() => { console.log('Now listening for requests on port 4000'); }); diff --git a/server/auth/TokenDecoder.js b/server/auth/TokenDecoder.js new file mode 100644 index 000000000..870d3d555 --- /dev/null +++ b/server/auth/TokenDecoder.js @@ -0,0 +1,91 @@ +const MODULE_NAME = "TokenDecoder"; + +/* + JSON Web Token (JWT) is a compact, URL-safe means of representing + claims to be transferred between two parties. The claims in a JWT + are encoded as a JSON object that is used as the payload of a JSON + Web Signature (JWS) structure or as the plaintext of a JSON Web + Encryption (JWE) structure, enabling the claims to be digitally + signed or integrity protected with a Message Authentication Code + (MAC) and/or encrypted. +*/ + +const JSONWebToken = require('jsonwebtoken'); // A library to deal with JSON Web Tokens. +const webTokenLibrary = require('jwks-rsa'); // A library to retrieve RSA signing keys from a JWKS (JSON Web Key Set) endpoint. + +const AUTH_CONFIG = require('./Auth0'); // Config where we have our secrets. + +const decoder = webTokenLibrary({ + cache: true, + rateLimit: true, + jwksRequestsPerMinute: 1, + jwksUri: `https://${AUTH_CONFIG.domain}/.well-known/jwks.json` +}) + +function decodeToken (token, callBackFunction) { + + try{ + + if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> decodeToken -> Entering function."); } + + const decoded = JSONWebToken.decode(token, { complete: true }); + const header = decoded.header; + const payload = decoded.payload; + + if ( + header === null || + header.kid === null || + payload === null + ) { + if (global.ERROR_LOG === true) { console.log ("[ERROR] " + MODULE_NAME + " -> decodeToken -> Invalid Token. "); } + if (global.ERROR_LOG === true) { console.log ("[ERROR] " + MODULE_NAME + " -> decodeToken -> token = " + token); } + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + + decoder.getSigningKey(header.kid, onKeyReady); + + function onKeyReady(err, key) { + + if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> decodeToken -> onKeyReady -> Entering function."); } + + if (err) { + + if (global.ERROR_LOG === true) { console.log ("[ERROR] " + MODULE_NAME + " -> decodeToken -> onKeyReady -> Error getting the key. "); } + if (global.ERROR_LOG === true) { console.log ("[ERROR] " + MODULE_NAME + " -> decodeToken -> onKeyReady -> key = " + key); } + if (global.ERROR_LOG === true) { console.log ("[ERROR] " + MODULE_NAME + " -> decodeToken -> onKeyReady -> err = " + err); } + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + + JSONWebToken.verify( + token, + key.publicKey, + { algorithms: ['RS256'] }, + onVerified); + + function onVerified(err, decoded) { + + if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> decodeToken -> onKeyReady -> onVerified -> Entering function."); } + + if (err) { + + if (global.ERROR_LOG === true) { console.log ("[ERROR] " + MODULE_NAME + " -> decodeToken -> onKeyReady -> onVerified -> Error verifying. "); } + if (global.ERROR_LOG === true) { console.log ("[ERROR] " + MODULE_NAME + " -> decodeToken -> onKeyReady -> onVerified -> decoded = " + decoded); } + if (global.ERROR_LOG === true) { console.log ("[ERROR] " + MODULE_NAME + " -> decodeToken -> onKeyReady -> onVerified -> err = " + err); } + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; + } + + callBackFunction(global.DEFAULT_OK_RESPONSE, decoded); + } + } + } catch(err) { + + if (global.ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> decodeToken -> err = " + err); } + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + + } +} + +module.exports = decodeToken; diff --git a/server/auth/directives.js b/server/auth/directives.js deleted file mode 100644 index 8111ab2cd..000000000 --- a/server/auth/directives.js +++ /dev/null @@ -1,69 +0,0 @@ -const _get = require('lodash.get') -const validateParseIdToken = require('./validate-auth0-token') -const createUser = require('./index') - -const userLocationOnContext = 'request.user' -const bearerAccessToken = 'request.headers.authorization' - -const ctxUser = ctx => _get(ctx, userLocationOnContext) -const ctxToken = ctx => _get(ctx, bearerAccessToken) - -const isLoggedIn = async ctx => { - let user = ctxUser(ctx, userLocationOnContext) - let token = ctxToken(ctx, bearerAccessToken) - let userToken - - if (!user && token) { - let scheme, credentials - const tokenParts = token.split(' ') - if (tokenParts.length === 2) { - scheme = tokenParts[0] - credentials = tokenParts[1] - } - - if (/^Bearer$/i.test(scheme)) { - token = credentials - //verify token - try { - userToken = await validateParseIdToken(token) - const auth0id = userToken.sub - - user = await ctx.db.query.user({ where: { auth0id } }) - - if (!user) { - user = await createUser(ctx, userToken) - } - } catch (err) { - userToken = false - } - } - } - - if (!user) { - throw new Error(`Not logged in`) - } - return user -} - - -const isRequestingUserAlsoOwner = ({ ctx, userId, type, typeId }) => - ctx.db.exists[type]({ id: typeId, owner: { auth0id: userId } }) -const isRequestingUser = ({ ctx, userId }) => ctx.db.exists.User({ auth0id: userId }) - -const directiveResolvers = { - isAuthenticated: async (next, source, args, ctx) => { - let result = await isLoggedIn(ctx) - console.log('directive isAuthenticated: ', result) - return next(result) - }, - hasRole: (next, source, { roles }, ctx) => { - const { role } = isLoggedIn(ctx) - console.log('directive hasRole: ', role) - if (roles.includes(role)) { - return next() - } - throw new Error(`Unauthorized, incorrect role`) - } -} - -module.exports = { directiveResolvers } diff --git a/server/schema/schema.js b/server/schema/schema.js index 104437fdc..d1c188824 100644 --- a/server/schema/schema.js +++ b/server/schema/schema.js @@ -1,8 +1,10 @@ +const MODULE_NAME = "schema"; + const graphql = require('graphql'); const _ = require('lodash'); const User = require('../models/user'); -const validateParseIdToken = require('../auth/validate-auth0-token'); +const tokenDecoder = require('../auth/TokenDecoder'); const { GraphQLObjectType, @@ -79,19 +81,59 @@ const RootQuery = new GraphQLObjectType({ resolve(parent,args) { // Code to get data from data source. + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Entering function."); } + return new Promise((resolve, reject) => { - User.findOne({authId: args.authId}, (err, user) => { - if(err) reject(err); - else{ + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> Entering function."); } - if (user.authId === args.authId && user.authId !== undefined) { - return resolve(user); - } else { - return null; + if (args.authId === null || args.authId === undefined) { + + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> User requested not specified."); } + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> args.authId = " + args.authId); } + + reject({ error: "No user specified" }); + return; + } + + User.findOne({authId: args.authId}, onUserReceived) + + function onUserReceived(err, user) { + if(err) { + if (ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserReceived -> Database Error."); } + if (ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserReceived -> err = " + err); } + reject(err); + } + else{ + + if (user === null) { + + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserReceived -> User not found at Database."); } + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserReceived -> args.authId = " + args.authId); } + + resolve({}); + return; + } + + if (user.authId === args.authId && user.authId !== undefined) { + + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserReceived -> User found at Database."); } + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserReceived -> args.authId = " + args.authId); } + + resolve(user); + return; + + } else { + + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserReceived -> User found at Database is not the user requested."); } + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserReceived -> args.authId = " + args.authId); } + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserReceived -> user.authId = " + user.authId); } + + resolve({}); + return; + } } } - }) }) } @@ -125,51 +167,36 @@ const Mutation = new GraphQLObjectType({ name: 'Mutation', fields: { authenticate: { - type: UserType, - args: { - idToken: {type: new GraphQLNonNull(GraphQLString)} - }, - resolve(parent, { idToken }) { - let userToken = null; - - return validateParseIdToken(idToken) - .then(authProviderResponse => { - - console.log('validateParseIdToken', authProviderResponse); - - const authId = authProviderResponse.sub; - const alias = authProviderResponse.nickname; - const email = authProviderResponse.email; - const emailVerified = authProviderResponse.email_verified; - - let user = new User({ - alias: authId, - authId: alias, - email: email, - emailVerified: emailVerified, - roleId: "1" - }); - - user.save(); - return { authId, alias }; - }) - .catch(err => { return {error: err } }) - } - }, - addUser:{ type: UserType, args: { - alias: {type: new GraphQLNonNull(GraphQLString)}, - authId: {type: new GraphQLNonNull(GraphQLString)} + idToken: {type: new GraphQLNonNull(GraphQLString)} }, resolve(parent, args) { - let user = new User({ - alias: args.alias, - authId: args.authId, - roleId: "1" + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> Mutation -> authenticate -> resolve -> Entering function."); } + + /* In order to be able to wait for asyc calls to the database, and authorization authority, we need to return a promise to GraphQL. */ + + const promiseToGraphQL = new Promise((resolve, reject) => { + + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> Mutation -> authenticate -> resolve -> Promise -> Entering function."); } + authenticate(args.idToken, onAuthenticated); + + function onAuthenticated(err, responseToGraphQL) { + + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> Mutation -> authenticate -> resolve -> Promise -> onAuthenticated -> Entering function."); } + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> Mutation -> authenticate -> resolve -> Promise -> onAuthenticated -> responseToGraphQL = " + JSON.stringify(responseToGraphQL)); } + + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + if (global.ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> authenticate -> onValidated -> err.message = " + err.message); } + reject (responseToGraphQL); + } else { + resolve (responseToGraphQL); + } + } }); - return user.save(); + + return promiseToGraphQL; } }, updateUser:{ @@ -210,6 +237,59 @@ const Mutation = new GraphQLObjectType({ } }) +function authenticate(encodedToken, callBackFunction) { + +try { + + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> authenticate -> Entering function."); } + + let authId = ""; + let alias = ""; + let email = ""; + let emailVerified = false; + + tokenDecoder(encodedToken, onValidated); + + function onValidated(err, decodedToken) { + + if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> authenticate -> onValidated -> Entering function."); } + + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + if (global.ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> authenticate -> onValidated -> err.message = " + err.message); } + callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err }); + return; + } + + authId = decodedToken.sub; + alias = decodedToken.nickname; + email = decodedToken.email; + emailVerified = decodedToken.email_verified; + + /* The authenticated user is NOT at our module database. We need to add him. */ + + let newUser = new User({ + alias: alias, + authId: authId, + email: email, + emailVerified: emailVerified, + roleId: "1" + }); + + if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> authenticate -> onValidated -> " + alias + " being added to the database"); } + + newUser.save(); + + callBackFunction(global.DEFAULT_OK_RESPONSE, { authId, alias }); + + } + } catch(err) { + + if (global.ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> authenticate -> err.message = " + err.message); } + callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err }); + + } +} + module.exports = new GraphQLSchema({ query: RootQuery, mutation: Mutation From 6f3c02cae0d3db39aadf04ad67e32be13c550480 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 9 Sep 2018 20:32:53 +0200 Subject: [PATCH 07/16] FindByAuthId function sent out of the schema const --- client/src/components/NavBar.js | 2 +- server/schema/schema.js | 130 +++++++++++++++++++++----------- 2 files changed, 85 insertions(+), 47 deletions(-) diff --git a/client/src/components/NavBar.js b/client/src/components/NavBar.js index c89223a71..7ce5477a9 100644 --- a/client/src/components/NavBar.js +++ b/client/src/components/NavBar.js @@ -55,7 +55,7 @@ class NavBar extends Component { if (userStored !== null && userStored !== undefined && userStored !== 'undefined') { const user = JSON.parse(userStored); - const authId = user.sub; + const authId = user.authId; console.log("user", user); console.log("authid", authId); this.setState({ authId: authId }); diff --git a/server/schema/schema.js b/server/schema/schema.js index d1c188824..9029794df 100644 --- a/server/schema/schema.js +++ b/server/schema/schema.js @@ -79,62 +79,34 @@ const RootQuery = new GraphQLObjectType({ type: UserType, args: {authId: {type: GraphQLString}}, resolve(parent,args) { - // Code to get data from data source. + // Code to get data from data source. if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Entering function."); } - return new Promise((resolve, reject) => { + /* In order to be able to wait for asyc calls to the database, we need to return a promise to GraphQL. */ + + const promiseToGraphQL = new Promise((resolve, reject) => { if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> Entering function."); } + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> args.authId = " + args.authId); } - if (args.authId === null || args.authId === undefined) { + findUserByAuthId(args.authId, onUserFound); - if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> User requested not specified."); } - if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> args.authId = " + args.authId); } + function onUserFound(err, responseToGraphQL) { - reject({ error: "No user specified" }); - return; - } + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserFound -> Entering function."); } + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserFound -> responseToGraphQL = " + JSON.stringify(responseToGraphQL)); } - User.findOne({authId: args.authId}, onUserReceived) - - function onUserReceived(err, user) { - if(err) { - if (ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserReceived -> Database Error."); } - if (ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserReceived -> err = " + err); } - reject(err); - } - else{ - - if (user === null) { - - if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserReceived -> User not found at Database."); } - if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserReceived -> args.authId = " + args.authId); } - - resolve({}); - return; - } - - if (user.authId === args.authId && user.authId !== undefined) { - - if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserReceived -> User found at Database."); } - if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserReceived -> args.authId = " + args.authId); } - - resolve(user); - return; - - } else { - - if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserReceived -> User found at Database is not the user requested."); } - if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserReceived -> args.authId = " + args.authId); } - if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserReceived -> user.authId = " + user.authId); } - - resolve({}); - return; - } + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + if (global.ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Promise -> onUserFound -> err.message = " + err.message); } + reject (responseToGraphQL); + } else { + resolve (responseToGraphQL); } } - }) + }); + + return promiseToGraphQL; } }, @@ -188,7 +160,7 @@ const Mutation = new GraphQLObjectType({ if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> Mutation -> authenticate -> resolve -> Promise -> onAuthenticated -> responseToGraphQL = " + JSON.stringify(responseToGraphQL)); } if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - if (global.ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> authenticate -> onValidated -> err.message = " + err.message); } + if (global.ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> Mutation -> authenticate -> resolve -> Promise -> onAuthenticated -> err.message = " + err.message); } reject (responseToGraphQL); } else { resolve (responseToGraphQL); @@ -237,6 +209,72 @@ const Mutation = new GraphQLObjectType({ } }) + +function findUserByAuthId(authId, callBackFunction) { + + try { + + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> Entering function."); } + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> authId = " + authId); } + + if (authId === null || authId === undefined) { + + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> User requested not specified."); } + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> args.authId = " + authId); } + + callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: "Bad Request" }); + return; + } + + User.findOne({authId: authId}, onUserReceived) + + function onUserReceived(err, user) { + + if(err) { + if (ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> findUserByAuthId -> onUserReceived -> Database Error."); } + if (ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> findUserByAuthId -> onUserReceived -> err = " + err); } + callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err }); + } + else{ + + if (user === null) { + + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> onUserReceived -> User not found at Database."); } + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> onUserReceived -> args.authId = " + authId); } + + callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err }); + return; + } + + if (user.authId === authId && user.authId !== undefined) { + + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> onUserReceived -> User found at Database."); } + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> onUserReceived -> args.authId = " + authId); } + + callBackFunction(global.DEFAULT_OK_RESPONSE, user); + return; + + } else { + + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> onUserReceived -> User found at Database is not the user requested."); } + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> onUserReceived -> args.authId = " + authId); } + if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> onUserReceived -> user.authId = " + user.authId); } + + callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err }); + return; + } + } + } + } catch(err) { + + if (global.ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> findUserByAuthId -> err.message = " + err.message); } + callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err }); + + } +} + + + function authenticate(encodedToken, callBackFunction) { try { From 64101169d45324f6dfc9557f776c8e8a13ad9d24 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 9 Sep 2018 21:07:54 +0200 Subject: [PATCH 08/16] No more duplication of recors at database --- client/src/components/NavBar.js | 11 ++++++- server/schema/schema.js | 58 +++++++++++++++++++++++++-------- 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/client/src/components/NavBar.js b/client/src/components/NavBar.js index 7ce5477a9..5b02b375d 100644 --- a/client/src/components/NavBar.js +++ b/client/src/components/NavBar.js @@ -55,7 +55,16 @@ class NavBar extends Component { if (userStored !== null && userStored !== undefined && userStored !== 'undefined') { const user = JSON.parse(userStored); - const authId = user.authId; + + /* For some reason, the result of GraphQL some times varies, that is why I had to do the following hack. */ + + let authId; + if (user.authId === undefined) { + authId = user.sub; + } else { + authId = user.authId; + } + console.log("user", user); console.log("authid", authId); this.setState({ authId: authId }); diff --git a/server/schema/schema.js b/server/schema/schema.js index 9029794df..7e06a1a6c 100644 --- a/server/schema/schema.js +++ b/server/schema/schema.js @@ -79,7 +79,7 @@ const RootQuery = new GraphQLObjectType({ type: UserType, args: {authId: {type: GraphQLString}}, resolve(parent,args) { - // Code to get data from data source. + // Code to get data from data source. if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> RootQuery -> userByAuthId -> resolve -> Entering function."); } @@ -242,7 +242,12 @@ function findUserByAuthId(authId, callBackFunction) { if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> onUserReceived -> User not found at Database."); } if (INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> findUserByAuthId -> onUserReceived -> args.authId = " + authId); } - callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err }); + let customResponse = { + result: global.CUSTOM_OK_RESPONSE.result, + message: "User Not Found" + }; + + callBackFunction(customResponse, { error: customResponse.message }); return; } @@ -303,22 +308,49 @@ try { email = decodedToken.email; emailVerified = decodedToken.email_verified; - /* The authenticated user is NOT at our module database. We need to add him. */ + findUserByAuthId(authId, onUserFound); - let newUser = new User({ - alias: alias, - authId: authId, - email: email, - emailVerified: emailVerified, - roleId: "1" - }); + function onUserFound(err, user){ - if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> authenticate -> onValidated -> " + alias + " being added to the database"); } + if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> authenticate -> onValidated -> onUserFound -> Entering function."); } - newUser.save(); + if (err.result === global.DEFAULT_FAIL_RESPONSE.result) { + if (global.ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> authenticate -> onValidated -> onUserFound -> err.message = " + err.message); } + callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err }); + return; + } - callBackFunction(global.DEFAULT_OK_RESPONSE, { authId, alias }); + if (err.result === global.DEFAULT_OK_RESPONSE.result) { + if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> authenticate -> onValidated -> onUserFound -> User already exists at database"); } + callBackFunction(global.DEFAULT_OK_RESPONSE, { authId: authId, alias: user.alias }); + return; + } + if ( + err.result === global.CUSTOM_OK_RESPONSE.result && + err.message === "User Not Found" + ) { + + if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> authenticate -> onValidated -> onUserFound -> User does not exist at database"); } + + /* The authenticated user is NOT at our module database. We need to add him. */ + + let newUser = new User({ + alias: alias, + authId: authId, + email: email, + emailVerified: emailVerified, + roleId: "1" + }); + + if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> authenticate -> onValidated -> onUserFound -> " + alias + " being added to the database"); } + + newUser.save(); + + callBackFunction(global.DEFAULT_OK_RESPONSE, { authId, alias }); + + } + } } } catch(err) { From 307b77535df4c87ca8b6271ad288d8d9f4f49886 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 10 Sep 2018 11:29:46 +0200 Subject: [PATCH 09/16] code cleaning --- client/src/auth/Auth.js | 2 -- client/src/components/LoggedInUser.js | 7 ------- client/src/components/NavBar.js | 5 +---- client/src/index.js | 7 ------- client/src/pokeball.png | Bin 16150 -> 0 bytes client/src/reducers/rootReducer.js | 15 --------------- 6 files changed, 1 insertion(+), 35 deletions(-) delete mode 100644 client/src/pokeball.png delete mode 100644 client/src/reducers/rootReducer.js diff --git a/client/src/auth/Auth.js b/client/src/auth/Auth.js index a8528584d..b221ae134 100644 --- a/client/src/auth/Auth.js +++ b/client/src/auth/Auth.js @@ -8,8 +8,6 @@ import { client } from '../App' import { AUTH_CONFIG } from './Auth0' // create by renaming Auth0.sample.js to Auth0.js and setting vars -console.log(process.env.AUTH0_CLIENTID) - const AUTHENTICATE = gql` mutation authenticate($idToken: String!) { authenticate(idToken: $idToken) { diff --git a/client/src/components/LoggedInUser.js b/client/src/components/LoggedInUser.js index 1405419f1..fbbfa8269 100644 --- a/client/src/components/LoggedInUser.js +++ b/client/src/components/LoggedInUser.js @@ -11,15 +11,8 @@ class LoggedInUser extends Component { const user = this.props.data.userByAuthId; - console.log('loggedInUser data', this.props.data); - console.log('loggedInUser', user); - if(user){ - console.log(user.firstName); - console.log(user.lastName ); - console.log(user.alias); - let displayName = "No Display Name"; if ( diff --git a/client/src/components/NavBar.js b/client/src/components/NavBar.js index 5b02b375d..8d210e23b 100644 --- a/client/src/components/NavBar.js +++ b/client/src/components/NavBar.js @@ -51,7 +51,6 @@ class NavBar extends Component { componentDidMount() { const userStored = localStorage.getItem('user'); - console.log(userStored); if (userStored !== null && userStored !== undefined && userStored !== 'undefined') { const user = JSON.parse(userStored); @@ -64,9 +63,7 @@ class NavBar extends Component { } else { authId = user.authId; } - - console.log("user", user); - console.log("authid", authId); + this.setState({ authId: authId }); } } diff --git a/client/src/index.js b/client/src/index.js index 9c47566b0..395b74997 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -2,12 +2,5 @@ import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; import App from './App'; -//import {createStore} from 'redux'; -//import {Provider} from 'reaxt-redux'; -//import rootReducer from './reducers/rootReducer'; - -//const store = createStore(rootReducer); - -//ReactDOM.render(, document.getElementById('root')); ReactDOM.render(, document.getElementById('root')); diff --git a/client/src/pokeball.png b/client/src/pokeball.png deleted file mode 100644 index f5eff9cffcf87e8692b99f2adea46e2894b491d8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16150 zcmaL8by!x>w>A3GjdUX=Al)g_-6(^JAudvei6G#>9}b) zTDp0fxL82M%pFZFDCO);tSr_Awq^q6 z)FQ%^LSBMk0DB8J6G|_8I|o-muea3yHLf7|``^cG)Rg~qh@0(O>i=_7I!daP5{@nw zlsv4wEM^?soRoY5tQ@@T0-W5;l$`7wd~ED|Y#dxH>>PsZynhxj4X);5ZYiiP zDgEEq0{^|GhPt^q39_+ydU~>Ya; zN4x*LMOCPyo1-h#(TP$*;@?~2r+lq#?O^Wc>B{h5=O`%&$~m~YnK+nP$VtAX2BWZA zTbm1V2yn0qh)eMEO9}9Da7gisvr7m_@=J+HvI|J_aPo@(=UhogGk1Fn2e<#6YyN-F z75HDz{TB}QPTe|NFi0{;%Wx_qpc(`@Qh}ujjIXn_>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aLKtI0d?{QeCoLf zB3dvgPfTsQNkxo9^}YXK4Dq*0Beui$z83d-b0i#;<`sWyK`2Evc8py1o&FIMjWg+J zYiS8{+n+X}A1%c`^;Jy?{tKRHlwLV!Urc))AkMaPGJzT?i91wGLqkK`!8r1Vw@ZR3 z_lpjhU4+&{GkJhgV3k?sU`{mk|8a`j)d6}}cOO8ROg7uE+{FJ2>DLBrZjx#cXE!%D zhQPq*ujR_Q7yoqd>_30J(0-=pX#esb`(CBh&IgR^C@gx7{Do8g1-C&FSjZE6_RHMX zfB{Gz@oF4LyY=-If4*_?8-t712`w|a*{TzgQI3xx)-CmbDv?~R$ zx>P_G-u3037n7_3o}`2Lv5xSbw7NnSRO)uyTeu zw6wMTba!#_iS9cQnf0yuw}@9T6YgCjPmd2sc57|!vtVc4C(-wNo*dp?hB!3h z>?XppyH5IX5(o-hb-$8=2{97w2pf(3I&HJ>ETB@pf*St;6q5QpW2MbnJ#Jkr) z+#I~`udML_&{Bp!WBunULZ)C9#c+}cB_v3nPze@8!Gary-)sa*w!SUk7ZU;ec+y=} zzQTJWx|c@CW~kZ6nho|0JpeGp9TgqT7*9(AL0SkSSl|mX>ky?X2!=6NtpGq%s-?9R zf!ksA&nu5NYEo4#an^N+ZVqzt^8btgURb9N@{J`2zz}KM1=@OX;8iE{hd-V$LO75g z!_a@(0bw;f=fh@@ng10Ixc-C>A3g+vl*U$+XJoS7!4A>u6Bp%u0a`9^faA;Iud)DB z?tuo{Fj`?lIst*DIPO+-1))=)EwRaNRG2&@=99z+d_tLEO|TL3=g*(Q_4=(YDzd+S zegTF9O0~#0J7ejAcGlLJc0{ybGH^C42N!4Hcz$_Y{sZz6KhpYCWNcD9RN(M@a!8+K+)5)k-Bq@0?TWXZT^8SX{gYsZc n)#sEpnv2-SDCciJ1P-FAO7WD$Qwaqd)gf|H%97RM#v%U?u-u^* diff --git a/client/src/reducers/rootReducer.js b/client/src/reducers/rootReducer.js deleted file mode 100644 index 7017b8baa..000000000 --- a/client/src/reducers/rootReducer.js +++ /dev/null @@ -1,15 +0,0 @@ -const initState = { - user: {} -} - -const rootReducer = (state = initState, action) => { - - if(action.type === 'USER_LOGS_IN'){ - return { - user: action.user - } - } - return state; -} - -export default rootReducer From dcfaae63a61e1e77db1a13245feef82f3c5589da Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 10 Sep 2018 11:31:43 +0200 Subject: [PATCH 10/16] More code cleaning --- client/src/components/Home.js | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/client/src/components/Home.js b/client/src/components/Home.js index 7768b4449..482c767b7 100644 --- a/client/src/components/Home.js +++ b/client/src/components/Home.js @@ -7,8 +7,6 @@ import React, { Component } from 'react' // Images import PortraitImage from '../img/portrait.jpg' -import CityImage from '../img/city.jpg' -import NatureImage from '../img/nature.jpg' class Home extends Component { @@ -27,24 +25,6 @@ class Home extends Component {

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum at lacus congue, suscipit elit nec, tincidunt orci.

-
-
- -
-
-

Title 2

-

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum at lacus congue, suscipit elit nec, tincidunt orci.

-
-
-
-
- -
-
-

Title 3

-

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum at lacus congue, suscipit elit nec, tincidunt orci.

-
-
From fa5b24ca78acdeb962e8d8fc27a4de3514f6e16e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 10 Sep 2018 11:46:35 +0200 Subject: [PATCH 11/16] AddUser component deleted --- README.md | 4 +-- client/src/components/AddUser.js | 53 ------------------------------- client/src/components/UserTabs.js | 18 ++--------- 3 files changed, 5 insertions(+), 70 deletions(-) delete mode 100644 client/src/components/AddUser.js diff --git a/README.md b/README.md index da26c4ad5..a8790edfb 100644 --- a/README.md +++ b/README.md @@ -20,9 +20,9 @@ App.js | | | | | |- UserTabs | | | | -| | | |- Tab 1 - AddUser +| | | |- Tab 1 - UserUpdate | | | | -| | | |- Tab 2 - UpdateUser +| | | |- Tab 2 - ManageImages | | | |- Browse | | | diff --git a/client/src/components/AddUser.js b/client/src/components/AddUser.js deleted file mode 100644 index 5d40d75c8..000000000 --- a/client/src/components/AddUser.js +++ /dev/null @@ -1,53 +0,0 @@ -import React, { Component } from 'react'; -import {graphql, compose} from 'react-apollo'; -import {getRolesQuery, addUserMutation, getUsersQuery} from '../queries/queries'; - -import AddUserNextButton from './AddUserNextButton'; - -class AddUser extends Component { - constructor(props){ - super(props); - this.state = { - alias: '', - authId: '1' - }; - } - - submitForm(e){ - - e.preventDefault(); - this.props.addUserMutation({ - variables: { - alias: this.state.alias, - authId: this.state.authId - }, - refetchQueries: [{ query: getUsersQuery}] // This allow us to re run whatever queries are necesary after the mutation. - }); - this.props.onAdded(); - } - - render(){ - return( -
-
-

Choose an Alias that will identify you anonimously across the whole Advanced Algos ecosystem. Choose it carefully, since the the Alias can not be changed later.

-
-
- this.setState({ alias:e.target.value})}/> - -
-
-
- - -
-
-
- ); - } -} - -export default compose( - graphql(getRolesQuery, {name: "getRolesQuery"}), - graphql(addUserMutation, {name: "addUserMutation"}) -) (AddUser); // This technique binds more than one query to a single component. diff --git a/client/src/components/UserTabs.js b/client/src/components/UserTabs.js index ef6989956..fd9a649a0 100644 --- a/client/src/components/UserTabs.js +++ b/client/src/components/UserTabs.js @@ -11,7 +11,6 @@ import Typography from '@material-ui/core/Typography'; // Components -import AddUser from './AddUser'; import UpdateUser from './UpdateUser'; function TabContainer(props) { @@ -36,23 +35,16 @@ const styles = theme => ({ class UserTabs extends React.Component { state = { - value: 0, - cureateDisabled: "false" + value: 0 }; handleChange = (event, value) => { this.setState({ value }); }; - updateUser = () => { - this.setState({ value: 1, cureateDisabled: "true" }); - }; - render() { const { classes } = this.props; const { value } = this.state; - const { createDisabled } = this.state; - return (
@@ -65,16 +57,12 @@ class UserTabs extends React.Component { indicatorColor="primary" textColor="primary" > - } /> - } /> } /> } /> - {value === 0 && } - {value === 1 && } - {value === 2 && Item Three} - + {value === 0 && } + {value === 1 && Item Three}
); } From 1470dfe9d03ce48248ce85e265f3b12a48ee6c93 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 10 Sep 2018 11:48:46 +0200 Subject: [PATCH 12/16] User Update refactored --- client/src/components/UserTabs.js | 4 ++-- client/src/components/{UpdateUser.js => UserUpdate.js} | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename client/src/components/{UpdateUser.js => UserUpdate.js} (98%) diff --git a/client/src/components/UserTabs.js b/client/src/components/UserTabs.js index fd9a649a0..dfadabfe1 100644 --- a/client/src/components/UserTabs.js +++ b/client/src/components/UserTabs.js @@ -11,7 +11,7 @@ import Typography from '@material-ui/core/Typography'; // Components -import UpdateUser from './UpdateUser'; +import UserUpdate from './UserUpdate'; function TabContainer(props) { return ( @@ -61,7 +61,7 @@ class UserTabs extends React.Component { } /> - {value === 0 && } + {value === 0 && } {value === 1 && Item Three} ); diff --git a/client/src/components/UpdateUser.js b/client/src/components/UserUpdate.js similarity index 98% rename from client/src/components/UpdateUser.js rename to client/src/components/UserUpdate.js index c8f430738..e3b45c9ed 100644 --- a/client/src/components/UpdateUser.js +++ b/client/src/components/UserUpdate.js @@ -3,7 +3,7 @@ import ReactDOM from 'react-dom'; import {graphql, compose} from 'react-apollo'; import {getRolesQuery, updateUserMutation, getUsersQuery} from '../queries/queries'; -class UpdateUser extends Component { +class UserUpdate extends Component { constructor(props){ super(props); @@ -188,4 +188,4 @@ class UpdateUser extends Component { export default compose( graphql(getRolesQuery, {name: "getRolesQuery"}), graphql(updateUserMutation, {name: "updateUserMutation"}) -) (UpdateUser); // This technique binds more than one query to a single component. +) (UserUpdate); // This technique binds more than one query to a single component. From 56a445d23c1e2a494c2c8e909ce2eb1003b0b636 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 10 Sep 2018 11:53:06 +0200 Subject: [PATCH 13/16] Form cleaning --- client/src/components/UserTabs.js | 1 - client/src/components/UserUpdate.js | 48 ++++++++++++++--------------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/client/src/components/UserTabs.js b/client/src/components/UserTabs.js index dfadabfe1..0636365b7 100644 --- a/client/src/components/UserTabs.js +++ b/client/src/components/UserTabs.js @@ -4,7 +4,6 @@ import { withStyles } from '@material-ui/core/styles'; import AppBar from '@material-ui/core/AppBar'; import Tabs from '@material-ui/core/Tabs'; import Tab from '@material-ui/core/Tab'; -import AddIcon from '@material-ui/icons/Add'; import UpdateIcon from '@material-ui/icons/Create'; import ImageIcon from '@material-ui/icons/Wallpaper'; import Typography from '@material-ui/core/Typography'; diff --git a/client/src/components/UserUpdate.js b/client/src/components/UserUpdate.js index e3b45c9ed..c0e832424 100644 --- a/client/src/components/UserUpdate.js +++ b/client/src/components/UserUpdate.js @@ -116,65 +116,65 @@ class UserUpdate extends Component { render(){ return( -
-
+
+

Complete your profile with the following optional information. Providing your real name might help other users trust you more.

-
-
- this.setState({ firstName:e.target.value})}/> +
+
+ this.setState({ firstName:e.target.value})}/>
-
-
- this.setState({ middleName:e.target.value})}/> +
+
+ this.setState({ middleName:e.target.value})}/>
-
-
- this.setState({ lastName:e.target.value})}/> +
+
+ this.setState({ lastName:e.target.value})}/>
-
-
- this.setState({ email:e.target.value})}/> +
+
+ this.setState({ email:e.target.value})}/>
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
-
+
From ee9792674c4314900c9660e4b86907aff81a844b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 10 Sep 2018 12:13:25 +0200 Subject: [PATCH 14/16] modularizing globals and sessions --- server/app.js | 33 ++----------------- .../{TokenDecoder.js => token-decoder.js} | 2 +- server/globals.js | 31 +++++++++++++++++ server/schema/schema.js | 2 +- server/sessions.js | 16 +++++++++ 5 files changed, 52 insertions(+), 32 deletions(-) rename server/auth/{TokenDecoder.js => token-decoder.js} (98%) create mode 100644 server/globals.js create mode 100644 server/sessions.js diff --git a/server/app.js b/server/app.js index f60c91372..aa7b6c3e3 100644 --- a/server/app.js +++ b/server/app.js @@ -1,35 +1,8 @@ -/* Debugging */ -global.INFO_LOG = true; -global.ERROR_LOG = true; - -/* Callbacks default responses. */ - -global.DEFAULT_OK_RESPONSE = { - result: "Ok", - message: "Operation Succeeded" -}; - -global.DEFAULT_FAIL_RESPONSE = { - result: "Fail", - message: "Operation Failed" -}; - -global.DEFAULT_RETRY_RESPONSE = { - result: "Retry", - message: "Retry Later" -}; - -global.CUSTOM_OK_RESPONSE = { - result: "Ok, but check Message", - message: "Custom Message" -}; - -global.CUSTOM_FAIL_RESPONSE = { - result: "Fail Because", - message: "Custom Message" -}; +/* This module imports */ +const globals = require('./globals'); +const sessions = require('./sessions'); const express = require('express'); const graphqlHTTP = require('express-graphql'); const schema = require('./schema/schema'); diff --git a/server/auth/TokenDecoder.js b/server/auth/token-decoder.js similarity index 98% rename from server/auth/TokenDecoder.js rename to server/auth/token-decoder.js index 870d3d555..ea10fb110 100644 --- a/server/auth/TokenDecoder.js +++ b/server/auth/token-decoder.js @@ -1,4 +1,4 @@ -const MODULE_NAME = "TokenDecoder"; +const MODULE_NAME = "token-decoder"; /* JSON Web Token (JWT) is a compact, URL-safe means of representing diff --git a/server/globals.js b/server/globals.js new file mode 100644 index 000000000..22a40b8da --- /dev/null +++ b/server/globals.js @@ -0,0 +1,31 @@ +/* Debugging */ + +global.INFO_LOG = true; +global.ERROR_LOG = true; + +/* Callbacks default responses. */ + +global.DEFAULT_OK_RESPONSE = { + result: "Ok", + message: "Operation Succeeded" +}; + +global.DEFAULT_FAIL_RESPONSE = { + result: "Fail", + message: "Operation Failed" +}; + +global.DEFAULT_RETRY_RESPONSE = { + result: "Retry", + message: "Retry Later" +}; + +global.CUSTOM_OK_RESPONSE = { + result: "Ok, but check Message", + message: "Custom Message" +}; + +global.CUSTOM_FAIL_RESPONSE = { + result: "Fail Because", + message: "Custom Message" +}; diff --git a/server/schema/schema.js b/server/schema/schema.js index 7e06a1a6c..d73ce3227 100644 --- a/server/schema/schema.js +++ b/server/schema/schema.js @@ -4,7 +4,7 @@ const graphql = require('graphql'); const _ = require('lodash'); const User = require('../models/user'); -const tokenDecoder = require('../auth/TokenDecoder'); +const tokenDecoder = require('../auth/token-decoder'); const { GraphQLObjectType, diff --git a/server/sessions.js b/server/sessions.js new file mode 100644 index 000000000..9ba7d9aef --- /dev/null +++ b/server/sessions.js @@ -0,0 +1,16 @@ +/* + +Global in-memory Sessions + +Here, we are going to store some information associated to the logged in user, after it was +succesfully authenticated. This will prevent cheating, since we will use the in-Session +user-id for any transaction belonging to the user instead of whatever user id it provides +from the client app. + +The key to access the in-Session information will allways be the authenticatioin token received +at the authentication transaction. This token should always come at the header of each +transactional functionality supported by this server module. + +*/ + +global.Sessions = new Map(); From fbd3ac5d8b02ec4ffdc6fa559e45d7ce0ea77675 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 10 Sep 2018 12:55:20 +0200 Subject: [PATCH 15/16] Session creation implemented --- server/schema/schema.js | 53 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/server/schema/schema.js b/server/schema/schema.js index d73ce3227..75a35857c 100644 --- a/server/schema/schema.js +++ b/server/schema/schema.js @@ -303,6 +303,13 @@ try { return; } + /* + + Ok, the user was correctly authenticated. Next we need to know if this logged in user + has already been added to this module's database or not yet. + + */ + authId = decodedToken.sub; alias = decodedToken.nickname; email = decodedToken.email; @@ -322,6 +329,18 @@ try { if (err.result === global.DEFAULT_OK_RESPONSE.result) { if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> authenticate -> onValidated -> onUserFound -> User already exists at database"); } + + if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> authenticate -> onValidated -> onUserFound -> Existing User: " + JSON.stringify(user)); } + + /* + + Here we save the user id of the logged in user at the server Sessions map, from there it will + be used to validate any further transaction comming from this same user. + + */ + + global.Sessions.set(encodedToken, user.id); + callBackFunction(global.DEFAULT_OK_RESPONSE, { authId: authId, alias: user.alias }); return; } @@ -333,7 +352,13 @@ try { if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> authenticate -> onValidated -> onUserFound -> User does not exist at database"); } - /* The authenticated user is NOT at our module database. We need to add him. */ + /* + + The authenticated user is NOT at our module database. We need to add him. + We will take from the authentication provider the basic information it knows about the logged in users + and save it as an initial set of data, which can later be modified. + + */ let newUser = new User({ alias: alias, @@ -345,10 +370,32 @@ try { if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> authenticate -> onValidated -> onUserFound -> " + alias + " being added to the database"); } - newUser.save(); + newUser.save(onSaved); - callBackFunction(global.DEFAULT_OK_RESPONSE, { authId, alias }); + function onSaved(err, savedUser) { + if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> authenticate -> onValidated -> onUserFound -> onSaved -> Entering function."); } + + if (err) { + if (global.ERROR_LOG === true) { console.log("[ERROR] " + MODULE_NAME + " -> authenticate -> onValidated -> onUserFound -> onSaved -> err = " + err); } + callBackFunction(global.DEFAULT_FAIL_RESPONSE, { error: err }); + return; + } + + if (global.INFO_LOG === true) { console.log("[INFO] " + MODULE_NAME + " -> authenticate -> onValidated -> onUserFound -> onSaved -> Saved User: " + JSON.stringify(savedUser)); } + + /* + + Here we save the user id of the logged in user at the server Sessions map, from there it will + be used to validate any further transaction comming from this same user. + + */ + + global.Sessions.set(encodedToken, savedUser.id); + + callBackFunction(global.DEFAULT_OK_RESPONSE, { authId, alias }); + + } } } } From e0bd92fadc7faefea9f22748684bfe74fcc31f75 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 10 Sep 2018 16:34:40 +0200 Subject: [PATCH 16/16] UI improvements, UserImages component created --- client/src/components/About.js | 6 +++--- client/src/components/Footer.js | 1 - client/src/components/LoggedInUser.js | 2 +- client/src/components/LoggedInUserMenu.js | 7 ++++++- client/src/components/UserImages.js | 14 ++++++++++++++ client/src/components/UserTabs.js | 3 ++- client/src/components/UserUpdate.js | 1 + 7 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 client/src/components/UserImages.js diff --git a/client/src/components/About.js b/client/src/components/About.js index 5283ad55d..34b02a317 100644 --- a/client/src/components/About.js +++ b/client/src/components/About.js @@ -3,9 +3,9 @@ import React from 'react' const About = () => { return (
-
-

About

-

Lorem ipsum dolor sit amet consectetur adipisicing elit. Recusandae repudiandae repellat illo magni eligendi cupiditate voluptates eius nam voluptate. Incidunt nihil ullam quae quia officia quaerat, deserunt eligendi explicabo totam?

+
+

About

+

This Module was developed by the AATeam. Contributions are welcomed.

) diff --git a/client/src/components/Footer.js b/client/src/components/Footer.js index df47f5326..5a2b475d7 100644 --- a/client/src/components/Footer.js +++ b/client/src/components/Footer.js @@ -14,7 +14,6 @@ const Footer = () => {
Links
  • Home
  • -
  • Profile
  • Browse
  • Search
  • Contact
  • diff --git a/client/src/components/LoggedInUser.js b/client/src/components/LoggedInUser.js index fbbfa8269..7b6137d6d 100644 --- a/client/src/components/LoggedInUser.js +++ b/client/src/components/LoggedInUser.js @@ -34,7 +34,7 @@ class LoggedInUser extends Component { return(
    -

    +

    ); diff --git a/client/src/components/LoggedInUserMenu.js b/client/src/components/LoggedInUserMenu.js index 803dde8de..248d6ec86 100644 --- a/client/src/components/LoggedInUserMenu.js +++ b/client/src/components/LoggedInUserMenu.js @@ -19,11 +19,16 @@ class LoggedInUserMenu extends Component { constructor(props){ super(props); this.state = { - property: 'value' + user: {} } } + componentDidMount(){ + this.setState({user: this.props.user}); + } + render() { + return ( {({ anchorEl, updateAnchorEl }) => { diff --git a/client/src/components/UserImages.js b/client/src/components/UserImages.js new file mode 100644 index 000000000..08ba7c5e3 --- /dev/null +++ b/client/src/components/UserImages.js @@ -0,0 +1,14 @@ +import React from 'react' + +const UserImages = () => { + return ( +
    +
    +

    Images Manager

    +

    This functionality has not been developed yet. Please visit this section later.

    +
    +
    + ) +} + +export default UserImages diff --git a/client/src/components/UserTabs.js b/client/src/components/UserTabs.js index 0636365b7..67055b9e1 100644 --- a/client/src/components/UserTabs.js +++ b/client/src/components/UserTabs.js @@ -11,6 +11,7 @@ import Typography from '@material-ui/core/Typography'; // Components import UserUpdate from './UserUpdate'; +import UserImages from './UserImages'; function TabContainer(props) { return ( @@ -61,7 +62,7 @@ class UserTabs extends React.Component { {value === 0 && } - {value === 1 && Item Three} + {value === 1 && }
); } diff --git a/client/src/components/UserUpdate.js b/client/src/components/UserUpdate.js index c0e832424..7e1e8a7c9 100644 --- a/client/src/components/UserUpdate.js +++ b/client/src/components/UserUpdate.js @@ -115,6 +115,7 @@ class UserUpdate extends Component { } render(){ + console.log("user at render", this.props); return(