Merge branch 'main' into aw-disruption-control
This commit is contained in:
commit
bff5a73c8c
5
package-lock.json
generated
5
package-lock.json
generated
@ -12386,6 +12386,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
|
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
|
||||||
"integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ=="
|
"integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ=="
|
||||||
},
|
},
|
||||||
|
"react-native-push-notification": {
|
||||||
|
"version": "6.1.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-native-push-notification/-/react-native-push-notification-6.1.3.tgz",
|
||||||
|
"integrity": "sha512-qNbFCkObCXwSFQbK6hJyx1Bym1D7V4XM8iN2L6eL3GAdNLmeBTdLdx3mPbKJtuaDJ1+deniFTQ2rz6hU4ELOXA=="
|
||||||
|
},
|
||||||
"react-push-notification": {
|
"react-push-notification": {
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/react-push-notification/-/react-push-notification-1.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/react-push-notification/-/react-push-notification-1.3.0.tgz",
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
"react": "^17.0.1",
|
"react": "^17.0.1",
|
||||||
"react-axios": "^2.0.3",
|
"react-axios": "^2.0.3",
|
||||||
"react-dom": "^17.0.1",
|
"react-dom": "^17.0.1",
|
||||||
|
"react-native-push-notification": "^6.1.3",
|
||||||
"react-push-notification": "^1.3.0",
|
"react-push-notification": "^1.3.0",
|
||||||
"react-router-dom": "^5.2.0",
|
"react-router-dom": "^5.2.0",
|
||||||
"react-scripts": "4.0.0",
|
"react-scripts": "4.0.0",
|
||||||
|
@ -5,7 +5,7 @@ import React, { Component } from "react";
|
|||||||
import { BrowserRouter as Router, Route } from "react-router-dom";
|
import { BrowserRouter as Router, Route } from "react-router-dom";
|
||||||
|
|
||||||
import BottomMenu from "./components/BottomMenu.js";
|
import BottomMenu from "./components/BottomMenu.js";
|
||||||
import AccessToken from "./components/AccessToken.js";
|
//import AccessToken from "./components/AccessToken.js";
|
||||||
import NearbyStation from "./components/NearbyStation";
|
import NearbyStation from "./components/NearbyStation";
|
||||||
|
|
||||||
import Tickets from "./components/pages/Tickets.js";
|
import Tickets from "./components/pages/Tickets.js";
|
||||||
|
12
src/GlobalData.js
Normal file
12
src/GlobalData.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import User from './classes/User.js';
|
||||||
|
import Coordinates from "./classes/Coordinates.js";
|
||||||
|
|
||||||
|
let globalData = {
|
||||||
|
user: new User(
|
||||||
|
"test",
|
||||||
|
"123",
|
||||||
|
new Coordinates()
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
export default globalData;
|
21
src/classes/AccessToken.js
Normal file
21
src/classes/AccessToken.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
class AccessToken {
|
||||||
|
credentials = 'NXR5N2d4bUFmUWxVSERIZG03a2dhcVh3SzVJYTp3cElPVVJuSkpjVHRPNnJPUlltWVlQcTR3WGth'
|
||||||
|
device = '123'
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
const headers = {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
'Authorization': 'Basic ' + this.credentials
|
||||||
|
};
|
||||||
|
|
||||||
|
axios.post('https://api.vasttrafik.se/token','grant_type=client_credentials&scope=device_'+this.device, {headers} )
|
||||||
|
.then(response => {
|
||||||
|
console.log(response);
|
||||||
|
this.token = response.data.access_token
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AccessToken
|
@ -1,65 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import axios from 'axios';
|
|
||||||
|
|
||||||
var globToken = ''
|
|
||||||
|
|
||||||
const GetToken = () => {
|
|
||||||
const vars = {
|
|
||||||
credentials: 'NXR5N2d4bUFmUWxVSERIZG03a2dhcVh3SzVJYTp3cElPVVJuSkpjVHRPNnJPUlltWVlQcTR3WGth',
|
|
||||||
token: undefined,
|
|
||||||
device: '123',
|
|
||||||
}
|
|
||||||
|
|
||||||
const headers = {
|
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
|
||||||
'Authorization': 'Basic ' + vars.credentials
|
|
||||||
};
|
|
||||||
|
|
||||||
axios.post('https://api.vasttrafik.se/token','grant_type=client_credentials&scope=device_'+vars.device, { headers })
|
|
||||||
.then(response => {
|
|
||||||
console.log(response);
|
|
||||||
globToken = response.data.access_token
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
class AccessToken extends React.Component {
|
|
||||||
state = {
|
|
||||||
token: 'No Token',
|
|
||||||
}
|
|
||||||
|
|
||||||
handleChange = event => {
|
|
||||||
this.setState({ token: event.target.value});
|
|
||||||
}
|
|
||||||
|
|
||||||
handleSubmit = event => {
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
this.setState({
|
|
||||||
credentials: 'Attempting to send token'
|
|
||||||
});
|
|
||||||
GetToken();
|
|
||||||
}
|
|
||||||
|
|
||||||
handleFetch = event => {
|
|
||||||
event.preventDefault();
|
|
||||||
this.setState({token: globToken})
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<form onSubmit={this.handleSubmit}>
|
|
||||||
<button type="submit">Get Token</button>
|
|
||||||
</form>
|
|
||||||
<h1>
|
|
||||||
{this.state.token}
|
|
||||||
</h1>
|
|
||||||
<form onSubmit={this.handleFetch}>
|
|
||||||
<button type="submit">fetch</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default AccessToken
|
|
@ -1,5 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import AccessToken from '../classes/AccessToken'
|
||||||
|
|
||||||
class NearbyStation extends React.Component {
|
class NearbyStation extends React.Component {
|
||||||
state = {
|
state = {
|
||||||
@ -7,7 +8,7 @@ class NearbyStation extends React.Component {
|
|||||||
long: '12.0',
|
long: '12.0',
|
||||||
stops: [],
|
stops: [],
|
||||||
token: undefined,
|
token: undefined,
|
||||||
device: '123',
|
tokenClass: new AccessToken()
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChangeLat = event => {
|
handleChangeLat = event => {
|
||||||
@ -18,15 +19,11 @@ class NearbyStation extends React.Component {
|
|||||||
this.setState({ long: event.target.value});
|
this.setState({ long: event.target.value});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChangeToken = event => {
|
|
||||||
this.setState({ token: event.target.value})
|
|
||||||
}
|
|
||||||
|
|
||||||
handleSubmit = event => {
|
handleSubmit = event => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
'Authorization': 'Bearer ' + this.state.token
|
'Authorization': 'Bearer ' + this.state.tokenClass.token
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('Attempted connection')
|
console.log('Attempted connection')
|
||||||
@ -52,10 +49,6 @@ class NearbyStation extends React.Component {
|
|||||||
Longitude coord:
|
Longitude coord:
|
||||||
<input type="text" name="long" onChange={this.handleChangeLong} />
|
<input type="text" name="long" onChange={this.handleChangeLong} />
|
||||||
</label>
|
</label>
|
||||||
<label>
|
|
||||||
Token:
|
|
||||||
<input type="text" name="token" onChange={this.handleChangeToken} />
|
|
||||||
</label>
|
|
||||||
<button type="submit">Stops</button>
|
<button type="submit">Stops</button>
|
||||||
</form>
|
</form>
|
||||||
<h1>
|
<h1>
|
||||||
|
Loading…
Reference in New Issue
Block a user