이민호

add password prompt

......@@ -2,30 +2,32 @@ var express = require("express");
var router = express.Router();
var AWS = require("aws-sdk");
var fs = require("fs");
var atob = require('atob');
var atob = require("atob");
AWS.config.loadFromPath("./config.json");
var rekognition = new AWS.Rekognition();
const { exec } = require("child_process");
router.post("/", function (req, res, next) {
console.log(req.body)
console.log(req.body);
if (req.body.landing == "true") {
res.render('use', { method: req.body.type,collection:req.body.collection })
}
else {
image = req.body.image
console.log(req.body.collection)
res.render("use", {
method: req.body.type,
collection: req.body.collection,
});
} else {
image = req.body.image;
console.log(req.body.collection);
// console.log(image)
// var img_arr = req.body.image.split(',').map(function(item) {
// return parseInt(item, 10);
// });
// console.log(img_arr)
// enc_data = Buffer.from(image.split("data:image/png;base64,")[1], 'base64').toString('ascii')
if(image[11]=='p')
enc_data = atob(image.split("data:image/png;base64,")[1])
else if(image[11]=='j')
enc_data = atob(image.split("data:image/jpeg;base64,")[1])
if (image[11] == "p")
enc_data = atob(image.split("data:image/png;base64,")[1]);
else if (image[11] == "j")
enc_data = atob(image.split("data:image/jpeg;base64,")[1]);
var length = enc_data.length;
imageBytes = new ArrayBuffer(length);
var ua = new Uint8Array(imageBytes);
......@@ -37,20 +39,24 @@ router.post("/", function (req, res, next) {
CollectionId: req.body.collection,
FaceMatchThreshold: 95,
Image: {
Bytes: imageBytes
Bytes: imageBytes,
},
MaxFaces: 5
MaxFaces: 5,
};
rekognition.searchFacesByImage(params, function (err, data) {
if (err) {
console.log(err, err.stack);
}
else {
if (data.FaceMatches.length>0){
res.render("redirect", {error:"Recognized!",collection: req.body.collection });
}
else{
// todo 잠금 페이지로 이동.
} else {
if (data.FaceMatches.length > 0) {
res.render("redirect", {
error: "Recognized!",
collection: req.body.collection,
});
} else {
res.render("password", {
collection: req.body.collection,
type: req.body.type,
});
}
}
});
......@@ -58,7 +64,7 @@ router.post("/", function (req, res, next) {
});
router.get("/", function (req, res, next) {
res.render('use')
res.render("use");
});
module.exports = router;
......
......@@ -61,8 +61,8 @@
<footer class="align-center">
<form action="/use" method="post">
<input type="hidden" name="landing" id="landing" value="true" />
<label for="type">Input Password:</label>
<input type='password' name='type' id='type'/>
<label for="type">Password (4 characters minimum):</label>
<input type='password' name='type' id='type' minlength="4" required/>
<input type='hidden' name="collection" id='collection' value="<%= collection %>" >
<!-- <select name="type" id="type" class="button alt">
<option value="Desktop">바탕화면</option>
......
<script type="text/javascript">
post_data = {
"collection":'<%= collection %>'
}
function winOpen() {
var type = '<%= type %>';
let sign = window.prompt("password");
if (sign == type){
redirectPost('/',post_data)
}
else{
winOpen();
}
}
function redirectPost(url, data) {
var form = document.createElement('form');
document.body.appendChild(form);
form.method = 'post';
form.action = url;
for (var name in data) {
var input = document.createElement('input');
input.type = 'hidden';
input.name = name;
input.value = data[name];
form.appendChild(input);
}
form.submit();
}
</script>
<body onLoad="winOpen()"></body>
\ No newline at end of file