mirror of
https://gitlab.com/comunic/comunicconsole
synced 2024-12-25 13:08:52 +00:00
Can send requests to server
This commit is contained in:
parent
e9c631e78a
commit
b1929fc21f
3
public/config.json
Normal file
3
public/config.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"api_url": "https://devweb.local/comunic/api-v2/admin/"
|
||||
}
|
46
src/App.tsx
46
src/App.tsx
@ -1,30 +1,30 @@
|
||||
import React from 'react';
|
||||
import './App.css';
|
||||
import { createMuiTheme, ThemeProvider } from '@material-ui/core';
|
||||
import { ApplicationDialogsProvider } from './ui/widgets/DialogsProvider';
|
||||
import { lightBlue, pink } from '@material-ui/core/colors';
|
||||
import { InitWidget } from './ui/widgets/InitWidget';
|
||||
import React from "react";
|
||||
import "./App.css";
|
||||
import { createMuiTheme, ThemeProvider } from "@material-ui/core";
|
||||
import { ApplicationDialogsProvider } from "./ui/widgets/DialogsProvider";
|
||||
import { lightBlue, pink } from "@material-ui/core/colors";
|
||||
import { InitWidget } from "./ui/widgets/InitWidget";
|
||||
|
||||
function App() {
|
||||
const darkTheme = createMuiTheme({
|
||||
palette: {
|
||||
type: 'dark',
|
||||
primary: lightBlue,
|
||||
secondary: pink,
|
||||
},
|
||||
});
|
||||
const darkTheme = createMuiTheme({
|
||||
palette: {
|
||||
type: "dark",
|
||||
primary: lightBlue,
|
||||
secondary: pink,
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<ThemeProvider theme={darkTheme}>
|
||||
<div className="App">
|
||||
{/* Holder of dialogs */}
|
||||
<ApplicationDialogsProvider></ApplicationDialogsProvider>
|
||||
return (
|
||||
<ThemeProvider theme={darkTheme}>
|
||||
<div className="App">
|
||||
{/* Holder of dialogs */}
|
||||
<ApplicationDialogsProvider></ApplicationDialogsProvider>
|
||||
|
||||
{/* Initialization widget */}
|
||||
<InitWidget></InitWidget>
|
||||
</div>
|
||||
</ThemeProvider>
|
||||
);
|
||||
{/* Initialization widget */}
|
||||
<InitWidget></InitWidget>
|
||||
</div>
|
||||
</ThemeProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
|
36
src/helpers/APIHelper.ts
Normal file
36
src/helpers/APIHelper.ts
Normal file
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* API request helper
|
||||
*
|
||||
* @author Pierre Hubert
|
||||
*/
|
||||
|
||||
import { ConfigHelper } from "./ConfigHelper";
|
||||
|
||||
/**
|
||||
* Perform an API request
|
||||
*
|
||||
* @param uri Target URI on the server
|
||||
* @param args Arguments to include in the request
|
||||
* @returns The result of the request, in case of success,
|
||||
* @throws An exception in case of failure
|
||||
*/
|
||||
export async function serverRequest(uri: string, args?: any): Promise<any> {
|
||||
const requestArguments = args || {};
|
||||
|
||||
const fd = new FormData();
|
||||
for (let arg in requestArguments) {
|
||||
if (requestArguments.hasOwnProperty(arg))
|
||||
fd.append(arg, requestArguments[arg]);
|
||||
}
|
||||
|
||||
// TODO : add access token, once supported
|
||||
|
||||
const result = await (
|
||||
await fetch((await ConfigHelper.apiURL()) + uri, {
|
||||
method: "POST",
|
||||
body: fd,
|
||||
})
|
||||
).json();
|
||||
|
||||
return result;
|
||||
}
|
@ -1,16 +1,33 @@
|
||||
/**
|
||||
* Account helper
|
||||
*
|
||||
*
|
||||
* @author Pierre Hubert
|
||||
*/
|
||||
|
||||
import { serverRequest } from "./APIHelper";
|
||||
|
||||
export interface AuthOptions {
|
||||
reset_token: string;
|
||||
}
|
||||
|
||||
export class AccountHelper {
|
||||
/**
|
||||
* Check whether access token are available
|
||||
* or not
|
||||
*/
|
||||
static get hasAccessToken() : boolean {
|
||||
// TODO : implement support
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Check whether access token are available
|
||||
* or not
|
||||
*/
|
||||
static get hasAccessToken(): boolean {
|
||||
// TODO : implement support
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get authentication options for a given email address
|
||||
*
|
||||
* @param mail Requested email
|
||||
*/
|
||||
static async getAuthOptions(mail: string): Promise<AuthOptions> {
|
||||
return await serverRequest("accounts/auth_options", {
|
||||
mail: mail,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
22
src/helpers/ConfigHelper.ts
Normal file
22
src/helpers/ConfigHelper.ts
Normal file
@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Configuration helper
|
||||
*
|
||||
* @author Pierre Hubert
|
||||
*/
|
||||
|
||||
let cache: any;
|
||||
|
||||
export class ConfigHelper {
|
||||
static async load() {
|
||||
if (!cache)
|
||||
cache = JSON.parse(await (await fetch("/config.json")).text());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get server API url
|
||||
*/
|
||||
static async apiURL(): Promise<string> {
|
||||
await this.load();
|
||||
return cache.api_url;
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ import {
|
||||
|
||||
import LockOutlinedIcon from "@material-ui/icons/LockOutlined";
|
||||
import React from "react";
|
||||
import { AccountHelper } from "../../helpers/AccountHelper";
|
||||
import { matAlert } from "../widgets/DialogsProvider";
|
||||
|
||||
function Copyright() {
|
||||
@ -63,7 +64,9 @@ export class LoginRoute extends React.Component<{}, LoginRouteState> {
|
||||
|
||||
if (!this.canSubmit) return;
|
||||
|
||||
matAlert("good");
|
||||
AccountHelper.getAuthOptions(this.state.currEmail).then((r) =>
|
||||
matAlert("reset token => " + r.reset_token)
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
@ -97,7 +100,7 @@ export class LoginRoute extends React.Component<{}, LoginRouteState> {
|
||||
<Typography
|
||||
component="h1"
|
||||
variant="h5"
|
||||
style={{ margin: "10px" }}
|
||||
style={{ margin: "10px", marginBottom: "50px" }}
|
||||
>
|
||||
Comunic Console
|
||||
</Typography>
|
||||
|
Loading…
Reference in New Issue
Block a user