Commit 72ce85fabcadd898f32bf6be60963d8e4cad8206
1 parent
8344c6f1
Exists in
master
and in
1 other branch
V. 0.2.0 - Configuração inicial da autenticação com o Google. Refatoração código banco de dados.
Showing
11 changed files
with
141 additions
and
50 deletions
Show diff stats
.gitignore
package-lock.json
... | ... | @@ -564,6 +564,11 @@ |
564 | 564 | "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", |
565 | 565 | "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=" |
566 | 566 | }, |
567 | + "oauth": { | |
568 | + "version": "0.9.15", | |
569 | + "resolved": "https://registry.npmjs.org/oauth/-/oauth-0.9.15.tgz", | |
570 | + "integrity": "sha1-vR/vr2hslrdUda7VGWQS/2DPucE=" | |
571 | + }, | |
567 | 572 | "on-finished": { |
568 | 573 | "version": "2.3.0", |
569 | 574 | "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", |
... | ... | @@ -595,11 +600,49 @@ |
595 | 600 | "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.2.tgz", |
596 | 601 | "integrity": "sha1-/CidTtiZMRlGDBViUyYs3I3mW/M=" |
597 | 602 | }, |
603 | + "passport": { | |
604 | + "version": "0.4.0", | |
605 | + "resolved": "https://registry.npmjs.org/passport/-/passport-0.4.0.tgz", | |
606 | + "integrity": "sha1-xQlWkTR71a07XhgCOMORTRbwWBE=", | |
607 | + "requires": { | |
608 | + "passport-strategy": "1.0.0", | |
609 | + "pause": "0.0.1" | |
610 | + } | |
611 | + }, | |
612 | + "passport-google-oauth20": { | |
613 | + "version": "1.0.0", | |
614 | + "resolved": "https://registry.npmjs.org/passport-google-oauth20/-/passport-google-oauth20-1.0.0.tgz", | |
615 | + "integrity": "sha1-O5YOih1w0dvnlGFcgnxoxAOSpdA=", | |
616 | + "requires": { | |
617 | + "passport-oauth2": "1.4.0" | |
618 | + } | |
619 | + }, | |
620 | + "passport-oauth2": { | |
621 | + "version": "1.4.0", | |
622 | + "resolved": "https://registry.npmjs.org/passport-oauth2/-/passport-oauth2-1.4.0.tgz", | |
623 | + "integrity": "sha1-9i+BWDy+EmCb585vFguTlaJ7hq0=", | |
624 | + "requires": { | |
625 | + "oauth": "0.9.15", | |
626 | + "passport-strategy": "1.0.0", | |
627 | + "uid2": "0.0.3", | |
628 | + "utils-merge": "1.0.0" | |
629 | + } | |
630 | + }, | |
631 | + "passport-strategy": { | |
632 | + "version": "1.0.0", | |
633 | + "resolved": "https://registry.npmjs.org/passport-strategy/-/passport-strategy-1.0.0.tgz", | |
634 | + "integrity": "sha1-tVOaqPwiWj0a0XlHbd8ja0QPUuQ=" | |
635 | + }, | |
598 | 636 | "path-to-regexp": { |
599 | 637 | "version": "0.1.7", |
600 | 638 | "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", |
601 | 639 | "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" |
602 | 640 | }, |
641 | + "pause": { | |
642 | + "version": "0.0.1", | |
643 | + "resolved": "https://registry.npmjs.org/pause/-/pause-0.0.1.tgz", | |
644 | + "integrity": "sha1-HUCLP9t2kjuVQ9lvtMnf1TXZy10=" | |
645 | + }, | |
603 | 646 | "pg": { |
604 | 647 | "version": "7.4.1", |
605 | 648 | "resolved": "https://registry.npmjs.org/pg/-/pg-7.4.1.tgz", |
... | ... | @@ -981,6 +1024,11 @@ |
981 | 1024 | "integrity": "sha1-bgkk1r2mta/jSeOabWMoUKD4grc=", |
982 | 1025 | "optional": true |
983 | 1026 | }, |
1027 | + "uid2": { | |
1028 | + "version": "0.0.3", | |
1029 | + "resolved": "https://registry.npmjs.org/uid2/-/uid2-0.0.3.tgz", | |
1030 | + "integrity": "sha1-SDEm4Rd03y9xuLY53NeZw3YWK4I=" | |
1031 | + }, | |
984 | 1032 | "unpipe": { |
985 | 1033 | "version": "1.0.0", |
986 | 1034 | "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", | ... | ... |
package.json
... | ... | @@ -7,7 +7,8 @@ |
7 | 7 | "npm": "5.6.0" |
8 | 8 | }, |
9 | 9 | "scripts": { |
10 | - "start": "node ./bin/www" | |
10 | + "start": "node ./bin/www", | |
11 | + "dev": "nodemon ./bin/www" | |
11 | 12 | }, |
12 | 13 | "dependencies": { |
13 | 14 | "body-parser": "~1.18.2", |
... | ... | @@ -19,6 +20,8 @@ |
19 | 20 | "leaflet-draw": "^1.0.2", |
20 | 21 | "morgan": "~1.9.0", |
21 | 22 | "mssql": "^4.1.0", |
23 | + "passport": "^0.4.0", | |
24 | + "passport-google-oauth20": "^1.0.0", | |
22 | 25 | "pg": "*", |
23 | 26 | "postgeo": "*", |
24 | 27 | "serve-favicon": "~2.4.5" | ... | ... |
public/stylesheets/style.css
... | ... | @@ -10,7 +10,7 @@ html, body { |
10 | 10 | height: 100px; |
11 | 11 | } |
12 | 12 | .outer { |
13 | - top: 50px; | |
13 | + top: 0px; | |
14 | 14 | left: 0; |
15 | 15 | right: 0; |
16 | 16 | bottom: 0; |
... | ... | @@ -19,7 +19,7 @@ html, body { |
19 | 19 | height: auto; |
20 | 20 | } |
21 | 21 | #map { |
22 | - height: 100%; | |
22 | + height: 85%; | |
23 | 23 | } |
24 | 24 | body { |
25 | 25 | margin:0; |
... | ... | @@ -31,7 +31,7 @@ a { |
31 | 31 | } |
32 | 32 | #leg, #leg_title { |
33 | 33 | position:absolute; |
34 | - top:50px; | |
34 | + top:0px; | |
35 | 35 | right:10px; |
36 | 36 | width:100px; |
37 | 37 | padding:10px; |
... | ... | @@ -45,7 +45,7 @@ a { |
45 | 45 | overflow:auto; |
46 | 46 | } |
47 | 47 | #leg_title { |
48 | - top:10px; | |
48 | + top:0px; | |
49 | 49 | } |
50 | 50 | #leg_items { |
51 | 51 | position:relative; |
... | ... | @@ -62,4 +62,13 @@ a { |
62 | 62 | bottom: 46px; |
63 | 63 | height: 48px; |
64 | 64 | width: 48px; |
65 | +} | |
66 | +.btn.btn-primary { | |
67 | + margin-top: 5px; | |
68 | +} | |
69 | +.form-control{ | |
70 | + margin-top: 5px; | |
71 | +} | |
72 | +.col.col-lg-3{ | |
73 | + margin-top: 11px; | |
65 | 74 | } |
66 | 75 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,29 @@ |
1 | +const passport = require("passport"); // from npm | |
2 | + | |
3 | +module.exports = router => { | |
4 | + // Enter to authenticate the user | |
5 | + router.get( | |
6 | + "/auth/google", | |
7 | + passport.authenticate("google", { | |
8 | + scope: ["profile", "email"] | |
9 | + }) | |
10 | + ); | |
11 | + | |
12 | + // Page after authenticate | |
13 | + router.get( | |
14 | + "/auth/google/callback", | |
15 | + passport.authenticate("google"), | |
16 | + (err, req, res, next) => { | |
17 | + // custom error handler to catch any errors, such as TokenError | |
18 | + if (err.name === "TokenError") { | |
19 | + res.redirect("http://nexusbr.com"); // redirect them back to the login page | |
20 | + } else { | |
21 | + // Handle other errors here | |
22 | + } | |
23 | + }, | |
24 | + (req, res) => { | |
25 | + // On success, redirect back to '/' | |
26 | + res.redirect("/"); | |
27 | + } | |
28 | + ); | |
29 | +}; | ... | ... |
routes/index.js
1 | 1 | var express = require("express"); |
2 | -var ms_sql = require("mssql"); | |
3 | -var conexao = require("../src/connectionsConfiguration"); | |
4 | 2 | var router = express.Router(); |
3 | +require("../services/passport"); | |
4 | +require("../services/databases"); | |
5 | +const authRoutes = require("./authRoutes"); | |
5 | 6 | |
6 | -// Conexão com Postgres | |
7 | -var pg = require("pg"); | |
8 | -pg.defaults.poolSize = 25; | |
9 | - | |
10 | -// Creates global pool connection with MS SqlServer | |
11 | - | |
12 | -global.poolPg = new pg.Pool(conexao.pg); | |
13 | - | |
14 | -global.poolMsql = new ms_sql.ConnectionPool(conexao.msql, function(err) { | |
15 | - if (err) { | |
16 | - console.log("Não conectou \n" + err); | |
17 | - } | |
18 | -}); | |
7 | +authRoutes(router); | |
19 | 8 | |
20 | 9 | /* GET home page. */ |
21 | 10 | router.get("/", function(req, res, next) { |
... | ... | @@ -27,11 +16,12 @@ router.get("/map/:nome", function(req, res, next) { |
27 | 16 | var coordenadas = require("../src/findCoordinatesFromConsumer"); |
28 | 17 | var retorno = numeroConsumidor(req.params.nome, function(numero, nome) { |
29 | 18 | console.log("Terminou tudo: " + numero + " Nome: " + nome); |
19 | + var codigoComNome = numero + " - " + nome; | |
30 | 20 | var retorno = coordenadas(numero, function(x, y) { |
31 | 21 | console.log("Terminou procura coordenadas x: " + x + " y: " + y); |
32 | 22 | res.render("map", { |
33 | 23 | codigo: numero, |
34 | - consumidor: nome, | |
24 | + consumidor: codigoComNome, | |
35 | 25 | fator_zoom: 23, |
36 | 26 | title: "NEXUS", |
37 | 27 | lat: y, |
... | ... | @@ -41,7 +31,7 @@ router.get("/map/:nome", function(req, res, next) { |
41 | 31 | }); |
42 | 32 | }); |
43 | 33 | |
44 | -router.get("http://127.0.0.1/ponto", function(req, res) { | |
34 | +router.get("http://nexusbr.dyndns-ip.com:3000/ponto", function(req, res) { | |
45 | 35 | var coord = {}; |
46 | 36 | console.log("Postou: "); |
47 | 37 | }); | ... | ... |
... | ... | @@ -0,0 +1,14 @@ |
1 | +var ms_sql = require("mssql"); | |
2 | +var pg = require("pg"); | |
3 | +const keys = require("../config/keys"); | |
4 | + | |
5 | +// Conexão com Postgres | |
6 | +pg.defaults.poolSize = 25; | |
7 | + | |
8 | +// Creates global pool connection with Postgres and MS SqlServer | |
9 | +global.poolPg = new pg.Pool(keys.pg); | |
10 | +global.poolMsql = new ms_sql.ConnectionPool(keys.msql, function(err) { | |
11 | + if (err) { | |
12 | + console.log("Não conectou \n" + err); | |
13 | + } | |
14 | +}); | |
0 | 15 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,21 @@ |
1 | +const passport = require("passport"); | |
2 | +const GoogleStrategy = require("passport-google-oauth20").Strategy; | |
3 | +const util = require('util'); | |
4 | +const keys = require("../config/keys"); | |
5 | + | |
6 | +passport.use( | |
7 | + new GoogleStrategy( | |
8 | + { | |
9 | + clientID: keys.googleClientID, | |
10 | + clientSecret: keys.googleClientSecret, | |
11 | + callbackURL: "/auth/google/callback" | |
12 | + }, | |
13 | + (accessToken, refreshToken, profile, done) => { // error function | |
14 | + console.log("Ocorreu um erro"); | |
15 | + console.log("Chave de acesso: " + accessToken); | |
16 | + console.log("Refresh token: " + refreshToken); | |
17 | + console.log("Profile: " + util.inspect(profile, false, null)); | |
18 | + } | |
19 | + ) | |
20 | + ); | |
21 | + | |
0 | 22 | \ No newline at end of file | ... | ... |
src/connectionsConfiguration.js
... | ... | @@ -1,21 +0,0 @@ |
1 | -var connection = { | |
2 | - pg: { | |
3 | - host: 'http://nexusbr.dyndns-ip.com', // server name or IP address; | |
4 | - hostaddr: 'http://nexusbr.dyndns-ip.com', | |
5 | - port: 5432, | |
6 | - database: 'gis', | |
7 | - user: 'postgres', | |
8 | - password: 'nexus243', | |
9 | - max: 10, // max number of clients in the pool | |
10 | - idleTimeoutMillis: 30000 // how long a client is allowed to remain idle before being closed | |
11 | - }, | |
12 | - msql: { | |
13 | - user: 'sa', | |
14 | - password: 'Nexus243', | |
15 | - server: 'http://nexusbr.dyndns-ip.com', | |
16 | - database: 'comercial', | |
17 | - port: '1444', | |
18 | - dialect: 'mssql' | |
19 | - } | |
20 | -} | |
21 | -module.exports = connection; | |
22 | 0 | \ No newline at end of file |
views/layout.jade
... | ... | @@ -19,7 +19,6 @@ html |
19 | 19 | link(src="http://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous") |
20 | 20 | body |
21 | 21 | .container |
22 | - | |
23 | 22 | script(src='//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js') |
24 | 23 | script(src='//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js') |
25 | 24 | block content | ... | ... |
views/map.jade
... | ... | @@ -3,11 +3,9 @@ block content |
3 | 3 | br |
4 | 4 | .container |
5 | 5 | .row |
6 | - .col.col-lg-2 | |
7 | - | Codigo: #{codigo} | |
8 | - .col.col-lg-3 | |
9 | - | Consumidor: #{consumidor} | |
10 | 6 | .col.col-lg-3 |
7 | + | #{consumidor} | |
8 | + .col.col-lg-2 | |
11 | 9 | input.form-control(type='text', id="nome", placeholder='Digite o nome') |
12 | 10 | .col.col-lg-1 |
13 | 11 | input.btn.btn-primary(type='button', value='Procura', onclick=' relocate_home()') |
... | ... | @@ -38,7 +36,7 @@ block content |
38 | 36 | "Google": L.tileLayer('http://www.google.cn/maps/vt?lyrs=s@189&gl=cn&x={x}&y={y}&z={z}', { |
39 | 37 | attribution: 'google' |
40 | 38 | }) |
41 | - }, {'Ocorrências': drawnItems, 'Redes': wmsLayer}, { position: 'topright', collapsed: false }).addTo(map); | |
39 | + }, {'Ocorrências': drawnItems, 'Redes': wmsLayer}, { position: 'topright', collapsed: true }).addTo(map); | |
42 | 40 | |
43 | 41 | var marker = L.marker([#{lat},#{lng}]).addTo(map); |
44 | 42 | marker.bindPopup("<b>#{codigo}</b><br>#{consumidor}").openPopup(); | ... | ... |