try to add parameter for localPath
This commit is contained in:
@@ -113,7 +113,7 @@
|
|||||||
}
|
}
|
||||||
chart.render();
|
chart.render();
|
||||||
|
|
||||||
$.getJSON("/n/dht", function(data){
|
$.getJSON(localPath + "/dht", function(data){
|
||||||
if(data && data.dht){
|
if(data && data.dht){
|
||||||
chart.title.set("text", "A23 Currently is " + data.dht.temp + "°C, " + data.dht.hum +"% RH" );
|
chart.title.set("text", "A23 Currently is " + data.dht.temp + "°C, " + data.dht.hum +"% RH" );
|
||||||
}else {
|
}else {
|
||||||
@@ -122,7 +122,7 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$.getJSON("/n/dht/A23_DHT", addData);
|
$.getJSON(localPath+ "/dht/A23_DHT", addData);
|
||||||
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
12
server.js
12
server.js
@@ -76,22 +76,22 @@ app.get('/login',
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.post('/login',
|
app.post('/login',
|
||||||
passport.authenticate('local', { failureRedirect: '/n/login' }),
|
passport.authenticate('local', { failureRedirect: config.localPath+ '/login' }),
|
||||||
function(req, res) {
|
function(req, res) {
|
||||||
res.redirect('/n/');
|
res.redirect(config.localPath+ '/');
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/logout',
|
app.get('/logout',
|
||||||
function(req, res){
|
function(req, res){
|
||||||
req.logout();
|
req.logout();
|
||||||
res.redirect('/n/');
|
res.redirect(config.localPath+ '/');
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/accontrol',
|
app.get('/accontrol',
|
||||||
// passport.authenticate('local', {
|
// passport.authenticate('local', {
|
||||||
// failureRedirect: '/n/login' ,
|
// failureRedirect: config.localPath+ '/login' ,
|
||||||
// successRedirect: '/n/accontrol'}),
|
// successRedirect: config.localPath+ '/accontrol'}),
|
||||||
require('connect-ensure-login').ensureLoggedIn('/n/login'),
|
require('connect-ensure-login').ensureLoggedIn(config.localPath+ '/login'),
|
||||||
function(req, res){
|
function(req, res){
|
||||||
res.render('accontrol', { user: req.user });
|
res.render('accontrol', { user: req.user });
|
||||||
});
|
});
|
||||||
|
|||||||
13
src/auth.js
13
src/auth.js
@@ -7,6 +7,7 @@ const util = require('util');
|
|||||||
var app = require('express')();
|
var app = require('express')();
|
||||||
|
|
||||||
var db = require('./db');
|
var db = require('./db');
|
||||||
|
var config = require('./setup_const');
|
||||||
var passport = require('passport');
|
var passport = require('passport');
|
||||||
var Strategy = require('passport-local').Strategy;
|
var Strategy = require('passport-local').Strategy;
|
||||||
var CookieStrategy = require('passport-cookie').Strategy;
|
var CookieStrategy = require('passport-cookie').Strategy;
|
||||||
@@ -14,13 +15,13 @@ var CookieStrategy = require('passport-cookie').Strategy;
|
|||||||
var session = require('express-session');
|
var session = require('express-session');
|
||||||
const cookierParser = require('cookie-parser');
|
const cookierParser = require('cookie-parser');
|
||||||
|
|
||||||
var ensureLoggedIn = require("connect-ensure-login").ensureLoggedIn("/n/login");
|
var ensureLoggedIn = require("connect-ensure-login").ensureLoggedIn(config.localPath + "/login");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
ensureLoggedIn_Orig: ensureLoggedIn,
|
ensureLoggedIn_Orig: ensureLoggedIn,
|
||||||
ensureLoggedIn_P: function (req, res, next){passport.authenticate('local', {
|
ensureLoggedIn_P: function (req, res, next){passport.authenticate('local', {
|
||||||
successRedirect: '/n/accontrol',
|
successRedirect: config.localPath + '/accontrol',
|
||||||
failureRedirect: '/n/login' })},
|
failureRedirect: config.localPath + '/login' })},
|
||||||
passport: passport,
|
passport: passport,
|
||||||
ensureLoggedIn_New: function (req, res, next) {
|
ensureLoggedIn_New: function (req, res, next) {
|
||||||
if (req.isAuthenticated()) {
|
if (req.isAuthenticated()) {
|
||||||
@@ -122,8 +123,8 @@ module.exports = {
|
|||||||
|
|
||||||
app.post('/login',
|
app.post('/login',
|
||||||
passport.authenticate('local', {
|
passport.authenticate('local', {
|
||||||
successRedirect: '/n/accontrol',
|
successRedirect: config.localPath + '/accontrol',
|
||||||
failureRedirect: '/n/login' }),
|
failureRedirect: config.localPath + '/login' }),
|
||||||
// authenticated user.
|
// authenticated user.
|
||||||
function(req, res) {
|
function(req, res) {
|
||||||
console.log("logged in. session:" + req.session);
|
console.log("logged in. session:" + req.session);
|
||||||
@@ -133,7 +134,7 @@ module.exports = {
|
|||||||
|
|
||||||
app.get('/logout', function(req, res){
|
app.get('/logout', function(req, res){
|
||||||
req.logout();
|
req.logout();
|
||||||
res.redirect('/n/login');
|
res.redirect(config.localPath + '/login');
|
||||||
});
|
});
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
|
|||||||
@@ -2,13 +2,14 @@ var GardenIP = '192.168.0.18';
|
|||||||
var AcIP = '192.168.1.143';
|
var AcIP = '192.168.1.143';
|
||||||
var HouseDhtIP = '192.168.1.126';
|
var HouseDhtIP = '192.168.1.126';
|
||||||
var HomeControllerMQTT = '192.168.0.10'; //GW02
|
var HomeControllerMQTT = '192.168.0.10'; //GW02
|
||||||
|
var localPath = "/n";
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
GardenIP: '192.168.0.18',
|
GardenIP: '192.168.0.18',
|
||||||
AcIP : '192.168.1.143',
|
AcIP : '192.168.1.143',
|
||||||
HouseDhtIP : '192.168.1.126',
|
HouseDhtIP : '192.168.1.126',
|
||||||
HomeControllerMQTT : '192.168.0.10',
|
HomeControllerMQTT : '192.168.0.10',
|
||||||
|
localPath : "/n",
|
||||||
foo: function () {
|
foo: function () {
|
||||||
// whatever
|
// whatever
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<h2>AC Control for <% if (model.user) {model.user.username; } %></h2>
|
<h2>AC Control for <% if (model.user) {model.user.username; } %></h2>
|
||||||
<h4 id="current">Retrieving current conditions...</h4>
|
<h4 id="current">Retrieving current conditions...</h4>
|
||||||
<!-- class="form-inline" -->
|
<!-- class="form-inline" -->
|
||||||
<form id="accontrol" action="/n/accontrol" method="POST">
|
<form id="accontrol" action= config.localPath + "/accontrol" method="POST">
|
||||||
<div class="form-group ">
|
<div class="form-group ">
|
||||||
<input type='checkbox' name='power' <%= model.data.power|true ? "checked" : "" %> data-toggle='toggle'
|
<input type='checkbox' name='power' <%= model.data.power|true ? "checked" : "" %> data-toggle='toggle'
|
||||||
data-style='android' data-on='ON' data-off='Off' />
|
data-style='android' data-on='ON' data-off='Off' />
|
||||||
@@ -34,7 +34,7 @@ INFO:
|
|||||||
<%- contentFor('head') %>
|
<%- contentFor('head') %>
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
const url = 'wss://iot.d-popov.com/n/ws'
|
const url = 'wss://iot.d-popov.com' + config.localPath + '/ws'
|
||||||
const connection = new WebSocket(url)
|
const connection = new WebSocket(url)
|
||||||
connection.onopen = (d) => {
|
connection.onopen = (d) => {
|
||||||
console.log(`WebSocket error: ${d}`)
|
console.log(`WebSocket error: ${d}`)
|
||||||
@@ -57,7 +57,7 @@ INFO:
|
|||||||
<script>
|
<script>
|
||||||
|
|
||||||
window.onload = function () {
|
window.onload = function () {
|
||||||
$.getJSON("/n/dht?e=now", function(data){
|
$.getJSON(config.localPath + "/dht?e=now", function(data){
|
||||||
if(data && data.dht){
|
if(data && data.dht){
|
||||||
$('#current').text( "A23 Currently is " + data.dht.temp + "°C, " + data.dht.hum +"% RH. Dew point : " + data.dht.dew + "°C" );
|
$('#current').text( "A23 Currently is " + data.dht.temp + "°C, " + data.dht.hum +"% RH. Dew point : " + data.dht.dew + "°C" );
|
||||||
}else {
|
}else {
|
||||||
|
|||||||
@@ -145,7 +145,7 @@
|
|||||||
}
|
}
|
||||||
chart.render();
|
chart.render();
|
||||||
|
|
||||||
$.getJSON("/n/dht?e=now", function(data){
|
$.getJSON(config.localPath + "/dht?e=now", function(data){
|
||||||
if(data && data.dht){
|
if(data && data.dht){
|
||||||
chart.title.set("text", "A23 Currently is " + data.dht.temp + "°C, " + data.dht.hum +"% RH" );
|
chart.title.set("text", "A23 Currently is " + data.dht.temp + "°C, " + data.dht.hum +"% RH" );
|
||||||
}else {
|
}else {
|
||||||
@@ -154,8 +154,8 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$.getJSON("/n/device/A23_DHT/7", addData);
|
$.getJSON(config.localPath + "/device/A23_DHT/7", addData);
|
||||||
$.getJSON("/n/device/A23_Garden_Humidity/7", addData);
|
$.getJSON(config.localPath + "/device/A23_Garden_Humidity/7", addData);
|
||||||
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -20,11 +20,11 @@
|
|||||||
Period
|
Period
|
||||||
</button>
|
</button>
|
||||||
<div class="dropdown-menu" aria-labelledby="btnGroupDrop1">
|
<div class="dropdown-menu" aria-labelledby="btnGroupDrop1">
|
||||||
<a class="dropdown-item" href="/n/garden/1">Day</a>
|
<a class="dropdown-item" href=config.localPath + "/garden/1">Day</a>
|
||||||
<a class="dropdown-item" href="/n/garden/2">2 Days</a>
|
<a class="dropdown-item" href=config.localPath + "/garden/2">2 Days</a>
|
||||||
<a class="dropdown-item" href="/n/garden/7">Week</a>
|
<a class="dropdown-item" href=config.localPath + "/garden/7">Week</a>
|
||||||
<a class="dropdown-item" href="/n/garden/30">Month</a>
|
<a class="dropdown-item" href=config.localPath + "/garden/30">Month</a>
|
||||||
<a class="dropdown-item" href="/n/garden/91">Quarter</a>
|
<a class="dropdown-item" href=config.localPath + "/garden/91">Quarter</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -224,10 +224,10 @@
|
|||||||
chart.render();
|
chart.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
$.getJSON("/n/device/A23_DHT/<%= model.days ? model.days : '7' %>", addData);
|
$.getJSON(config.localPath + "/device/A23_DHT/<%= model.days ? model.days : '7' %>", addData);
|
||||||
$.getJSON("/n/device/A23_Garden_dht/<%= model.days ? model.days : '7' %>", addData);
|
$.getJSON(config.localPath + "/device/A23_Garden_dht/<%= model.days ? model.days : '7' %>", addData);
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
$.getJSON("/n/dht?e=now", function(data){
|
$.getJSON(config.localPath + "/dht?e=now", function(data){
|
||||||
if(data && data.dht){
|
if(data && data.dht){
|
||||||
$("#now").text("In A23 currently is " + data.dht.temp + "°C, " + data.dht.hum +"% RH" );
|
$("#now").text("In A23 currently is " + data.dht.temp + "°C, " + data.dht.hum +"% RH" );
|
||||||
}else {
|
}else {
|
||||||
@@ -236,7 +236,7 @@
|
|||||||
});
|
});
|
||||||
},5000);
|
},5000);
|
||||||
|
|
||||||
$("#water").on("click", function(){$.ajax({url:"/n/water?t="+$("#waterTime").val()});});
|
$("#water").on("click", function(){$.ajax({url:config.localPath + "/water?t="+$("#waterTime").val()});});
|
||||||
$("#waterStop").on("click", function(){$.ajax({url:"/n/waterStop"});});
|
$("#waterStop").on("click", function(){$.ajax({url:config.localPath + "/waterStop"});});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<form action="/n/login" method="post">
|
<form action=config.localPath+ "/login" method="post">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Username:</label>
|
<label>Username:</label>
|
||||||
<input type="text" name="username" class="form-control" />
|
<input type="text" name="username" class="form-control" />
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
<a href="/n/accontrol" >control</a>
|
<a href=config.localPath + "/accontrol" >control</a>
|
||||||
<a href="/n/logout" >log out</a>
|
<a href=config.localPath + "/logout" >log out</a>
|
||||||
<a href="/n/chart"> chart</a>
|
<a href=config.localPath + "/chart"> chart</a>
|
||||||
<a href="/n/garden"> garden</a>
|
<a href=config.localPath + "/garden"> garden</a>
|
||||||
Reference in New Issue
Block a user