#346: Setup router for oauth success page for code response type

This commit is contained in:
SleepWalker 2017-08-07 23:11:39 +03:00
parent 38778628ee
commit 89d42a7363
8 changed files with 51 additions and 24 deletions

View File

@ -1,4 +1,4 @@
import { PropTypes } from 'react'; import PropTypes from 'prop-types';
/** /**
* @typedef {object} User * @typedef {object} User

View File

@ -1,18 +1,21 @@
// @flow // @flow
import { UPDATE, SET, CHANGE_LANG } from './actions'; import { UPDATE, SET, CHANGE_LANG } from './actions';
export type User = { export type User = {|
id: ?number, id: ?number,
uuid: ?string, uuid: ?string,
token: string, token: string,
username: string, username: string,
email: string, email: string,
avatar: string, avatar: string,
isGuest: boolean, lang: string,
isActive: boolean, isGuest: bool,
isActive: bool,
passwordChangedAt: ?number, passwordChangedAt: ?number,
hasMojangUsernameCollision: bool, hasMojangUsernameCollision: bool,
}; maskedEmail?: string,
shouldAcceptRules?: bool,
|};
const defaults: User = { const defaults: User = {
@ -32,8 +35,7 @@ const defaults: User = {
hasMojangUsernameCollision: false, hasMojangUsernameCollision: false,
// frontend specific attributes // frontend specific attributes
isGuest: true, isGuest: true
goal: null // the goal with wich user entered site
}; };
export default function user( export default function user(

View File

@ -15,8 +15,9 @@ import loader from 'services/loader';
import logger from 'services/logger'; import logger from 'services/logger';
import font from 'services/font'; import font from 'services/font';
import history, { browserHistory } from 'services/history'; import history, { browserHistory } from 'services/history';
import RootPage from 'pages/root/RootPage';
import AuthFlowRoute from 'containers/AuthFlowRoute'; import AuthFlowRoute from 'containers/AuthFlowRoute';
import RootPage from 'pages/root/RootPage';
import SuccessOauthPage from 'pages/auth/SuccessOauthPage';
history.init(); history.init();
@ -39,7 +40,8 @@ Promise.all([
<IntlProvider> <IntlProvider>
<Router history={browserHistory}> <Router history={browserHistory}>
<Switch> <Switch>
<AuthFlowRoute path="/oauth2/:version/:clientId?" component={() => null} /> <Route path="/oauth2/code/success" component={SuccessOauthPage} />
<AuthFlowRoute path="/oauth2/:version(v\d+)/:clientId?" component={() => null} />
<Route path="/" component={RootPage} /> <Route path="/" component={RootPage} />
</Switch> </Switch>
</Router> </Router>

View File

@ -1,27 +1,48 @@
// @flow // @flow
import React, { Component } from 'react'; import React, { Component } from 'react';
import { FooterMenu } from 'components/footerMenu';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { FormattedMessage as Message } from 'react-intl'; import { FormattedMessage as Message } from 'react-intl';
import Helmet from 'react-helmet'; import Helmet from 'react-helmet';
import styles from './success-oauth.scss'; import loader from 'services/loader';
import rootMessages from 'pages/root/RootPage.intl.json'; import rootMessages from 'pages/root/RootPage.intl.json';
import styles from './success-oauth.scss';
import messages from './SuccessOauthPage.intl.json'; import messages from './SuccessOauthPage.intl.json';
import profileStyles from 'pages/profile/profile.scss'; import type { Query } from 'services/request';
export default class SuccessOauthPage extends Component { export default class SuccessOauthPage extends Component {
props: { props: {
appName: ?string location: {
query: Query<'appName'>
}
}; };
componentDidMount() {
this.onPageUpdate();
setTimeout(() => {
try {
// try to close window if possible
window.open('', '_self').close();
} catch (err) {
// don't care
}
}, 8000);
}
componentDidUpdate() {
this.onPageUpdate();
}
onPageUpdate() {
loader.hide();
}
render() { render() {
// TODO: detect GET param `appName` const appName = this.props.location.query.get('appName');
// TODO: попытаться заркыть окно с помощью https://stackoverflow.com/a/31163281/5184751
const {appName} = this.props;
return ( return (
<div className={styles.page}> <div className={styles.page}>
@ -54,10 +75,6 @@ export default class SuccessOauthPage extends Component {
<Message {...messages.youCanCloseThisPage} /> <Message {...messages.youCanCloseThisPage} />
</div> </div>
</div> </div>
<div className={profileStyles.footer}>
<FooterMenu/>
</div>
</div> </div>
); );
} }

View File

@ -10,7 +10,6 @@ import AuthPage from 'pages/auth/AuthPage';
import ProfilePage from 'pages/profile/ProfilePage'; import ProfilePage from 'pages/profile/ProfilePage';
import RulesPage from 'pages/rules/RulesPage'; import RulesPage from 'pages/rules/RulesPage';
import PageNotFound from 'pages/404/PageNotFound'; import PageNotFound from 'pages/404/PageNotFound';
import SuccessOauthPage from 'pages/static/SuccessOauthPage';
import { restoreScroll } from 'functions'; import { restoreScroll } from 'functions';
import PrivateRoute from 'containers/PrivateRoute'; import PrivateRoute from 'containers/PrivateRoute';
@ -88,8 +87,6 @@ class RootPage extends Component {
)} )}
<div className={styles.body}> <div className={styles.body}>
<Switch> <Switch>
{ /* TODO: это должен быть /oauth2/code/success */ }
<Route path="/oauth/code/success" component={SuccessOauthPage} />
<PrivateRoute path="/profile" component={ProfilePage} /> <PrivateRoute path="/profile" component={ProfilePage} />
<Route path="/404" component={PageNotFound} /> <Route path="/404" component={PageNotFound} />
<Route path="/rules" component={RulesPage} /> <Route path="/rules" component={RulesPage} />

View File

@ -1,6 +1,15 @@
import request from './request'; import request from './request';
import InternalServerError from './InternalServerError'; import InternalServerError from './InternalServerError';
/**
* Usage: Query<'requeired'|'keys'|'names'>
* TODO: find a way to make it more friendly with URLSearchParams type
*/
export type Query<T: string> = {
get: (key: T) => ?string,
set: (key: T, value: any) => void,
};
export default request; export default request;
export { InternalServerError }; export { InternalServerError };