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,6 +564,11 @@ | ||
564 | "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", | 564 | "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", |
565 | "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=" | 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 | "on-finished": { | 572 | "on-finished": { |
568 | "version": "2.3.0", | 573 | "version": "2.3.0", |
569 | "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", | 574 | "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", |
@@ -595,11 +600,49 @@ | @@ -595,11 +600,49 @@ | ||
595 | "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.2.tgz", | 600 | "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.2.tgz", |
596 | "integrity": "sha1-/CidTtiZMRlGDBViUyYs3I3mW/M=" | 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 | "path-to-regexp": { | 636 | "path-to-regexp": { |
599 | "version": "0.1.7", | 637 | "version": "0.1.7", |
600 | "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", | 638 | "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", |
601 | "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" | 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 | "pg": { | 646 | "pg": { |
604 | "version": "7.4.1", | 647 | "version": "7.4.1", |
605 | "resolved": "https://registry.npmjs.org/pg/-/pg-7.4.1.tgz", | 648 | "resolved": "https://registry.npmjs.org/pg/-/pg-7.4.1.tgz", |
@@ -981,6 +1024,11 @@ | @@ -981,6 +1024,11 @@ | ||
981 | "integrity": "sha1-bgkk1r2mta/jSeOabWMoUKD4grc=", | 1024 | "integrity": "sha1-bgkk1r2mta/jSeOabWMoUKD4grc=", |
982 | "optional": true | 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 | "unpipe": { | 1032 | "unpipe": { |
985 | "version": "1.0.0", | 1033 | "version": "1.0.0", |
986 | "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", | 1034 | "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", |
package.json
@@ -7,7 +7,8 @@ | @@ -7,7 +7,8 @@ | ||
7 | "npm": "5.6.0" | 7 | "npm": "5.6.0" |
8 | }, | 8 | }, |
9 | "scripts": { | 9 | "scripts": { |
10 | - "start": "node ./bin/www" | 10 | + "start": "node ./bin/www", |
11 | + "dev": "nodemon ./bin/www" | ||
11 | }, | 12 | }, |
12 | "dependencies": { | 13 | "dependencies": { |
13 | "body-parser": "~1.18.2", | 14 | "body-parser": "~1.18.2", |
@@ -19,6 +20,8 @@ | @@ -19,6 +20,8 @@ | ||
19 | "leaflet-draw": "^1.0.2", | 20 | "leaflet-draw": "^1.0.2", |
20 | "morgan": "~1.9.0", | 21 | "morgan": "~1.9.0", |
21 | "mssql": "^4.1.0", | 22 | "mssql": "^4.1.0", |
23 | + "passport": "^0.4.0", | ||
24 | + "passport-google-oauth20": "^1.0.0", | ||
22 | "pg": "*", | 25 | "pg": "*", |
23 | "postgeo": "*", | 26 | "postgeo": "*", |
24 | "serve-favicon": "~2.4.5" | 27 | "serve-favicon": "~2.4.5" |
public/stylesheets/style.css
@@ -10,7 +10,7 @@ html, body { | @@ -10,7 +10,7 @@ html, body { | ||
10 | height: 100px; | 10 | height: 100px; |
11 | } | 11 | } |
12 | .outer { | 12 | .outer { |
13 | - top: 50px; | 13 | + top: 0px; |
14 | left: 0; | 14 | left: 0; |
15 | right: 0; | 15 | right: 0; |
16 | bottom: 0; | 16 | bottom: 0; |
@@ -19,7 +19,7 @@ html, body { | @@ -19,7 +19,7 @@ html, body { | ||
19 | height: auto; | 19 | height: auto; |
20 | } | 20 | } |
21 | #map { | 21 | #map { |
22 | - height: 100%; | 22 | + height: 85%; |
23 | } | 23 | } |
24 | body { | 24 | body { |
25 | margin:0; | 25 | margin:0; |
@@ -31,7 +31,7 @@ a { | @@ -31,7 +31,7 @@ a { | ||
31 | } | 31 | } |
32 | #leg, #leg_title { | 32 | #leg, #leg_title { |
33 | position:absolute; | 33 | position:absolute; |
34 | - top:50px; | 34 | + top:0px; |
35 | right:10px; | 35 | right:10px; |
36 | width:100px; | 36 | width:100px; |
37 | padding:10px; | 37 | padding:10px; |
@@ -45,7 +45,7 @@ a { | @@ -45,7 +45,7 @@ a { | ||
45 | overflow:auto; | 45 | overflow:auto; |
46 | } | 46 | } |
47 | #leg_title { | 47 | #leg_title { |
48 | - top:10px; | 48 | + top:0px; |
49 | } | 49 | } |
50 | #leg_items { | 50 | #leg_items { |
51 | position:relative; | 51 | position:relative; |
@@ -62,4 +62,13 @@ a { | @@ -62,4 +62,13 @@ a { | ||
62 | bottom: 46px; | 62 | bottom: 46px; |
63 | height: 48px; | 63 | height: 48px; |
64 | width: 48px; | 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 | \ No newline at end of file | 75 | \ No newline at end of file |
@@ -0,0 +1,29 @@ | @@ -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 | var express = require("express"); | 1 | var express = require("express"); |
2 | -var ms_sql = require("mssql"); | ||
3 | -var conexao = require("../src/connectionsConfiguration"); | ||
4 | var router = express.Router(); | 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 | /* GET home page. */ | 9 | /* GET home page. */ |
21 | router.get("/", function(req, res, next) { | 10 | router.get("/", function(req, res, next) { |
@@ -27,11 +16,12 @@ router.get("/map/:nome", function(req, res, next) { | @@ -27,11 +16,12 @@ router.get("/map/:nome", function(req, res, next) { | ||
27 | var coordenadas = require("../src/findCoordinatesFromConsumer"); | 16 | var coordenadas = require("../src/findCoordinatesFromConsumer"); |
28 | var retorno = numeroConsumidor(req.params.nome, function(numero, nome) { | 17 | var retorno = numeroConsumidor(req.params.nome, function(numero, nome) { |
29 | console.log("Terminou tudo: " + numero + " Nome: " + nome); | 18 | console.log("Terminou tudo: " + numero + " Nome: " + nome); |
19 | + var codigoComNome = numero + " - " + nome; | ||
30 | var retorno = coordenadas(numero, function(x, y) { | 20 | var retorno = coordenadas(numero, function(x, y) { |
31 | console.log("Terminou procura coordenadas x: " + x + " y: " + y); | 21 | console.log("Terminou procura coordenadas x: " + x + " y: " + y); |
32 | res.render("map", { | 22 | res.render("map", { |
33 | codigo: numero, | 23 | codigo: numero, |
34 | - consumidor: nome, | 24 | + consumidor: codigoComNome, |
35 | fator_zoom: 23, | 25 | fator_zoom: 23, |
36 | title: "NEXUS", | 26 | title: "NEXUS", |
37 | lat: y, | 27 | lat: y, |
@@ -41,7 +31,7 @@ router.get("/map/:nome", function(req, res, next) { | @@ -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 | var coord = {}; | 35 | var coord = {}; |
46 | console.log("Postou: "); | 36 | console.log("Postou: "); |
47 | }); | 37 | }); |
@@ -0,0 +1,14 @@ | @@ -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 | \ No newline at end of file | 15 | \ No newline at end of file |
@@ -0,0 +1,21 @@ | @@ -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 | \ No newline at end of file | 22 | \ No newline at end of file |
src/connectionsConfiguration.js
@@ -1,21 +0,0 @@ | @@ -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 | \ No newline at end of file | 0 | \ No newline at end of file |
views/layout.jade
@@ -19,7 +19,6 @@ html | @@ -19,7 +19,6 @@ html | ||
19 | link(src="http://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous") | 19 | link(src="http://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous") |
20 | body | 20 | body |
21 | .container | 21 | .container |
22 | - | ||
23 | script(src='//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js') | 22 | script(src='//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js') |
24 | script(src='//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js') | 23 | script(src='//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js') |
25 | block content | 24 | block content |
views/map.jade
@@ -3,11 +3,9 @@ block content | @@ -3,11 +3,9 @@ block content | ||
3 | br | 3 | br |
4 | .container | 4 | .container |
5 | .row | 5 | .row |
6 | - .col.col-lg-2 | ||
7 | - | Codigo: #{codigo} | ||
8 | - .col.col-lg-3 | ||
9 | - | Consumidor: #{consumidor} | ||
10 | .col.col-lg-3 | 6 | .col.col-lg-3 |
7 | + | #{consumidor} | ||
8 | + .col.col-lg-2 | ||
11 | input.form-control(type='text', id="nome", placeholder='Digite o nome') | 9 | input.form-control(type='text', id="nome", placeholder='Digite o nome') |
12 | .col.col-lg-1 | 10 | .col.col-lg-1 |
13 | input.btn.btn-primary(type='button', value='Procura', onclick=' relocate_home()') | 11 | input.btn.btn-primary(type='button', value='Procura', onclick=' relocate_home()') |
@@ -38,7 +36,7 @@ block content | @@ -38,7 +36,7 @@ block content | ||
38 | "Google": L.tileLayer('http://www.google.cn/maps/vt?lyrs=s@189&gl=cn&x={x}&y={y}&z={z}', { | 36 | "Google": L.tileLayer('http://www.google.cn/maps/vt?lyrs=s@189&gl=cn&x={x}&y={y}&z={z}', { |
39 | attribution: 'google' | 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 | var marker = L.marker([#{lat},#{lng}]).addTo(map); | 41 | var marker = L.marker([#{lat},#{lng}]).addTo(map); |
44 | marker.bindPopup("<b>#{codigo}</b><br>#{consumidor}").openPopup(); | 42 | marker.bindPopup("<b>#{codigo}</b><br>#{consumidor}").openPopup(); |