diff --git a/index.js b/index.js index a2804b9..c7acd5f 100644 --- a/index.js +++ b/index.js @@ -93,28 +93,30 @@ app.post('/reg_user', (req, res) => { let inp = req.body; let cook = req.cookies; let uuid = func.get_uuid(inp["login"]); - let admin = Boolean(inp["admin"]); + let admin = inp["admin"]; let pass = inp["pass"]; let login = inp["login"]; check_db(); function check_db() { db.cv("users","login",inp["login"], (ldata)=>{ db.cv("users","login",inp["uuid"],(udata) =>{ - console.log("/reg_user same login recs = "+ldata); - console.log("/reg_user same uuid recs = "+udata); - if(udata==null){ - if(ldata==null){ - good_reg(udata); - console.log("/reg_user good reg"); - console.log("/reg_user reged "+login+" uuid = "+uuid); - } - else{ - console.log("bad user"); - } + // console.log("/reg_user same login recs = "+ldata); + // console.log("/reg_user same uuid recs = "+udata); + if(udata==null && ldata==null){ + good_reg(udata); + // console.log("/reg_user good reg"); + console.log(`user ${login} registered with uuid = ${uuid} admin = ${admin}`); + } else if(udata!=null){ uuid = func.get_uuid(inp["login"]); check_db(); + // res.send({out:"bad", body:"uuid"}); + } + else if (ldata != null){ + console.log("bad user"); + res.send({out:"bad", body:"login"}); + return; } }) }) @@ -126,7 +128,7 @@ app.post('/reg_user', (req, res) => { db.nr("admins",'`login`,`uid`',`'${login}',${res["id"]}`); }) } - res.redirect("/reg"); + res.send({out:"good", body:{uuid:uuid,login:login,admin:admin}}); } }) @@ -262,6 +264,11 @@ app.post("/get_projs", (req,res) => { } }) +app.post("/new_obj", (req,res) => { + let inp = req.body; + let cook = req.cookies; +}) + // app.post("/set_cr_uuid", (req,res) => { // let inp = req.body; // if(inp["uuid"] != null && inp["sid"] != null){ @@ -315,6 +322,10 @@ app.get("/main", (req,res) =>{ res.render('main'); }); +app.get("/admin", (req,res) =>{ + res.render('admin'); +}); + // app.get("/main/:id", (req,res) =>{ // res.render('main'); // }); diff --git a/public/lib/fn.js b/public/lib/fn.js index ce15909..9c8c9c4 100644 --- a/public/lib/fn.js +++ b/public/lib/fn.js @@ -133,6 +133,10 @@ function get_sid(hostname){ }); } +function new_obj(){ + +} + function load_projs(callback){ $.post( "/get_projs") .done(function( res ) { @@ -147,6 +151,7 @@ function load_projs(callback){ function goto(url) { location.href = url; } + function postForm(path, params, method) { method = method || 'post'; diff --git a/views/admin.ejs b/views/admin.ejs index e8d6161..1b5e6fe 100644 --- a/views/admin.ejs +++ b/views/admin.ejs @@ -1,16 +1,13 @@ - - - - - - - Document - - -

<%= name %>

+ + +<%- include('./static/start.ejs',{name:"admin",async: true}) %> +<%- include('./header.ejs') %> +

hello admin

-
- -
- - \ No newline at end of file + + +<%- include('./static/end.ejs') %> \ No newline at end of file diff --git a/views/header.ejs b/views/header.ejs index f268b12..36d7241 100644 --- a/views/header.ejs +++ b/views/header.ejs @@ -30,7 +30,7 @@ left.innerHTML += `
${res["login"]}
`; if (res["admin"] == true){ - right.innerHTML += ""; + right.innerHTML += ``; } right.innerHTML += ""; }); diff --git a/views/reg.ejs b/views/reg.ejs index 4c8e7e3..93d1665 100644 --- a/views/reg.ejs +++ b/views/reg.ejs @@ -1,9 +1,33 @@ - +<%- include('./static/start.ejs',{name:"reg",async: true}) %> -
- - + + + - + +
+ + -
\ No newline at end of file + + diff --git a/views/static/end.ejs b/views/static/end.ejs index 308b1d0..d9ab2bc 100644 --- a/views/static/end.ejs +++ b/views/static/end.ejs @@ -1,2 +1,11 @@ + diff --git a/views/static/start.ejs b/views/static/start.ejs index eb36bf2..f4cc86a 100644 --- a/views/static/start.ejs +++ b/views/static/start.ejs @@ -10,15 +10,6 @@ <%= name %> -