이민호

add password prompt

...@@ -2,30 +2,32 @@ var express = require("express"); ...@@ -2,30 +2,32 @@ var express = require("express");
2 var router = express.Router(); 2 var router = express.Router();
3 var AWS = require("aws-sdk"); 3 var AWS = require("aws-sdk");
4 var fs = require("fs"); 4 var fs = require("fs");
5 -var atob = require('atob'); 5 +var atob = require("atob");
6 AWS.config.loadFromPath("./config.json"); 6 AWS.config.loadFromPath("./config.json");
7 var rekognition = new AWS.Rekognition(); 7 var rekognition = new AWS.Rekognition();
8 8
9 const { exec } = require("child_process"); 9 const { exec } = require("child_process");
10 10
11 router.post("/", function (req, res, next) { 11 router.post("/", function (req, res, next) {
12 - console.log(req.body) 12 + console.log(req.body);
13 if (req.body.landing == "true") { 13 if (req.body.landing == "true") {
14 - res.render('use', { method: req.body.type,collection:req.body.collection }) 14 + res.render("use", {
15 - } 15 + method: req.body.type,
16 - else { 16 + collection: req.body.collection,
17 - image = req.body.image 17 + });
18 - console.log(req.body.collection) 18 + } else {
19 + image = req.body.image;
20 + console.log(req.body.collection);
19 // console.log(image) 21 // console.log(image)
20 // var img_arr = req.body.image.split(',').map(function(item) { 22 // var img_arr = req.body.image.split(',').map(function(item) {
21 // return parseInt(item, 10); 23 // return parseInt(item, 10);
22 // }); 24 // });
23 // console.log(img_arr) 25 // console.log(img_arr)
24 // enc_data = Buffer.from(image.split("data:image/png;base64,")[1], 'base64').toString('ascii') 26 // enc_data = Buffer.from(image.split("data:image/png;base64,")[1], 'base64').toString('ascii')
25 - if(image[11]=='p') 27 + if (image[11] == "p")
26 - enc_data = atob(image.split("data:image/png;base64,")[1]) 28 + enc_data = atob(image.split("data:image/png;base64,")[1]);
27 - else if(image[11]=='j') 29 + else if (image[11] == "j")
28 - enc_data = atob(image.split("data:image/jpeg;base64,")[1]) 30 + enc_data = atob(image.split("data:image/jpeg;base64,")[1]);
29 var length = enc_data.length; 31 var length = enc_data.length;
30 imageBytes = new ArrayBuffer(length); 32 imageBytes = new ArrayBuffer(length);
31 var ua = new Uint8Array(imageBytes); 33 var ua = new Uint8Array(imageBytes);
...@@ -37,20 +39,24 @@ router.post("/", function (req, res, next) { ...@@ -37,20 +39,24 @@ router.post("/", function (req, res, next) {
37 CollectionId: req.body.collection, 39 CollectionId: req.body.collection,
38 FaceMatchThreshold: 95, 40 FaceMatchThreshold: 95,
39 Image: { 41 Image: {
40 - Bytes: imageBytes 42 + Bytes: imageBytes,
41 }, 43 },
42 - MaxFaces: 5 44 + MaxFaces: 5,
43 }; 45 };
44 rekognition.searchFacesByImage(params, function (err, data) { 46 rekognition.searchFacesByImage(params, function (err, data) {
45 if (err) { 47 if (err) {
46 console.log(err, err.stack); 48 console.log(err, err.stack);
47 - } 49 + } else {
48 - else { 50 + if (data.FaceMatches.length > 0) {
49 - if (data.FaceMatches.length>0){ 51 + res.render("redirect", {
50 - res.render("redirect", {error:"Recognized!",collection: req.body.collection }); 52 + error: "Recognized!",
51 - } 53 + collection: req.body.collection,
52 - else{ 54 + });
53 - // todo 잠금 페이지로 이동. 55 + } else {
56 + res.render("password", {
57 + collection: req.body.collection,
58 + type: req.body.type,
59 + });
54 } 60 }
55 } 61 }
56 }); 62 });
...@@ -58,7 +64,7 @@ router.post("/", function (req, res, next) { ...@@ -58,7 +64,7 @@ router.post("/", function (req, res, next) {
58 }); 64 });
59 65
60 router.get("/", function (req, res, next) { 66 router.get("/", function (req, res, next) {
61 - res.render('use') 67 + res.render("use");
62 }); 68 });
63 69
64 module.exports = router; 70 module.exports = router;
......
...@@ -61,8 +61,8 @@ ...@@ -61,8 +61,8 @@
61 <footer class="align-center"> 61 <footer class="align-center">
62 <form action="/use" method="post"> 62 <form action="/use" method="post">
63 <input type="hidden" name="landing" id="landing" value="true" /> 63 <input type="hidden" name="landing" id="landing" value="true" />
64 - <label for="type">Input Password:</label> 64 + <label for="type">Password (4 characters minimum):</label>
65 - <input type='password' name='type' id='type'/> 65 + <input type='password' name='type' id='type' minlength="4" required/>
66 <input type='hidden' name="collection" id='collection' value="<%= collection %>" > 66 <input type='hidden' name="collection" id='collection' value="<%= collection %>" >
67 <!-- <select name="type" id="type" class="button alt"> 67 <!-- <select name="type" id="type" class="button alt">
68 <option value="Desktop">바탕화면</option> 68 <option value="Desktop">바탕화면</option>
......
1 +<script type="text/javascript">
2 + post_data = {
3 + "collection":'<%= collection %>'
4 + }
5 + function winOpen() {
6 + var type = '<%= type %>';
7 + let sign = window.prompt("password");
8 +
9 + if (sign == type){
10 + redirectPost('/',post_data)
11 + }
12 + else{
13 + winOpen();
14 + }
15 + }
16 +
17 + function redirectPost(url, data) {
18 + var form = document.createElement('form');
19 + document.body.appendChild(form);
20 + form.method = 'post';
21 + form.action = url;
22 + for (var name in data) {
23 + var input = document.createElement('input');
24 + input.type = 'hidden';
25 + input.name = name;
26 + input.value = data[name];
27 + form.appendChild(input);
28 + }
29 + form.submit();
30 + }
31 + </script>
32 +
33 + <body onLoad="winOpen()"></body>
...\ No newline at end of file ...\ No newline at end of file