From 681c1455f67b32fa1347e02b93865b2fc17d0f6a Mon Sep 17 00:00:00 2001 From: N0rdye Date: Tue, 27 Jun 2023 14:58:28 +0500 Subject: [PATCH] fixes --- index.js | 11 ++- public/lib/fn.js | 18 +++- public/lib/inter.js | 98 +++++++++++++++++++ views/header.ejs | 11 +++ views/main.ejs | 212 ++++++++++++----------------------------- views/static/start.ejs | 4 +- 6 files changed, 191 insertions(+), 163 deletions(-) create mode 100644 public/lib/inter.js create mode 100644 views/header.ejs diff --git a/index.js b/index.js index 86598f2..0122744 100644 --- a/index.js +++ b/index.js @@ -40,7 +40,7 @@ app.post('/back_login', (req, res) => { db.gv("users","login",ilogin,(udata)=>{ if(ipass == udata["pass"]){ console.log(udata["uuid"]+" logged in by login & pass from "+cook["sid"]); - res.cookie("uuid",udata["uuid"],{maxAge:1000000}); + res.cookie("uuid",udata["uuid"],{maxAge:1000000,path:"/;SameSite=Strict"}); db.gv("users","uuid",udata["uuid"],(rdata)=>{ // console.log(rdata["sids"]); @@ -157,7 +157,7 @@ app.post("/get_sid" , (req,res) =>{ let inp = req.body; let sid = func.get_uuid(inp["name"]); var week = 7 * 24 * 3600 * 1000; - res.cookie("sid",sid,{maxAge:(week)}); + res.cookie("sid",sid,{maxAge:(week),path:"/;SameSite=Strict"}); res.send({out:"good"}); }); @@ -208,7 +208,12 @@ app.get("/main", (req,res) =>{ }); app.get('/', (req, res) => { - res.redirect('login'); + if(req.cookies["uuid"] != null){ + res.redirect('main'); + } + else{ + res.redirect('login'); + } }); app.all('*', (req, res) => { diff --git a/public/lib/fn.js b/public/lib/fn.js index e60c85c..91003eb 100644 --- a/public/lib/fn.js +++ b/public/lib/fn.js @@ -39,7 +39,8 @@ function log_by_sid() { // const sid = $.cookie("sid"); console.log("log"); if($.cookie('sid') == null){ - get_sid(location.hostname); + // get_sid(location.hostname); + clear_ck(false); }else{ $.post( "/sid_log") .done(function( res ) { @@ -53,19 +54,19 @@ function log_by_sid() { })} } -function clear_ck(){ +function clear_ck(redirect = true){ $.cookie("uuid",null); $.cookie("sid",null); - goto("login"); + get_sid(location.hostname); + if (redirect) goto("login"); } function check_sid(){ console.log("checking sid"); - if($.cookie('sid') == null){ + if($.cookie('sid') == null || $.cookie('uuid') == null){ clear_ck(); } else{ - console.log("ping"); $.post( "/sid_log") .done(function( res ) { if(res["out"] == "bad"){ @@ -75,6 +76,13 @@ function check_sid(){ } } +function logout() { + let dialog = confirm("logout?"); + if(dialog){ + clear_ck(); + } +} + function get_sid(hostname){ $.post( "/get_sid", { name:hostname }) diff --git a/public/lib/inter.js b/public/lib/inter.js new file mode 100644 index 0000000..f40881b --- /dev/null +++ b/public/lib/inter.js @@ -0,0 +1,98 @@ +window.dragMoveListener = dragMoveListener +let root = document.getElementById("drags"); +var objs = {}; +if ($.cookie("objs") != null){ + load_local(); +} + + +function add(obj){ + if (objs[obj] == null) objs[obj] = {}; + if ((objs[obj]["count"] == null)){(objs[obj]["count"] = 0)} + let count = Object.keys(objs[obj]).length -1; + // console.log(obj,objs[obj+"_count"],objs[obj+"_s"]); + root.innerHTML += "
"+obj+"
"; + objs[obj][obj+"_"+count] = {}; + objs[obj]["count"]+=1; + console.log(objs); +} + +function create(clas,obj,x,y,inside){ + if (inside == null || inside == "") inside = "[]"; + root.innerHTML += "
"+inside+"
"; + let obj_doc = document.getElementById(obj); + set_pos(obj_doc,x,y); +} + +function load_local(){ + objs = JSON.parse($.cookie("objs")); + // console.log(objs); + Object.entries(objs).forEach(([keys, values]) => { + // console.log(keys,values); + Object.entries(values).forEach(([key, value]) => { + if(key != "count"){ + // console.log(key,value); + create(keys,key,value["x"],value["y"],value["body"]); + } + }) + }); +} + +function save(){ + $.cookie("objs",JSON.stringify(objs),{path:"/;SameSite=Strict"}); +} + +function set_pos(obj,x,y){ + obj.style.transform = 'translate(' + x + 'px, ' + y + 'px)'; + obj.setAttribute('data-x', x) + obj.setAttribute('data-y', y) +} + +function dragMoveListener (event) { + var drag = event.target + var x = (parseFloat(drag.getAttribute('data-x')) || 0) + event.dx + var y = (parseFloat(drag.getAttribute('data-y')) || 0) + event.dy + set_pos(drag,x,y); +} + +interact('.drag').draggable({ + inertia: true, + // modifiers: [ + // interact.modifiers.restrictRect({restriction: 'parent',endOnly: true}), + // interact.modifiers.snap({targets: [interact.snappers.grid({ x: 5, y: 5 })],range: Infinity,relativePoints: [ { x: 0, y: 0 } ]}),], + // autoScroll: true, + listeners: {move: dragMoveListener, end (event) {}} +}) + +interact('.trash').dropzone({ + accept: '.drag', + overlap: 0.2, + + ondragenter: function (event) {var drag = event.relatedTarget;var zone = event.target; zone.classList.add('drop-target');drag.classList.add('can-drop');}, + ondragleave: function (event) {var drag = event.relatedTarget;var zone = event.target;zone.classList.remove('drop-target');drag.classList.remove('in_zone');drag.classList.remove('can-drop');}, + ondrop: function (event) { + var drag = event.relatedTarget + delete objs[drag.classList[0]][drag.id]; + drag.remove(); + console.log(objs); + drag.classList.add('in_zone') + drag.classList.remove('can-drop') + }, + ondropdeactivate: function (event) {var zone = event.target;zone.classList.remove('drop-active');zone.classList.remove('drop-target');} +}) + +interact('.dropzone').dropzone({ + accept: '.drag', + overlap: 0.5, + + ondragenter: function (event) {var drag = event.relatedTarget;var zone = event.target;zone.classList.add('drop-target');drag.classList.add('can-drop');}, + ondragleave: function (event) {var drag = event.relatedTarget;var zone = event.target;zone.classList.remove('drop-target');drag.classList.remove('in_zone');drag.classList.remove('can-drop');}, + ondrop: function (event) { + var drag = event.relatedTarget + objs[drag.classList[0]][drag.id] = {y:drag.getAttribute('data-y'),x:drag.getAttribute('data-x'),body:drag.innerHTML}; + // $.cookie("objs",JSON.stringify(objs)); + drag.classList.add('in_zone') + drag.classList.remove('can-drop') + }, + ondropdeactivate: function (event) {var zone = event.target;zone.classList.remove('drop-active');zone.classList.remove('drop-target');} +}) \ No newline at end of file diff --git a/views/header.ejs b/views/header.ejs new file mode 100644 index 0000000..c285cf3 --- /dev/null +++ b/views/header.ejs @@ -0,0 +1,11 @@ + +
+
puzzle
+
+
\ No newline at end of file diff --git a/views/main.ejs b/views/main.ejs index 3b38170..54f7953 100644 --- a/views/main.ejs +++ b/views/main.ejs @@ -1,159 +1,65 @@ + + <%- include('./static/start.ejs',{name:'main',async: true}) %> -

none

-

hello

- - - -
- -
-
- - - - - - +

none

+

hello

+ + + +
+ +
+
+ + + + + + <%- include('./static/end.ejs') %> diff --git a/views/static/start.ejs b/views/static/start.ejs index 901fc90..8e7da05 100644 --- a/views/static/start.ejs +++ b/views/static/start.ejs @@ -1,7 +1,7 @@ - + @@ -13,5 +13,5 @@ - +