added a register route via token
This commit is contained in:
parent
1ccbea30e4
commit
ed9552b62b
7 changed files with 76 additions and 3 deletions
|
@ -7,6 +7,7 @@ import bodyParser = require('body-parser');
|
|||
import * as http from "http";
|
||||
import {MapController} from "./Controller/MapController";
|
||||
import {PrometheusController} from "./Controller/PrometheusController";
|
||||
import {AdminController} from "./Controller/AdminController";
|
||||
|
||||
class App {
|
||||
public app: Application;
|
||||
|
@ -15,6 +16,7 @@ class App {
|
|||
public authenticateController: AuthenticateController;
|
||||
public mapController: MapController;
|
||||
public prometheusController: PrometheusController;
|
||||
private adminController: AdminController;
|
||||
|
||||
constructor() {
|
||||
this.app = express();
|
||||
|
@ -32,6 +34,7 @@ class App {
|
|||
this.authenticateController = new AuthenticateController(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
|
||||
|
|
40
back/src/Controller/AdminController.ts
Normal file
40
back/src/Controller/AdminController.ts
Normal file
|
@ -0,0 +1,40 @@
|
|||
import {Application, Request, Response} from "express";
|
||||
import {OK} from "http-status-codes";
|
||||
import {ADMIN_API_URL} from "../Enum/EnvironmentVariable";
|
||||
import Axios, {AxiosError} 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;
|
||||
|
||||
//todo add ADMIN_API_TOKEN authorization
|
||||
let response = null
|
||||
try {
|
||||
console.log(ADMIN_API_URL+'/api/login-url/'+token);
|
||||
response = await Axios.get(ADMIN_API_URL+'/api/login-url/'+token)
|
||||
} catch (e) {
|
||||
console.log(e.message)
|
||||
return res.status(500).send('An error happened');
|
||||
}
|
||||
|
||||
const teamSlug = response.data.teamSlug;
|
||||
const worldSlug = response.data.worldSlug;
|
||||
const roomSlug = response.data.roomSlug;
|
||||
return res.status(OK).send({
|
||||
loginUrl: '/@/'+teamSlug+'/'+worldSlug+'/'+roomSlug,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue