Prettied UI for the auth controls
This commit is contained in:
@@ -1,13 +1,14 @@
|
|||||||
/**
|
/**
|
||||||
* Created by andrew on 12/02/16.
|
* Created by andrew on 12/02/16.
|
||||||
*/
|
*/
|
||||||
import { AuthGlobals } from "redux-auth/bootstrap-theme";
|
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Provider} from "react-redux";
|
import { Provider} from "react-redux";
|
||||||
import { ReduxRouter} from "redux-router";
|
import { ReduxRouter} from "redux-router";
|
||||||
import { Route, IndexRoute} from "react-router";
|
import { Route, IndexRoute} from "react-router";
|
||||||
import { configure, authStateReducer} from "redux-auth";
|
import { configure, authStateReducer} from "redux-auth";
|
||||||
|
import { AuthGlobals } from "redux-auth/bootstrap-theme";
|
||||||
|
|
||||||
import { createStore, compose, applyMiddleware} from "redux";
|
import { createStore, compose, applyMiddleware} from "redux";
|
||||||
import { createHistory, createMemoryHistory} from "history";
|
import { createHistory, createMemoryHistory} from "history";
|
||||||
import { routerStateReducer, reduxReactRouter as clientRouter} from "redux-router";
|
import { routerStateReducer, reduxReactRouter as clientRouter} from "redux-router";
|
||||||
@@ -15,6 +16,9 @@ import { reduxReactRouter as serverRouter } from "redux-router/server";
|
|||||||
import { combineReducers} from "redux";
|
import { combineReducers} from "redux";
|
||||||
import thunk from "redux-thunk";
|
import thunk from "redux-thunk";
|
||||||
|
|
||||||
|
import {connect} from 'react-redux';
|
||||||
|
import {pushState} from 'redux-router';
|
||||||
|
|
||||||
//import demoButtons from "./reducers/request-test-buttons";
|
//import demoButtons from "./reducers/request-test-buttons";
|
||||||
//import demoUi from "./reducers/demo-ui";
|
//import demoUi from "./reducers/demo-ui";
|
||||||
//import Container from "./views/partials/Container";
|
//import Container from "./views/partials/Container";
|
||||||
@@ -80,29 +84,73 @@ export function initialize({cookies, isServer, currentLocation, userAgent} = {})
|
|||||||
//demoUi
|
//demoUi
|
||||||
});
|
});
|
||||||
|
|
||||||
let store;
|
//let store;
|
||||||
|
|
||||||
// access control method, used above in the "account" route
|
//// access control method, used above in the "account" route
|
||||||
const requireAuth = (nextState, transition, cb) => {
|
//const requireAuth = (nextState, transition, cb) => {
|
||||||
// the setTimeout is necessary because of this bug:
|
// // the setTimeout is necessary because of this bug:
|
||||||
// https://github.com/rackt/redux-router/pull/62
|
// // https://github.com/rackt/redux-router/pull/62
|
||||||
// this will result in a bunch of warnings, but it doesn't seem to be a serious problem
|
// // this will result in a bunch of warnings, but it doesn't seem to be a serious problem
|
||||||
setTimeout(() => {
|
// setTimeout(() => {
|
||||||
debugger;
|
// if (!store.getState().auth.getIn(["user", "isSignedIn"])) {
|
||||||
if (!store.getState().auth.getIn(["user", "isSignedIn"])) {
|
// transition(null, "/login");
|
||||||
transition(null, "/login");
|
// }
|
||||||
|
// cb();
|
||||||
|
// }, 0);
|
||||||
|
//};
|
||||||
|
|
||||||
|
const requireAuthentication = (Component) => {
|
||||||
|
class AuthenticatedComponent extends React.Component {
|
||||||
|
|
||||||
|
componentWillMount() {
|
||||||
|
this.checkAuth();
|
||||||
}
|
}
|
||||||
cb();
|
|
||||||
}, 0);
|
componentWillReceiveProps(nextProps) {
|
||||||
|
this.checkAuth();
|
||||||
|
}
|
||||||
|
|
||||||
|
checkAuth() {
|
||||||
|
debugger;
|
||||||
|
if (!this.props.isAuthenticated) {
|
||||||
|
let redirectAfterLogin = this.props.location.pathname;
|
||||||
|
this.props.dispatch(pushState(null, `/login?next=${redirectAfterLogin}`));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
debugger;
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{this.props.isAuthenticated === true
|
||||||
|
? <Component {...this.props}/>
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = (state) => ({
|
||||||
|
token: state.auth.token,
|
||||||
|
userName: state.auth.userName,
|
||||||
|
isAuthenticated: state.auth.isAuthenticated
|
||||||
|
});
|
||||||
|
|
||||||
|
return connect(mapStateToProps)(AuthenticatedComponent);
|
||||||
};
|
};
|
||||||
|
|
||||||
// define app routes
|
// define app routes
|
||||||
|
// <Route path="account" component={Account} onEnter={requireAuth} />
|
||||||
|
|
||||||
const routes = (
|
const routes = (
|
||||||
<Route path="/" component={App}>
|
<Route path="/" component={App}>
|
||||||
<IndexRoute component={Main} />
|
<IndexRoute component={Main} />
|
||||||
<Route path="login" component={SignIn} />
|
<Route path="login" component={SignIn} />
|
||||||
<Route path="register" component={SignUp} />
|
<Route path="register" component={SignUp} />
|
||||||
<Route path="account" component={Account} onEnter={requireAuth} />
|
<Route path="account" component={requireAuthentication(Account)} />
|
||||||
|
<Route path="account2" component={requireAuthentication(Account)} />
|
||||||
</Route>
|
</Route>
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -116,7 +164,7 @@ export function initialize({cookies, isServer, currentLocation, userAgent} = {})
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create the redux store
|
// create the redux store
|
||||||
store = compose(
|
const store = compose(
|
||||||
applyMiddleware(thunk),
|
applyMiddleware(thunk),
|
||||||
reduxReactRouter({
|
reduxReactRouter({
|
||||||
createHistory: createHistoryMethod,
|
createHistory: createHistoryMethod,
|
||||||
@@ -164,6 +212,12 @@ export function initialize({cookies, isServer, currentLocation, userAgent} = {})
|
|||||||
global.navigator = {userAgent};
|
global.navigator = {userAgent};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (blank) {
|
||||||
|
// if `blank` is true, this is an OAuth redirect and should not
|
||||||
|
// be rendered
|
||||||
|
return <noscript />;
|
||||||
|
}
|
||||||
|
|
||||||
return ({
|
return ({
|
||||||
blank,
|
blank,
|
||||||
store,
|
store,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||||
|
|
||||||
<title>Money Transfer App</title>
|
<title>Money Transfer App</title>
|
||||||
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
|
||||||
|
|
||||||
<!-- inject:app:css -->
|
<!-- inject:app:css -->
|
||||||
<!-- endinject -->
|
<!-- endinject -->
|
||||||
|
|||||||
@@ -5,14 +5,18 @@ import React from "react";
|
|||||||
import { PageHeader } from "react-bootstrap";
|
import { PageHeader } from "react-bootstrap";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
|
|
||||||
|
// bootstrap theme
|
||||||
|
import { EmailSignInForm } from "redux-auth/bootstrap-theme";
|
||||||
|
|
||||||
export class SignIn extends React.Component {
|
export class SignIn extends React.Component {
|
||||||
render () {
|
render () {
|
||||||
return (
|
return <EmailSignInForm />;
|
||||||
<div>
|
//return (
|
||||||
<PageHeader>Sign In First</PageHeader>
|
// <div>
|
||||||
<p>Unauthenticated users can't access the account page.</p>
|
// <PageHeader>Sign In First</PageHeader>
|
||||||
</div>
|
// <p>Unauthenticated users can't access the account page.</p>
|
||||||
);
|
// </div>
|
||||||
|
//);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export default connect(({routes}) => ({routes}))(SignIn);
|
export default connect(({routes}) => ({routes}))(SignIn);
|
||||||
|
|||||||
@@ -5,14 +5,18 @@ import React from "react";
|
|||||||
import { PageHeader } from "react-bootstrap";
|
import { PageHeader } from "react-bootstrap";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
|
|
||||||
|
import { EmailSignUpForm } from "redux-auth/bootstrap-theme"
|
||||||
|
|
||||||
export class SignUp extends React.Component {
|
export class SignUp extends React.Component {
|
||||||
render () {
|
render () {
|
||||||
return (
|
|
||||||
<div>
|
return <EmailSignUpForm />;
|
||||||
<PageHeader>Sign Up Page</PageHeader>
|
//return (
|
||||||
<p>Here you can register.</p>
|
// <div>
|
||||||
</div>
|
// <PageHeader>Sign Up Page</PageHeader>
|
||||||
);
|
// <p>Here you can register.</p>
|
||||||
|
// </div>
|
||||||
|
//);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export default connect(({routes}) => ({routes}))(SignUp);
|
export default connect(({routes}) => ({routes}))(SignUp);
|
||||||
Reference in New Issue
Block a user