Integration with Master App - Login Working
This commit is contained in:
1 parent
b2771bb8fe
commit
2380c30c8f
8 files changed
+188
-236
No files matched your search
@@ -89,6 +89,7 @@ function loadAdvancedAlgosPlatform() {
|
||||
}
|
||||
|
||||
window.USER_PROFILE = responseFromServer.userProfile;
|
||||
console.log("window.USER_PROFILE at AppPreLoader", window.USER_PROFILE);
|
||||
|
||||
loadDebugModule();
|
||||
}
|
||||
|
||||
+13
-13
@@ -40,26 +40,26 @@ function newTopSpace() {
|
||||
};
|
||||
|
||||
thisObject.login = newLogin();
|
||||
thisObject.login.initialize();
|
||||
thisObject.login.initialize(onLoginInitialized);
|
||||
|
||||
thisObject.companyLogo = newCompanyLogo();
|
||||
thisObject.companyLogo.initialize();
|
||||
|
||||
thisObject.endUser = newEndUser();
|
||||
thisObject.endUser.initialize();
|
||||
|
||||
thisObject.devTeam = newDevTeam();
|
||||
thisObject.devTeam.initialize(sharedStatus);
|
||||
|
||||
thisObject.currentBot = newCurrentBot();
|
||||
thisObject.currentBot.initialize(sharedStatus);
|
||||
|
||||
thisObject.currentProcess = newCurrentProcess();
|
||||
thisObject.currentProcess.initialize(sharedStatus);
|
||||
|
||||
thisObject.currentStartMode = newCurrentStartMode();
|
||||
thisObject.currentStartMode.initialize(sharedStatus);
|
||||
thisObject.devTeam = newDevTeam();
|
||||
|
||||
|
||||
function onLoginInitialized() {
|
||||
|
||||
thisObject.companyLogo.initialize();
|
||||
thisObject.endUser.initialize();
|
||||
thisObject.currentBot.initialize(sharedStatus);
|
||||
thisObject.currentProcess.initialize(sharedStatus);
|
||||
thisObject.currentStartMode.initialize(sharedStatus);
|
||||
thisObject.devTeam.initialize(sharedStatus);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
|
||||
@@ -118,6 +118,7 @@ function newCurrentBot() {
|
||||
|
||||
let fontSize = 12;
|
||||
let label = window.CURRENT_BOT_DISPLAY_NAME;
|
||||
if (label === undefined) { label = "" };
|
||||
|
||||
let point = {
|
||||
x: thisObject.container.frame.width * 1 / 3,
|
||||
|
||||
@@ -111,6 +111,7 @@ function newCurrentProcess() {
|
||||
|
||||
let fontSize = 12;
|
||||
let label = window.CURRENT_PROCESS;
|
||||
if (label === undefined) { label = "" };
|
||||
|
||||
let point = {
|
||||
x: thisObject.container.frame.width * 1 / 3,
|
||||
|
||||
@@ -83,6 +83,7 @@ function newCurrentStartMode() {
|
||||
|
||||
let fontSize = 12;
|
||||
let label = window.CURRENT_START_MODE + " Mode";
|
||||
if (label === "undefined Mode") { label = "" };
|
||||
|
||||
let point = {
|
||||
x: thisObject.container.frame.width / 2 - label.length / 2 * fontSize / 3,
|
||||
|
||||
@@ -50,6 +50,7 @@ function newDevTeam() {
|
||||
window.TEAMS = storedTeams;
|
||||
window.DEV_TEAM = storedTeams[sharedStatus.currentDevTeamIndex].slug;
|
||||
label = storedTeams[sharedStatus.currentDevTeamIndex].name;
|
||||
sharedStatus.eventHandler.raiseEvent("devTeam Changed");
|
||||
}
|
||||
|
||||
thisObject.container.eventHandler.listenToEvent("onMouseClick", onClick);
|
||||
|
||||
+1
-5
@@ -24,11 +24,6 @@ function newEndUser() {
|
||||
|
||||
function initialize() {
|
||||
|
||||
if (window.EXECUTING_AT === 'Master App') {
|
||||
window.USER_LOGGED_IN = "";
|
||||
return;
|
||||
}
|
||||
|
||||
let storedUser = window.localStorage.getItem('loggedInUser');
|
||||
|
||||
if (storedUser === null || storedUser === "") {
|
||||
@@ -83,6 +78,7 @@ function newEndUser() {
|
||||
|
||||
let fontSize = 12;
|
||||
let label = window.USER_LOGGED_IN;
|
||||
if (label === undefined) { label = "" };
|
||||
|
||||
let point = {
|
||||
x: thisObject.container.frame.width * 1 / 3,
|
||||
|
||||
+169
-218
@@ -29,252 +29,202 @@ function newLogin() {
|
||||
return thisObject;
|
||||
|
||||
function initialize() {
|
||||
function initialize(callBackFunction) {
|
||||
|
||||
if (window.EXECUTING_AT === 'Master App') {
|
||||
currentLabel = "";
|
||||
return;
|
||||
}
|
||||
|
||||
const accessToken = window.localStorage.getItem("access_token");
|
||||
let user = window.localStorage.getItem("user");
|
||||
|
||||
let parameters = {
|
||||
domain: 'advancedalgos.eu.auth0.com',
|
||||
clientID: 'WQTnXt20a0t2WGl64mEcOyP4Ippo37nB',
|
||||
redirectUri: window.location.href,
|
||||
audience: 'https://auth-dev.advancedalgos.net',
|
||||
};
|
||||
if (user === null) { return; }
|
||||
|
||||
Auth0 = new auth0.WebAuth(parameters);
|
||||
user = JSON.parse(user);
|
||||
|
||||
userAuthorization = window.location.hash.substr(1); // What comes after the # on the URL.
|
||||
const authId = user.authId;
|
||||
|
||||
let sessionToken = window.localStorage.getItem('sessionToken');
|
||||
let sessionToken;
|
||||
|
||||
if (sessionToken !== null && sessionToken !== "") {
|
||||
const apolloClient = new Apollo.lib.ApolloClient({
|
||||
networkInterface: Apollo.lib.createNetworkInterface({
|
||||
/*uri: 'http://localhost:4000/graphql',*/
|
||||
uri: 'https://users-api.advancedalgos.net/graphql',
|
||||
transportBatching: true,
|
||||
}),
|
||||
connectToDevTools: true,
|
||||
})
|
||||
|
||||
currentLabel = "Logout";
|
||||
|
||||
if (window.location.search !== "?" + sessionToken ) {
|
||||
|
||||
/* When the user was logged in, and we navigate again to the platform url alone, we need to re-submit the token session to AAWeb */
|
||||
|
||||
window.location = "/index.html?" + sessionToken;
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (userAuthorization === "") {
|
||||
|
||||
currentLabel = "Login / Signup";
|
||||
|
||||
} else {
|
||||
|
||||
Auth0.parseHash({ hash: window.location.hash }, function (err, authResult) {
|
||||
if (err) {
|
||||
return console.log("Parse Hash Error", err);
|
||||
const QUERY = Apollo.gql`
|
||||
query($authId: String){
|
||||
userByAuthId (authId: $authId){
|
||||
id
|
||||
referrerId
|
||||
alias
|
||||
firstName
|
||||
middleName
|
||||
lastName
|
||||
bio
|
||||
email
|
||||
emailVerified
|
||||
isDeveloper
|
||||
isDataAnalyst
|
||||
isTrader
|
||||
avatarHandle
|
||||
avatarChangeDate
|
||||
sessionToken
|
||||
role {
|
||||
id
|
||||
}
|
||||
|
||||
// The contents of authResult depend on which authentication parameters were used.
|
||||
// It can include the following:
|
||||
// authResult.accessToken - access token for the API specified by `audience`
|
||||
// authResult.expiresIn - string with the access token's expiration time in seconds
|
||||
// authResult.idToken - ID token JWT containing user profile information
|
||||
|
||||
currentLabel = "Logout";
|
||||
|
||||
let authId = authResult.idTokenPayload.sub;
|
||||
|
||||
// We store the token so we can identify the user
|
||||
window.localStorage.setItem('auth0Token', authResult.accessToken);
|
||||
|
||||
/* Now we connect to the users and team modules
|
||||
to get the users alias, first, middle and last names
|
||||
as well as the user's teams and their team data. */
|
||||
|
||||
// To avoid race conditions, add asynchronous fetches to array
|
||||
let fetchDataPromises = [];
|
||||
|
||||
const apolloClient = new Apollo.lib.ApolloClient({
|
||||
networkInterface: Apollo.lib.createNetworkInterface({
|
||||
/*uri: 'http://localhost:4000/graphql',*/
|
||||
uri: 'https://users-api.advancedalgos.net/graphql',
|
||||
transportBatching: true,
|
||||
}),
|
||||
connectToDevTools: true,
|
||||
})
|
||||
|
||||
const QUERY = Apollo.gql`
|
||||
query($authId: String){
|
||||
userByAuthId (authId: $authId){
|
||||
id
|
||||
referrerId
|
||||
alias
|
||||
firstName
|
||||
middleName
|
||||
lastName
|
||||
bio
|
||||
email
|
||||
emailVerified
|
||||
isDeveloper
|
||||
isDataAnalyst
|
||||
isTrader
|
||||
avatarHandle
|
||||
avatarChangeDate
|
||||
sessionToken
|
||||
role {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
const getUser = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
apolloClient.query({
|
||||
query: QUERY,
|
||||
variables: {
|
||||
authId: authId
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
console.log("apolloClient data", response);
|
||||
let sessionToken = response.data.userByAuthId.sessionToken;
|
||||
window.localStorage.setItem('sessionToken', sessionToken);
|
||||
window.localStorage.setItem('loggedInUser', JSON.stringify(response.data.userByAuthId));
|
||||
resolve({user: response.data.userByAuthId})
|
||||
})
|
||||
.catch(error => {
|
||||
console.log("apolloClient error", error)
|
||||
// reject (error)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const networkInterfaceTeams = Apollo.lib.createNetworkInterface({
|
||||
// uri: 'http://localhost:4001/graphql',
|
||||
uri: 'https://teams-api.advancedalgos.net/graphql'
|
||||
});
|
||||
|
||||
networkInterfaceTeams.use([{
|
||||
applyMiddleware(req, next) {
|
||||
req.options.headers = {
|
||||
authorization: `Bearer ${authResult.accessToken}`
|
||||
};
|
||||
next();
|
||||
}
|
||||
}]);
|
||||
|
||||
const apolloClientTeams = new Apollo.lib.ApolloClient({
|
||||
networkInterface: networkInterfaceTeams,
|
||||
connectToDevTools: true,
|
||||
});
|
||||
|
||||
const TEAM_BY_OWNER_QUERY = Apollo.gql`
|
||||
query teamsByOwnerQuery($authId: String!) {
|
||||
teamsByOwner(ownerId: $authId) {
|
||||
id
|
||||
name
|
||||
slug
|
||||
profile {
|
||||
avatar
|
||||
banner
|
||||
description
|
||||
motto
|
||||
updatedAt
|
||||
}
|
||||
members {
|
||||
member {
|
||||
alias
|
||||
}
|
||||
}
|
||||
fb {
|
||||
id
|
||||
name
|
||||
slug
|
||||
avatar
|
||||
kind
|
||||
status {
|
||||
status
|
||||
reason
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
const getTeamByOwner = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
apolloClientTeams.query({
|
||||
query: TEAM_BY_OWNER_QUERY,
|
||||
variables: { authId: authId }
|
||||
})
|
||||
.then(response => {
|
||||
console.log("apolloClientTeam data", response);
|
||||
window.localStorage.setItem('userTeams', JSON.stringify(response.data.teamsByOwner));
|
||||
resolve({teams: response.data.teamsByOwner})
|
||||
})
|
||||
.catch(error => {
|
||||
console.log("apolloClientTeam error", error)
|
||||
// reject (error)
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
fetchDataPromises.push(getUser(), getTeamByOwner());
|
||||
|
||||
// When all asynchronous fetches resolve, refresh page or throw error.
|
||||
Promise.all(fetchDataPromises).then(result => {
|
||||
console.log('fetchDataPromises: ', result);
|
||||
window.location = "/index.html?" + sessionToken;
|
||||
}, err => {
|
||||
console.error("fetchData error", err)
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
`
|
||||
const getUser = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
apolloClient.query({
|
||||
query: QUERY,
|
||||
variables: {
|
||||
authId: authId
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
console.log("apolloClient data", response);
|
||||
sessionToken = response.data.userByAuthId.sessionToken;
|
||||
|
||||
window.localStorage.setItem('loggedInUser', JSON.stringify(response.data.userByAuthId));
|
||||
resolve({user: response.data.userByAuthId})
|
||||
})
|
||||
.catch(error => {
|
||||
console.log("apolloClient error", error)
|
||||
// reject (error)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const networkInterfaceTeams = Apollo.lib.createNetworkInterface({
|
||||
// uri: 'http://localhost:4001/graphql',
|
||||
uri: 'https://teams-api.advancedalgos.net/graphql'
|
||||
});
|
||||
|
||||
networkInterfaceTeams.use([{
|
||||
applyMiddleware(req, next) {
|
||||
req.options.headers = {
|
||||
authorization: `Bearer ${accessToken}`
|
||||
};
|
||||
next();
|
||||
}
|
||||
}]);
|
||||
|
||||
const apolloClientTeams = new Apollo.lib.ApolloClient({
|
||||
networkInterface: networkInterfaceTeams,
|
||||
connectToDevTools: true,
|
||||
});
|
||||
|
||||
const TEAM_BY_OWNER_QUERY = Apollo.gql`
|
||||
query teamsByOwnerQuery($authId: String!) {
|
||||
teamsByOwner(ownerId: $authId) {
|
||||
id
|
||||
name
|
||||
slug
|
||||
profile {
|
||||
avatar
|
||||
banner
|
||||
description
|
||||
motto
|
||||
updatedAt
|
||||
}
|
||||
members {
|
||||
member {
|
||||
alias
|
||||
}
|
||||
}
|
||||
fb {
|
||||
id
|
||||
name
|
||||
slug
|
||||
avatar
|
||||
kind
|
||||
status {
|
||||
status
|
||||
reason
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
const getTeamByOwner = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
apolloClientTeams.query({
|
||||
query: TEAM_BY_OWNER_QUERY,
|
||||
variables: { authId: authId }
|
||||
})
|
||||
.then(response => {
|
||||
console.log("apolloClientTeam data", response);
|
||||
window.localStorage.setItem('userTeams', JSON.stringify(response.data.teamsByOwner));
|
||||
resolve({teams: response.data.teamsByOwner})
|
||||
})
|
||||
.catch(error => {
|
||||
console.log("apolloClientTeam error", error)
|
||||
// reject (error)
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
// To avoid race conditions, add asynchronous fetches to array
|
||||
let fetchDataPromises = [];
|
||||
|
||||
fetchDataPromises.push(getUser(), getTeamByOwner());
|
||||
|
||||
// When all asynchronous fetches resolve, authenticate user or throw error.
|
||||
Promise.all(fetchDataPromises).then(result => {
|
||||
console.log('fetchDataPromises: ', result);
|
||||
|
||||
/* this is the time to authenticate the user at AAWeb */
|
||||
|
||||
authenticateUser();
|
||||
|
||||
}, err => {
|
||||
console.error("fetchData error", err)
|
||||
});
|
||||
|
||||
thisObject.container.eventHandler.listenToEvent("onMouseClick", onClick);
|
||||
}
|
||||
|
||||
function onClick() {
|
||||
function authenticateUser() {
|
||||
|
||||
let sessionToken = window.localStorage.getItem('sessionToken');
|
||||
if (sessionToken === undefined) { sessionToken = "" }
|
||||
|
||||
if (sessionToken !== null && sessionToken !== "") {
|
||||
let path = window.URL_PREFIX + "AABrowserAPI/authenticateUser/" + sessionToken;
|
||||
|
||||
window.localStorage.setItem('sessionToken', "");
|
||||
window.localStorage.setItem('loggedInUser', "");
|
||||
window.localStorage.setItem('userTeams', "");
|
||||
window.localStorage.setItem('accessToken', "");
|
||||
window.location = "/index.html";
|
||||
currentLabel = "Login / Signup";
|
||||
callServer(undefined, path, onServerReponded);
|
||||
|
||||
} else {
|
||||
function onServerReponded(pResponseFromServer) {
|
||||
|
||||
if (userAuthorization === "") {
|
||||
let responseFromServer = JSON.parse(pResponseFromServer);
|
||||
|
||||
/* Goes for a login / signup */
|
||||
err = responseFromServer.err;
|
||||
|
||||
Auth0.authorize({
|
||||
scope: 'openid profile',
|
||||
responseType: 'token id_token'
|
||||
});
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
} else {
|
||||
console.log("Authentication Error. " + err.message);
|
||||
return;
|
||||
|
||||
/* Goes for a logout */
|
||||
}
|
||||
|
||||
window.localStorage.setItem('sessionToken', "");
|
||||
window.localStorage.setItem('loggedInUser', "");
|
||||
window.localStorage.setItem('userTeams', "");
|
||||
window.localStorage.setItem('accessToken', "");
|
||||
window.location = "/index.html";
|
||||
currentLabel = "Login / Signup";
|
||||
window.USER_PROFILE = responseFromServer.userProfile;
|
||||
window.localStorage.setItem('sessionToken', sessionToken);
|
||||
|
||||
console.log("window.USER_PROFILE at Login", window.USER_PROFILE);
|
||||
|
||||
currentLabel = "Logged In"
|
||||
callBackFunction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function onClick() {
|
||||
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
|
||||
let container;
|
||||
@@ -300,6 +250,7 @@ function newLogin() {
|
||||
|
||||
let fontSize = 12;
|
||||
let label = currentLabel;
|
||||
if (label === undefined) { label = "" };
|
||||
|
||||
let point = {
|
||||
x: thisObject.container.frame.width * 1 / 3,
|
||||
|
||||
Reference in new issue
Block a user