#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

View File

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

View File

@ -15,8 +15,9 @@ import loader from 'services/loader';
import logger from 'services/logger';
import font from 'services/font';
import history, { browserHistory } from 'services/history';
import RootPage from 'pages/root/RootPage';
import AuthFlowRoute from 'containers/AuthFlowRoute';
import RootPage from 'pages/root/RootPage';
import SuccessOauthPage from 'pages/auth/SuccessOauthPage';
history.init();
@ -39,7 +40,8 @@ Promise.all([
<IntlProvider>
<Router history={browserHistory}>
<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} />
</Switch>
</Router>

View File

@ -1,27 +1,48 @@
// @flow
import React, { Component } from 'react';
import { FooterMenu } from 'components/footerMenu';
import { Link } from 'react-router-dom';
import { FormattedMessage as Message } from 'react-intl';
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 styles from './success-oauth.scss';
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 {
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() {
// TODO: detect GET param `appName`
// TODO: попытаться заркыть окно с помощью https://stackoverflow.com/a/31163281/5184751
const {appName} = this.props;
const appName = this.props.location.query.get('appName');
return (
<div className={styles.page}>
@ -54,10 +75,6 @@ export default class SuccessOauthPage extends Component {
<Message {...messages.youCanCloseThisPage} />
</div>
</div>
<div className={profileStyles.footer}>
<FooterMenu/>
</div>
</div>
);
}

View File

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

View File

@ -1,6 +1,15 @@
import request from './request';
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 { InternalServerError };