Skip to content
Permalink
Browse files

Merge pull request #5 from xwang345/add_login

Add login
  • Loading branch information...
Garrik-Liu committed Nov 15, 2018
2 parents 59982fd + 8c4e92d commit e860954d145106d2614133e3b2f92d4670d98463
Showing 10,476 changed files with 9,435 additions and 1,644,972 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
@@ -0,0 +1,63 @@
{
"env": {
"browser": true,
"node": true
},
"plugins": ["prettier"],
"extends": [
"plugin:prettier/recommended",
"prettier/flowtype",
"prettier/react",
"prettier/standard"
],
"parserOptions": {
"ecmaVersion": 8,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"curly": 2,
"dot-notation": 2,
"id-length": 2,
"no-const-assign": 2,
"no-dupe-class-members": 2,
"no-else-return": 2,
"no-inner-declarations": 2,
"no-lonely-if": 2,
"no-magic-numbers": [
2,
{
"ignore": [-1, 0, 1]
}
],
"no-shadow": 2,
"no-unneeded-ternary": 2,
"no-unused-expressions": 2,
"no-unused-vars": [
2,
{
"args": "none"
}
],
"no-useless-return": 2,
"no-var": 2,
"one-var": [2, "never"],
"prefer-arrow-callback": 2,
"prefer-const": 2,
"prefer-promise-reject-errors": 2,
"prettier/prettier": 2,
"sort-imports": 2,
"sort-keys": [
2,
"asc",
{
"caseSensitive": true,
"natural": true
}
],
"sort-vars": 2,
"strict": [2, "global"]
}
}
@@ -0,0 +1,3 @@
package-lock.json
package.json
node_modules
@@ -1,20 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach by Process ID",
"processId": "${command:PickProcess}"
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}\\bin\\www"
}
]
}
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach by Process ID",
"processId": "${command:PickProcess}"
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}\\bin\\www"
}
]
}
69 app.js
@@ -1,55 +1,64 @@
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
const bodyParser = require('body-parser');
var createError = require("http-errors");
var express = require("express");
var path = require("path");
var cookieParser = require("cookie-parser");
var logger = require("morgan");
const bodyParser = require("body-parser");
const clientSessions = require("client-sessions");
const bcrypt = require('bcryptjs');
const bcrypt = require("bcryptjs");

var indexRouter = require('./routes/index');
var imagesRouter = require('./routes/images');
var indexRouter = require("./routes/index");
var imagesRouter = require("./routes/images");
//
var app = express();

app.setSocketIo = function(socket, io) {
indexRouter.setSocketIo(socket, io);
imagesRouter.setSocketIo(socket, io);
}
indexRouter.setSocketIo(socket, io);
imagesRouter.setSocketIo(socket, io);
};

const user = {
username: ""
};
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "ejs");

app.use(logger('dev'));
app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, "public")));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended:true }));

app.use('/', indexRouter);
app.use('/images', imagesRouter);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static("node_modules"));

app.use("/", indexRouter);
app.use("/images", imagesRouter);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
next(createError(404));
});


app.use(
clientSessions({
cookieName: "session", // cookie name dictates the key name added to the request object
secret: "home_security", // should be a large unguessable string
duration: 24 * 60 * 60 * 1000, // how long the session will stay valid in ms
activeDuration: 1000 * 60 * 5 // if expiresIn < activeDuration, the session will be extended by activeDuration milliseconds
})
);

// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get("env") === "development" ? err : {};

// render the error page
res.status(err.status || 500);
res.render('error');
// render the error page
res.status(err.status || 500);
res.render("error");
});


module.exports = app;
module.exports = app;
@@ -26,7 +26,7 @@ var argv = require('optimist').argv;
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || '8080');
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
@@ -101,7 +101,7 @@ server.listen(port,function onHttpStart(){
});

// -----------------------
server.listen(port, argv.fe_ip);
//server.listen(port, argv.fe_ip);

server.on('error', onError);
server.on('listening', onListening);
@@ -1,6 +1,5 @@
{
"GCLOUD_PROJECT": "security-camera-221601",
"DATA_BACKEND": "datastore",
"CLOUD_BUCKET": "security-camera-snapshots"

}
"GCLOUD_PROJECT": "security-camera-221601",
"DATA_BACKEND": "datastore",
"CLOUD_BUCKET": "security-camera-snapshots"
}
@@ -1,4 +1,3 @@
## fswebcam

[文档](https://www.raspberrypi.org/documentation/usage/webcams/)

@@ -1,48 +1,51 @@
const express = require('express');
const exec = require('child_process').exec;
const five = require('johnny-five');
const Raspi = require('raspi-io');
const request = require('request');
const fs = require('fs');
const express = require("express");
const exec = require("child_process").exec;
const five = require("johnny-five");
const Raspi = require("raspi-io");
const request = require("request");
const fs = require("fs");

const app = express();
const board = new five.Board({
io: new Raspi()
io: new Raspi()
});

board.on("ready", function() {
takePicture("123");

takePicture('123');

app.listen('8080', () => {
console.log('Device is running on port:8080');
});
app.listen("8080", () => {
console.log("Device is running on port:8080");
});
});


function takePicture(name) {
exec("fswebcam /home/pi/Desktop/secure_camera/camera_imgs/" + name + ".jpg", (err, stdout, stderr) => {
console.log('Taking Picture Successful!');
postPicture(name);
})

exec(
"fswebcam /home/pi/Desktop/secure_camera/camera_imgs/" + name + ".jpg",
(err, stdout, stderr) => {
console.log("Taking Picture Successful!");
postPicture(name);
}
);
}

function postPicture(name) {
var formData = {
// Pass a simple key-value pair
my_field: name,
// Pass data via Buffers
my_buffer: Buffer.from([1, 2, 3]),
// Pass data via Streams
my_file: fs.createReadStream(__dirname + '/camera_imgs/' + name + '.jpg'),
// Pass multiple values /w an Array
};

request.post({ url: 'http://47.93.7.57:3000/uploadImg', formData: formData }, function optionalCallback(err, httpResponse, body) {
if (err) {
return console.error('upload failed:', err);
}
console.log('Upload successful! Server responded with:', body);
});
}
var formData = {
// Pass a simple key-value pair
my_field: name,
// Pass data via Buffers
my_buffer: Buffer.from([1, 2, 3]),
// Pass data via Streams
my_file: fs.createReadStream(__dirname + "/camera_imgs/" + name + ".jpg")
// Pass multiple values /w an Array
};

request.post(
{ url: "http://47.93.7.57:3000/uploadImg", formData: formData },
function optionalCallback(err, httpResponse, body) {
if (err) {
return console.error("upload failed:", err);
}
console.log("Upload successful! Server responded with:", body);
}
);
}
@@ -1,12 +1,12 @@
{
"type": "service_account",
"project_id": "home-security-220818",
"private_key_id": "ce96a4878dc39bbc6046eaf5dd479544287298b1",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCd8qP/MD6f4nXy\nBmo9Zaf577eEgMqjdFMBP59XUyJVLfL9LeENZ58PvI5LDF0CvXL0lRxGjYK/kQnI\n5rVTYbCvD8UQd1GRBE19NJulP4s6Aw1ZSfuXeGA0I+wCqoXXGMH/JQDqG16vchDh\nJHkRWB/5cIcLw4fgEUd8zKVHxCVr2t6iNz0zQnNQKNELrN+UMNtioWYjTJFOrb+f\nxSx+1UjCvy48wJyvrcwSJBXvQ9oYgtM37yU+WaaUaFlZeEc66B45EFuLiPWnWLRQ\nb5PfX3a4IQ8rF8PuDvGU+jn+Vwe0WUAU+EzyTQJN9A352wK03HrIxMY3fQzaKJe0\noYob4PqlAgMBAAECggEAGgSzGrGsE0LnCnYfkJsbE1s3eCKOHuRl2v4L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+AeaX40f1BOrnZyOaIyxGAdwLblr2OOWqyfgwJnUhtbRMFOxmpZRZ\nL29Ip0i2/w3jZEVfoB86xQE4cjzA8y46Mn1XNFDw01Nyd6zr37+xLb0LFSKFRPgJ\nVjTlQoi2vcyIaR/KK+dvO7Tr\n-----END PRIVATE KEY-----\n",
"client_email": "home-security-220818@appspot.gserviceaccount.com",
"client_id": "113967556367956046318",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/home-security-220818%40appspot.gserviceaccount.com"
}
"type": "service_account",
"project_id": "home-security-220818",
"private_key_id": "ce96a4878dc39bbc6046eaf5dd479544287298b1",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCd8qP/MD6f4nXy\nBmo9Zaf577eEgMqjdFMBP59XUyJVLfL9LeENZ58PvI5LDF0CvXL0lRxGjYK/kQnI\n5rVTYbCvD8UQd1GRBE19NJulP4s6Aw1ZSfuXeGA0I+wCqoXXGMH/JQDqG16vchDh\nJHkRWB/5cIcLw4fgEUd8zKVHxCVr2t6iNz0zQnNQKNELrN+UMNtioWYjTJFOrb+f\nxSx+1UjCvy48wJyvrcwSJBXvQ9oYgtM37yU+WaaUaFlZeEc66B45EFuLiPWnWLRQ\nb5PfX3a4IQ8rF8PuDvGU+jn+Vwe0WUAU+EzyTQJN9A352wK03HrIxMY3fQzaKJe0\noYob4PqlAgMBAAECggEAGgSzGrGsE0LnCnYfkJsbE1s3eCKOHuRl2v4LxcMKVA1E\naovg94gTBfDZ4Md519503hDlDkM3304pVjiY9JISXJgkrnx1SYXzrNUacZt42BbS\nH1wGT5KTCGvFcD/+Was4o8rI7oeRLqYD3U6YifCiHcE5Ycj1LEY0aDy+2kZXor8y\nBEmU4l7is7apuLn5PE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n-----END PRIVATE KEY-----\n",
"client_email": "home-security-220818@appspot.gserviceaccount.com",
"client_id": "113967556367956046318",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/home-security-220818%40appspot.gserviceaccount.com"
}
@@ -1,25 +1,20 @@
const ioListener = {}
const ioListener = {};

ioListener.socket = null
ioListener.socket = null;

ioListener.initialize = function(socket, io) {
this.socket = socket;
this.io = io
loadImage(socket);
addImage(socket);
}
this.socket = socket;
this.io = io;
loadImage(socket);
addImage(socket);
};

function loadImage(socket) {
socket.on('load image', function() {

});
socket.on("load image", function() {});
}

function addImage(socket) {
socket.on('add image', function() {

});
socket.on("add image", function() {});
}


module.exports = ioListener;
module.exports = ioListener;

0 comments on commit e860954

Please sign in to comment.
You can’t perform that action at this time.