Merge branch 'develop' into feature/global-message

# Conflicts:
#	back/src/App.ts
This commit is contained in:
Gregoire Parant 2020-09-23 17:26:00 +02:00
commit bcb126a146
7 changed files with 90 additions and 2 deletions

View File

@ -42,6 +42,7 @@
"@types/multer": "^1.4.4",
"@types/socket.io": "^2.1.4",
"@types/uuidv4": "^5.0.0",
"axios": "^0.20.0",
"body-parser": "^1.19.0",
"express": "^4.17.1",
"generic-type-guard": "^3.2.0",

View File

@ -8,6 +8,7 @@ import * as http from "http";
import {MapController} from "./Controller/MapController";
import {PrometheusController} from "./Controller/PrometheusController";
import {FileController} from "./Controller/FileController";
import {AdminController} from "./Controller/AdminController";
class App {
public app: Application;
@ -17,6 +18,7 @@ class App {
public fileController: FileController;
public mapController: MapController;
public prometheusController: PrometheusController;
private adminController: AdminController;
constructor() {
this.app = express();
@ -35,6 +37,7 @@ class App {
this.fileController = new FileController(this.app);
this.mapController = new MapController(this.app);
this.prometheusController = new PrometheusController(this.app, this.ioSocketController);
this.adminController = new AdminController(this.app);
}
// TODO add session user

View File

@ -0,0 +1,36 @@
import {Application, Request, Response} from "express";
import {OK} from "http-status-codes";
import {ADMIN_API_TOKEN, ADMIN_API_URL} from "../Enum/EnvironmentVariable";
import Axios from "axios";
export class AdminController {
App : Application;
constructor(App : Application) {
this.App = App;
this.getLoginUrlByToken();
}
getLoginUrlByToken(){
this.App.get("/register/:token", async (req: Request, res: Response) => {
if (!ADMIN_API_URL) {
return res.status(500).send('No admin backoffice set!');
}
const token:string = req.params.token;
let response = null
try {
response = await Axios.get(ADMIN_API_URL+'/api/login-url/'+token, { headers: {"Authorization" : `${ADMIN_API_TOKEN}`} })
} catch (e) {
console.log(e.message)
return res.status(e.status || 500).send('An error happened');
}
const organizationSlug = response.data.organizationSlug;
const worldSlug = response.data.worldSlug;
const roomSlug = response.data.roomSlug;
return res.status(OK).send({organizationSlug, worldSlug, roomSlug});
});
}
}

View File

@ -3,11 +3,15 @@ const URL_ROOM_STARTED = "/Floor0/floor0.json";
const MINIMUM_DISTANCE = process.env.MINIMUM_DISTANCE ? Number(process.env.MINIMUM_DISTANCE) : 64;
const GROUP_RADIUS = process.env.GROUP_RADIUS ? Number(process.env.GROUP_RADIUS) : 48;
const ALLOW_ARTILLERY = process.env.ALLOW_ARTILLERY ? process.env.ALLOW_ARTILLERY == 'true' : false;
const ADMIN_API_URL = process.env.ADMIN_API_URL || null;
const ADMIN_API_TOKEN = process.env.ADMIN_API_TOKEN || null;
export {
SECRET_KEY,
URL_ROOM_STARTED,
MINIMUM_DISTANCE,
ADMIN_API_URL,
ADMIN_API_TOKEN,
GROUP_RADIUS,
ALLOW_ARTILLERY
ALLOW_ARTILLERY,
}

View File

@ -266,6 +266,13 @@ async-limiter@~1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.1.tgz#dd379e94f0db8310b08291f9d64c3209766617fd"
axios@^0.20.0:
version "0.20.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.20.0.tgz#057ba30f04884694993a8cd07fa394cff11c50bd"
integrity sha512-ANA4rr2BDcmmAQLOKft2fufrtuvlqR+cXNNinUmvfeSNCOF98PZL+7M/v1zIdGo7OLjEA9J2gXJL+j4zGsl0bA==
dependencies:
follow-redirects "^1.10.0"
backo2@1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/backo2/-/backo2-1.0.2.tgz#31ab1ac8b129363463e35b3ebb69f4dfcfba7947"
@ -827,6 +834,11 @@ flatted@^2.0.0:
version "2.0.2"
resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.2.tgz#4575b21e2bcee7434aa9be662f4b7b5f9c2b5138"
follow-redirects@^1.10.0:
version "1.13.0"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.0.tgz#b42e8d93a2a7eea5ed88633676d6597bc8e384db"
integrity sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA==
forwarded@~0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.1.2.tgz#98c23dab1175657b8c0573e8ceccd91b0ff18c84"

View File

@ -11,8 +11,11 @@ import WebGLRenderer = Phaser.Renderer.WebGL.WebGLRenderer;
import {OutlinePipeline} from "./Phaser/Shaders/OutlinePipeline";
import {CustomizeScene} from "./Phaser/Login/CustomizeScene";
import {CoWebsiteManager} from "./WebRtc/CoWebsiteManager";
import {redirectIfToken} from "./register";
//CoWebsiteManager.loadCoWebsite('https://thecodingmachine.com');
let connectionData //todo: do something with this data
redirectIfToken().then(res => connectionData = res);
// Load Jitsi if the environment variable is set.
if (JITSI_URL) {

29
front/src/register.ts Normal file
View File

@ -0,0 +1,29 @@
import Axios from "axios";
import {API_URL} from "./Enum/EnvironmentVariable";
declare let history:History;
//todo: better naming
export interface ConnexionData {
organizationSlug: string,
worldSlug: string,
roomSlug: string,
}
export async function redirectIfToken(): Promise<ConnexionData | null> {
const match = /\/register\/(.+)/.exec(window.location.toString());
if (!match) {
return null
}
let res = null;
try {
res = await Axios.get(`${API_URL}/register/`+match[1])
} catch (e) {
return null;
}
const organizationSlug = res.data.organizationSlug;
const worldSlug = res.data.worldSlug;
const roomSlug = res.data.roomSlug;
const connexionUrl = '/@/'+organizationSlug+'/'+worldSlug+'/'+roomSlug;
history.pushState({}, '', connexionUrl);
return {organizationSlug, worldSlug, roomSlug};
}