Commit 9f1b0a7532d23ba0be04e8481f7f69173358f351
1 parent
d8f42d39
Exists in
master
V.0.9.0 - Login and Logout working
Showing
10 changed files
with
86 additions
and
146 deletions
Show diff stats
app.js
... | ... | @@ -40,18 +40,19 @@ app.set("views", path.join(__dirname, "views")); |
40 | 40 | app.set("view engine", "pug"); |
41 | 41 | |
42 | 42 | // uncomment after placing your favicon in /public |
43 | -app.use( | |
44 | - cookieSession({ | |
45 | - maxAge: 30 * 24 * 60 * 60 * 1000, // 30 days | |
46 | - keys: [keys.cookieKey] | |
47 | - }) | |
48 | -); | |
49 | 43 | app.use(favicon(path.join(__dirname, "public", "favicon.ico"))); |
50 | 44 | app.use(logger("dev")); |
51 | 45 | app.use(bodyParser.json()); |
52 | 46 | app.use(bodyParser.urlencoded({ extended: false })); |
53 | 47 | app.use(cookieParser()); |
54 | 48 | app.use(express.static(path.join(__dirname, "public"))); |
49 | +// intersept all incoming requests | |
50 | +app.use( | |
51 | + cookieSession({ | |
52 | + maxAge: 30 * 24 * 60 * 60 * 1000, // 30 days | |
53 | + keys: [keys.cookieKey] | |
54 | + }) | |
55 | +); | |
55 | 56 | app.use(passport.initialize()); |
56 | 57 | app.use(passport.session()); |
57 | 58 | ... | ... |
client/package.json
... | ... | @@ -6,22 +6,16 @@ |
6 | 6 | "/map": { |
7 | 7 | "target": "http://localhost:5000" |
8 | 8 | }, |
9 | - "/map/pedro": { | |
9 | + "/map/*": { | |
10 | 10 | "target": "http://localhost:5000" |
11 | 11 | }, |
12 | 12 | "/stylesheets": { |
13 | 13 | "target": "http://localhost:5000" |
14 | 14 | }, |
15 | - "/auth/google": { | |
15 | + "/auth/*": { | |
16 | 16 | "target": "http://localhost:5000" |
17 | 17 | }, |
18 | - "/auth/google/callback": { | |
19 | - "target": "http://localhost:5000" | |
20 | - }, | |
21 | - "/api/current_user": { | |
22 | - "target": "http://localhost:5000" | |
23 | - }, | |
24 | - "/api/logout": { | |
18 | + "/api/*": { | |
25 | 19 | "target": "http://localhost:5000" |
26 | 20 | }, |
27 | 21 | "/consumidores": { |
... | ... | @@ -32,15 +26,23 @@ |
32 | 26 | } |
33 | 27 | }, |
34 | 28 | "dependencies": { |
29 | + "@material-ui/core": "^1.4.2", | |
30 | + "@material-ui/icons": "^2.0.0", | |
31 | + "@types/react-redux": "^6.0.6", | |
35 | 32 | "ajv": "^6.5.0", |
36 | - "axios": "0.17.1", | |
33 | + "axios": "^0.17.1", | |
37 | 34 | "faker": "^4.1.0", |
38 | 35 | "react": "^16.4.0", |
39 | 36 | "react-dom": "^16.4.0", |
40 | 37 | "react-iframe": "^1.2.0", |
38 | + "react-redux": "^5.0.7", | |
39 | + "react-router-dom": "^4.3.1", | |
41 | 40 | "react-scripts": "1.1.4", |
42 | 41 | "react-select": "1.1.0", |
42 | + "redux": "^4.0.0", | |
43 | + "redux-thunk": "^2.3.0", | |
43 | 44 | "source-map-explorer": "^1.5.0", |
45 | + "typeface-roboto": "0.0.54", | |
44 | 46 | "util": "^0.10.3" |
45 | 47 | }, |
46 | 48 | "scripts": { | ... | ... |
client/public/index.html
... | ... | @@ -7,6 +7,7 @@ |
7 | 7 | <meta name="theme-color" content="#000000"> |
8 | 8 | <link rel="manifest" href="%PUBLIC_URL%/manifest.json"> |
9 | 9 | <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico"> |
10 | + <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"> | |
10 | 11 | <title>NEXUS</title> |
11 | 12 | </head> |
12 | 13 | <body> | ... | ... |
client/public/index1.html
... | ... | @@ -1,18 +0,0 @@ |
1 | -<!-- Html start page --> | |
2 | -<!DOCTYPE html> | |
3 | -<html lang="en"> | |
4 | - <head> | |
5 | - <meta charset="utf-8"> | |
6 | - <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
7 | - <meta name="theme-color" content="#000000"> | |
8 | - <link rel="manifest" href="%PUBLIC_URL%/manifest.json"> | |
9 | - <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico"> | |
10 | - <title>NEXUS1</title> | |
11 | - </head> | |
12 | - <body> | |
13 | - <noscript> | |
14 | - You need to enable JavaScript to run this app. | |
15 | - </noscript> | |
16 | - <div id="root"></div> | |
17 | - </body> | |
18 | -</html> |
client/src/App.css
... | ... | @@ -1,28 +0,0 @@ |
1 | -.App { | |
2 | - text-align: center; | |
3 | -} | |
4 | - | |
5 | -.App-logo { | |
6 | - animation: App-logo-spin infinite 20s linear; | |
7 | - height: 80px; | |
8 | -} | |
9 | - | |
10 | -.App-header { | |
11 | - background-color: #222; | |
12 | - height: 150px; | |
13 | - padding: 20px; | |
14 | - color: white; | |
15 | -} | |
16 | - | |
17 | -.App-title { | |
18 | - font-size: 1.5em; | |
19 | -} | |
20 | - | |
21 | -.App-intro { | |
22 | - font-size: large; | |
23 | -} | |
24 | - | |
25 | -@keyframes App-logo-spin { | |
26 | - from { transform: rotate(0deg); } | |
27 | - to { transform: rotate(360deg); } | |
28 | -} |
client/src/App.js
... | ... | @@ -1,21 +0,0 @@ |
1 | -import React, { Component } from "react"; | |
2 | -import "./App.css"; | |
3 | -import FindConsumer from "./components/findConsumer"; | |
4 | -import Map from "./components/map"; | |
5 | - | |
6 | -class App extends Component { | |
7 | - render() { | |
8 | - return ( | |
9 | - <div className="App"> | |
10 | - <div> | |
11 | - <FindConsumer /> | |
12 | - </div> | |
13 | - <div> | |
14 | - <Map /> | |
15 | - </div> | |
16 | - </div> | |
17 | - ); | |
18 | - } | |
19 | -} | |
20 | - | |
21 | -export default App; |
client/src/App.test.js
client/src/components/map.js
1 | -import React, { Component } from 'react'; | |
2 | -import Iframe from 'react-iframe'; | |
3 | -import 'react-select/dist/react-select.css'; | |
1 | +import React, { Component } from 'react' | |
2 | +import Iframe from 'react-iframe' | |
3 | +import 'react-select/dist/react-select.css' | |
4 | 4 | |
5 | -export default class Map extends Component<*, State> { | |
6 | - constructor(props) { | |
7 | - super(props); | |
8 | - this.state = { | |
9 | - }; | |
10 | - } | |
11 | - render() { | |
12 | - return ( | |
13 | - <div> | |
14 | - <Iframe url="/map/pedro" position="absolute" width="100%" height="95%" id="mapId" allowFullScreen /> | |
15 | - </div> | |
16 | - ); | |
17 | - } | |
5 | +export default class Map extends Component { | |
6 | + constructor (props) { | |
7 | + super(props) | |
8 | + this.state = {} | |
9 | + } | |
10 | + render () { | |
11 | + return ( | |
12 | + <div> | |
13 | + <Iframe url='/map/pedro' position='absolute' width='100%' height='95%' id='mapId' allowFullScreen /> | |
14 | + </div> | |
15 | + ) | |
16 | + } | |
18 | 17 | } | ... | ... |
client/src/index.js
... | ... | @@ -3,11 +3,24 @@ |
3 | 3 | * @author José Maria Villac Pinheiro |
4 | 4 | * @date 2018-07-19 |
5 | 5 | */ |
6 | -import React from "react"; | |
7 | -import ReactDOM from "react-dom"; | |
8 | -import "./index.css"; | |
9 | -import App from "./App"; | |
6 | +import 'typeface-roboto'; | |
7 | +import React from 'react'; | |
8 | +import ReactDOM from 'react-dom'; | |
9 | +import { Provider } from 'react-redux'; | |
10 | +import { createStore, applyMiddleware } from 'redux'; | |
11 | +import reduxThunk from "redux-thunk"; | |
12 | + | |
13 | +import './index.css'; | |
14 | +import App from './components/App'; | |
10 | 15 | // import registerServiceWorker from "./registerServiceWorker"; |
16 | +import reducers from './reducers'; | |
17 | + | |
18 | +const store = createStore(reducers, {}, applyMiddleware(reduxThunk)); | |
11 | 19 | |
12 | -ReactDOM.render(<App />, document.getElementById("root")); | |
20 | +ReactDOM.render( | |
21 | + <Provider store={store}> | |
22 | + <App /> | |
23 | + </Provider>, | |
24 | + document.getElementById('root') | |
25 | +); | |
13 | 26 | // registerServiceWorker(); | ... | ... |
routes/authRoutes.js
1 | 1 | // Autentication routes |
2 | 2 | // |
3 | -const passport = require("passport"); // from npm | |
3 | +const passport = require('passport') // from npm | |
4 | 4 | |
5 | 5 | module.exports = router => { |
6 | - // Enter to authenticate the user | |
6 | + // Enter to authenticate the user | |
7 | 7 | router.get( |
8 | - "/auth/google", | |
9 | - passport.authenticate("google", { | |
10 | - scope: ["profile", "email"] | |
11 | - }) | |
12 | - ); | |
8 | + '/auth/google', | |
9 | + passport.authenticate('google', { | |
10 | + scope: ['profile', 'email'] | |
11 | + }) | |
12 | + ) | |
13 | 13 | |
14 | - // Page after authenticate | |
14 | + // Page after authenticate | |
15 | 15 | router.get( |
16 | - "/auth/google/callback", | |
17 | - passport.authenticate("google"), | |
18 | - (err, req, res, next) => { | |
19 | - // custom error handler to catch any errors, such as TokenError | |
20 | - if (err.name === "TokenError") { | |
21 | - res.redirect("http://nexusbr.com"); // redirect them back to the login page | |
22 | - } else { | |
23 | - console.log("Falhou ao logar!"); | |
24 | - // Handle other errors here | |
25 | - } | |
26 | - }, | |
27 | - (req, res) => { | |
28 | - console.log("Logou com sucesso!"); | |
29 | - // On success, redirect back to '/' | |
30 | - res.redirect("/"); | |
31 | - } | |
32 | - ); | |
16 | + '/auth/google/callback', | |
17 | + passport.authenticate('google'), // middleware to authenticate the user, after authenticate it passes to callbark | |
18 | + (err, req, res, next) => { | |
19 | + // custom error handler to catch any errors, such as TokenError | |
20 | + if (err.name === 'TokenError') { | |
21 | + res.redirect('http://nexusbr.com') // redirect them back to the login page | |
22 | + } else { | |
23 | + console.log('Falhou ao logar!') | |
24 | + // Handle other errors here | |
25 | + } | |
26 | + }, | |
27 | + (req, res) => { | |
28 | + console.log('Logou com sucesso!') | |
29 | + // On success, redirect back to '/' | |
30 | + res.redirect('/surveys') | |
31 | + } | |
32 | + ) | |
33 | 33 | |
34 | - router.get("/api/logout", (req,res)=>{ | |
35 | - req.logout(); | |
36 | - res.send(req.user); | |
37 | - }); | |
34 | + router.get('/api/logout', (req, res) => { | |
35 | + req.logout() | |
36 | + res.redirect('/') | |
37 | + }) | |
38 | 38 | |
39 | - router.get("/api/current_user", (req, res)=> { | |
40 | - res.send (req.user); | |
41 | - }); | |
42 | -}; | |
39 | + router.get('/api/current_user', (req, res) => { | |
40 | + res.send(req.user) | |
41 | + }) | |
42 | +} | ... | ... |