mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-02-14 16:27:17 +00:00
show authorize form when auth error
This commit is contained in:
parent
0737a249b9
commit
1e6751323d
@ -15,7 +15,7 @@ function action(type, payload = {}) {
|
|||||||
|
|
||||||
export const AUTHENTICATE = createRequestTypes('AUTHENTICATE');
|
export const AUTHENTICATE = createRequestTypes('AUTHENTICATE');
|
||||||
export const authenticate = {
|
export const authenticate = {
|
||||||
request: (token) => action(AUTHENTICATE[REQUEST], {token}),
|
request: (token, callback) => action(AUTHENTICATE[REQUEST], {token, callback}),
|
||||||
success: () => action(AUTHENTICATE[SUCCESS]),
|
success: () => action(AUTHENTICATE[SUCCESS]),
|
||||||
failure: (error) => action(AUTHENTICATE[FAILURE], {error})
|
failure: (error) => action(AUTHENTICATE[FAILURE], {error})
|
||||||
};
|
};
|
||||||
|
@ -2,6 +2,7 @@ import PropTypes from "prop-types";
|
|||||||
import {connect} from 'react-redux';
|
import {connect} from 'react-redux';
|
||||||
import React, {Component} from 'react';
|
import React, {Component} from 'react';
|
||||||
import {withRouter} from "react-router-dom";
|
import {withRouter} from "react-router-dom";
|
||||||
|
import {Alert, Page, Form, Button} from "tabler-react";
|
||||||
|
|
||||||
import routes from '../routes';
|
import routes from '../routes';
|
||||||
import queryString from 'query-string';
|
import queryString from 'query-string';
|
||||||
@ -16,6 +17,12 @@ import {
|
|||||||
} from '../actions';
|
} from '../actions';
|
||||||
|
|
||||||
class AppContainer extends Component {
|
class AppContainer extends Component {
|
||||||
|
constructor (props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
authenticateError: null
|
||||||
|
};
|
||||||
|
}
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
let token;
|
let token;
|
||||||
if (this.props.location.search) {
|
if (this.props.location.search) {
|
||||||
@ -24,7 +31,12 @@ class AppContainer extends Component {
|
|||||||
} else {
|
} else {
|
||||||
token = cacheGet('token');
|
token = cacheGet('token');
|
||||||
}
|
}
|
||||||
this.props.authenticate(token);
|
this.props.authenticate(token, (err) => {
|
||||||
|
if (err) {
|
||||||
|
return this.setState({authenticateError: err});
|
||||||
|
}
|
||||||
|
this.setState({authenticateError: null});
|
||||||
|
});
|
||||||
this.props.initBlockHeader();
|
this.props.initBlockHeader();
|
||||||
this.props.fetchProcesses();
|
this.props.fetchProcesses();
|
||||||
this.props.fetchVersions();
|
this.props.fetchVersions();
|
||||||
@ -32,6 +44,19 @@ class AppContainer extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
if (this.state.authenticateError) {
|
||||||
|
return <Page.Content>
|
||||||
|
<Alert type="danger">
|
||||||
|
{this.state.authenticateError}
|
||||||
|
</Alert>
|
||||||
|
<Form>
|
||||||
|
<Form.Input name="token" label="Token" placeholder="Enter Token"/>
|
||||||
|
<Button type="submit" color="primary">
|
||||||
|
Authorize
|
||||||
|
</Button>
|
||||||
|
</Form>
|
||||||
|
</Page.Content>;
|
||||||
|
}
|
||||||
return (<React.Fragment>{routes}</React.Fragment>);
|
return (<React.Fragment>{routes}</React.Fragment>);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,18 @@ function get(path, params, endpoint) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function post(path, params) {
|
function post(path, params) {
|
||||||
|
const callback = params.callback || function(){};
|
||||||
|
delete params.callback;
|
||||||
return axios.post(constants.httpEndpoint + path, params)
|
return axios.post(constants.httpEndpoint + path, params)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
return {response, error: null};
|
const data = (response.data && response.data.error) ? {error: response.data.error} : {response, error: null};
|
||||||
|
callback(data.error, data.response);
|
||||||
|
return data;
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
return {response: null, error: error.message || 'Something bad happened'};
|
const data = {response: null, error: error.message || 'Something bad happened'};
|
||||||
|
callback(data.error, data.response);
|
||||||
|
return data;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class Authenticator {
|
|||||||
this.logger.warn(__('Someone tried and failed to authenticate to the backend'));
|
this.logger.warn(__('Someone tried and failed to authenticate to the backend'));
|
||||||
this.logger.warn(__('- User-Agent: %s', req.headers['user-agent']));
|
this.logger.warn(__('- User-Agent: %s', req.headers['user-agent']));
|
||||||
this.logger.warn(__('- Referer: %s', req.headers.referer));
|
this.logger.warn(__('- Referer: %s', req.headers.referer));
|
||||||
return res.status(403).send({error: __('Wrong authentication token')});
|
return res.send({error: __('Wrong authentication token. Get your token from the Embark console by typing `token`')});
|
||||||
}
|
}
|
||||||
res.send();
|
res.send();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user