Guest User

Untitled

a guest
May 28th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. class LoginForm extends React.Component {
  2. constructor(props){
  3. super();
  4. this.state = {
  5. username: '',
  6. password: ''
  7. };
  8. this.onInputUsernameChange = this.onInputUsernameChange.bind(this);
  9. this.onInputPasswordChange = this.onInputPasswordChange.bind(this);
  10. this.onSubmit = this.onSubmit.bind(this);
  11. }
  12.  
  13. onSubmit(){
  14. const ROOT_URL = "http://localhost:8000";
  15. let self = this
  16. axios.post(ROOT_URL + '/login',{
  17. email: self.state.username,
  18. password: self.state.password
  19. })
  20. .then(response => {
  21. if(response.status===200){
  22. this.props.onRequestToken(response.data)
  23. self.props.history.push("/books");
  24. }
  25. })
  26. .catch(function (error) {
  27. alert("Invalid login or password! Try again!")
  28. });
  29. }
  30.  
  31. ....
  32.  
  33. const mapDispatchToProps = dispatch => {
  34. return {
  35. onRequestToken: (token) => dispatch({ type: "TOKEN_PUSH", token})
  36. };
  37. };
  38.  
  39. export default withRouter(
  40. connect(null, mapDispatchToProps)(LoginForm));
  41.  
  42. const rootReducer = combineReducers({
  43. usersReducer,
  44. rentsReducer,
  45. booksReducer,
  46. customerReducer,
  47. authorsReducer,
  48. rolesReducer,
  49. tokenReducer,
  50. router: routerReducer
  51. })
  52.  
  53. export default rootReducer
  54.  
  55. class App extends Component {
  56. render() {
  57. return (
  58. <Provider store={this.props.store}>
  59. <BrowserRouter>
  60. <section style={{ width: '100%', height: '100vh', minWidth:
  61. '600px'}}>
  62. <Navigation />
  63. <Switch>
  64. <Route exact path="/" render={props => <LoginPage {...props}
  65. />} />
  66. <Route exact path="/login" render={props => <LoginPage
  67. {...props} />} />
  68. <Route exact path="/rents" render={props => <RentsPage
  69. {...props} />} />
  70.  
  71. ....
  72.  
  73. </Switch>
  74. </section>
  75. </BrowserRouter>
  76. </Provider>);}
  77. }
  78.  
  79. export default function* rootSaga() {
  80. yield fork(rentSagas);
  81. yield fork(bookSagas);
  82. yield fork(customerSagas);
  83. yield fork(authorsSagas);
  84. yield fork(rolesSagas);
  85. yield fork(usersSagas);
  86. }
  87.  
  88. const history = createHistory()
  89. const middleware = routerMiddleware(history)
  90.  
  91. const sagaMiddleware = createSagaMiddleware()
  92. const store = createStore(
  93. rootReducer,
  94. applyMiddleware(sagaMiddleware, middleware))
  95.  
  96. sagaMiddleware.run(rootSaga)
  97.  
  98. ReactDOM.render(<App store={store}/>, document.getElementById('root'));
  99. registerServiceWorker();
Add Comment
Please, Sign In to add comment