Skip to content

Commit

Permalink
feat(login): local login feature
Browse files Browse the repository at this point in the history
- add tests
- add login action creators
- add welcome page component

[Starts #161290964]
  • Loading branch information
tersoo-atsen committed Dec 19, 2018
1 parent fac4eaa commit 133bc3a
Show file tree
Hide file tree
Showing 17 changed files with 306 additions and 155 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const express = require('express');
const path = require('path');
const dotenv = require('dotenv');

dotenv.config();

const app = express();
const PORT = process.env.PORT || 3000;
Expand Down
109 changes: 28 additions & 81 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions public/styles/Welcome.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

.welcome {
margin-top: 5em;
}
2 changes: 2 additions & 0 deletions public/styles/index.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import url('https://fonts.googleapis.com/css?family=Zilla+Slab:300,300i,400,500,600,700|Open+Sans:300,400,600,700,800');
@import 'react-redux-toastr/src/styles/index';

@import 'react-redux-toastr/src/styles/index';
@import './variables';
Expand All @@ -11,6 +12,7 @@
@import './Navbar';
@import './AllArticles';
@import './NewArticle';
@import './Welcome';
@import './Spinner';

* {
Expand Down
1 change: 1 addition & 0 deletions public/styles/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ $login-placeholder-color: rgba(0, 0, 0, 0.25);
$pagination-button: #ededed;
$header-border-color: #e4e4e4;
$spinner-overlay: rgba(255, 255, 255, 0.6);

// font variable
$font-general: 'Open Sans', serif;
$font-welcome: 'Zilla Slab', serif;
Expand Down
9 changes: 4 additions & 5 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
import { PersistGate } from 'redux-persist/integration/react';
import { Provider } from 'react-redux';
import ReduxToastr from 'react-redux-toastr';

import routes from './routes';
import { persistor, store } from './store/store';
import NotFound from './components/404/NotFound';
Expand All @@ -24,8 +23,8 @@ class App extends Component {

render() {
return (
<PersistGate persistor={persistor}>
<Provider store={store}>
<Provider store={store}>
<PersistGate persistor={persistor}>
<Router>
<Fragment>
<Header />
Expand Down Expand Up @@ -56,8 +55,8 @@ class App extends Component {
/>
</Fragment>
</Router>
</Provider>
</PersistGate>
</PersistGate>
</Provider>
);
}
}
Expand Down
33 changes: 33 additions & 0 deletions src/actions/loginActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { toastr } from 'react-redux-toastr';

import { globalLoading, globalFailure, globalLoggedIn } from './globalActions';
import requestOptions from '../utils/requestOptions';

export const sendEmailLink = email => dispatch => fetch(`${process.env.API_BASE_URL}/users/login`, requestOptions({ email }, 'POST', null))
.then(
res => res.json(),
error => dispatch(globalFailure(['An error has occured', error]))
)
.then((jsonResponse) => {
if (jsonResponse.errors) {
dispatch(globalFailure(jsonResponse.errors));
toastr.error('There was an error please try again');
} else {
toastr.success('Email sent successfully! Check your email.');
}
});

export const logUserIn = tokenQueryString => dispatch => fetch(`${process.env.API_BASE_URL}/users/login${tokenQueryString}`)
.then(res => res.json(), error => dispatch(globalFailure(['We were unable to log you in, please try again.', error])))
.then((jsonResponse) => {
if (jsonResponse.errors) {
dispatch(globalFailure(jsonResponse.errors));
toastr.error('An error has occured, please try again!');
} else {
dispatch(globalLoading(true));
localStorage.setItem('token', JSON.stringify(jsonResponse.user.token));
dispatch(globalLoggedIn(true));
toastr.success('Login was was successful');
dispatch(globalLoading(false));
}
});
56 changes: 0 additions & 56 deletions src/components/Button.js

This file was deleted.

Loading

0 comments on commit 133bc3a

Please sign in to comment.