added admin panel & fixed user registration
This commit is contained in:
		
							
								
								
									
										35
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										35
									
								
								index.js
									
									
									
									
									
								
							| @ -93,28 +93,30 @@ app.post('/reg_user', (req, res) => { | |||||||
|     let inp = req.body; |     let inp = req.body; | ||||||
|     let cook = req.cookies; |     let cook = req.cookies; | ||||||
|     let uuid = func.get_uuid(inp["login"]); |     let uuid = func.get_uuid(inp["login"]); | ||||||
|     let admin = Boolean(inp["admin"]); |     let admin = inp["admin"]; | ||||||
|     let pass = inp["pass"]; |     let pass = inp["pass"]; | ||||||
|     let login = inp["login"]; |     let login = inp["login"]; | ||||||
|     check_db(); |     check_db(); | ||||||
|     function check_db() { |     function check_db() { | ||||||
|         db.cv("users","login",inp["login"], (ldata)=>{ |         db.cv("users","login",inp["login"], (ldata)=>{ | ||||||
|             db.cv("users","login",inp["uuid"],(udata) =>{ |             db.cv("users","login",inp["uuid"],(udata) =>{ | ||||||
|                 console.log("/reg_user same login recs = "+ldata); |                 // console.log("/reg_user same login recs = "+ldata); | ||||||
|                 console.log("/reg_user same uuid recs = "+udata); |                 // console.log("/reg_user same uuid recs = "+udata); | ||||||
|                 if(udata==null){ |                 if(udata==null && ldata==null){ | ||||||
|                     if(ldata==null){ |  | ||||||
|                     good_reg(udata); |                     good_reg(udata); | ||||||
|                         console.log("/reg_user good reg"); |                     // console.log("/reg_user good reg"); | ||||||
|                         console.log("/reg_user reged "+login+" uuid = "+uuid); |                     console.log(`user ${login} registered with uuid = ${uuid} admin = ${admin}`); | ||||||
|                     } |  | ||||||
|                     else{ |  | ||||||
|                         console.log("bad user"); |  | ||||||
|                     } |  | ||||||
|                 } |                 } | ||||||
|                 else if(udata!=null){ |                 else if(udata!=null){ | ||||||
|                     uuid = func.get_uuid(inp["login"]); |                     uuid = func.get_uuid(inp["login"]); | ||||||
|                     check_db(); |                     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"]}`); |                 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) => { | // app.post("/set_cr_uuid", (req,res) => { | ||||||
| //     let inp = req.body; | //     let inp = req.body; | ||||||
| //     if(inp["uuid"] != null && inp["sid"] != null){ | //     if(inp["uuid"] != null && inp["sid"] != null){ | ||||||
| @ -315,6 +322,10 @@ app.get("/main", (req,res) =>{ | |||||||
|     res.render('main'); |     res.render('main'); | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | app.get("/admin", (req,res) =>{ | ||||||
|  |     res.render('admin'); | ||||||
|  | }); | ||||||
|  |  | ||||||
| // app.get("/main/:id", (req,res) =>{ | // app.get("/main/:id", (req,res) =>{ | ||||||
| //     res.render('main'); | //     res.render('main'); | ||||||
| // }); | // }); | ||||||
|  | |||||||
| @ -133,6 +133,10 @@ function get_sid(hostname){ | |||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | function new_obj(){ | ||||||
|  |  | ||||||
|  | } | ||||||
|  |  | ||||||
| function load_projs(callback){ | function load_projs(callback){ | ||||||
|     $.post( "/get_projs") |     $.post( "/get_projs") | ||||||
|     .done(function( res ) { |     .done(function( res ) { | ||||||
| @ -147,6 +151,7 @@ function load_projs(callback){ | |||||||
| function goto(url) { | function goto(url) { | ||||||
|     location.href = url; |     location.href = url; | ||||||
| } | } | ||||||
|  |  | ||||||
| function postForm(path, params, method) { | function postForm(path, params, method) { | ||||||
|     method = method || 'post'; |     method = method || 'post'; | ||||||
|  |  | ||||||
|  | |||||||
| @ -1,16 +1,13 @@ | |||||||
| <!DOCTYPE html> | <style> | ||||||
| <html lang="en"> |     iframe{ | ||||||
| <head> |         width: 100%; | ||||||
|     <meta charset="UTF-8"> |     } | ||||||
|     <meta http-equiv="X-UA-Compatible" content="IE=edge"> | </style> | ||||||
|     <meta name="viewport" content="width=device-width, initial-scale=1.0"> |  | ||||||
|     <title>Document</title> | <%- include('./static/start.ejs',{name:"admin",async: true}) %> | ||||||
| </head> | <%- include('./header.ejs') %> | ||||||
| <body> |  | ||||||
|     <h1><%= name %></h1> |  | ||||||
|     <h1>hello admin</h1> |     <h1>hello admin</h1> | ||||||
|     <form action="/add_user"> |     <iframe src="/reg" frameborder="0"></iframe> | ||||||
|         <input type="submit" value="add"> |  | ||||||
|     </form> | <%- include('./static/end.ejs') %> | ||||||
| </body> |  | ||||||
| </html> |  | ||||||
| @ -30,7 +30,7 @@ | |||||||
|         left.innerHTML += `<div id="user_name">${res["login"]}</div>`; |         left.innerHTML += `<div id="user_name">${res["login"]}</div>`; | ||||||
|          |          | ||||||
|         if (res["admin"] == true){ |         if (res["admin"] == true){ | ||||||
|             right.innerHTML += "<button>admin panel</button>"; |             right.innerHTML += `<button onclick='goto("/admin")'>admin panel</button>`; | ||||||
|         } |         } | ||||||
|         right.innerHTML += "<button onclick='logout();'>logout</button>"; |         right.innerHTML += "<button onclick='logout();'>logout</button>"; | ||||||
|     }); |     }); | ||||||
|  | |||||||
| @ -1,9 +1,33 @@ | |||||||
| <script src="/lib/fn.js"></script> | <%- include('./static/start.ejs',{name:"reg",async: true}) %> | ||||||
|  |  | ||||||
| <form action="/reg_user" method="post"> | <form action="" method="get" onsubmit="return false;"> | ||||||
|     <input type="text" name="login"> |     <input type="text" id="login" name="login"> | ||||||
|     <input type="password" name="pass"> |     <input type="password" id="pass" name="pass"> | ||||||
|     <input type="checkbox" name="admin" value='false' id="admin_check"> |     <input type="checkbox" name="admin" value='false' id="admin_check"> | ||||||
|     <input type="submit" value=""> |     <button onclick='reg();'>reg</button> | ||||||
|  |     <div id="reg_response"></div> | ||||||
|  |     <script> | ||||||
|  |         function reg(){ | ||||||
|  |             console.log("reg"); | ||||||
|  |             let login = document.getElementById("login").value; | ||||||
|  |             let pass = document.getElementById("pass").value; | ||||||
|  |             let admin = document.getElementById("admin_check").checked; | ||||||
|  |             // console.log(login,pass,admin); | ||||||
|  |             // console.log("cl reg"); | ||||||
|  |             $.post( "/reg_user", { login:login,pass:pass,admin:admin }) | ||||||
|  |             .done(function( res ) { | ||||||
|  |                 // console.log("serv reg"); | ||||||
|  |                 if(res["out"] == "good"){ | ||||||
|  |                     // console.log(res["body"]); | ||||||
|  |                     document.getElementById("reg_response").innerHTML = `user ${login} successfully registered `; | ||||||
|  |                 } | ||||||
|  |                 else if (res["out"] == "bad"){ | ||||||
|  |                     document.getElementById("reg_response").innerHTML = "cannot register user "+login+" already in use"; | ||||||
|  |                 } | ||||||
|  |             }); | ||||||
|  |         } | ||||||
|  |     </script> | ||||||
|  |     <!-- <input type="submit" value=""> --> | ||||||
|     <!-- <script>test();</script> --> |     <!-- <script>test();</script> --> | ||||||
|  |     <!-- <iframe id="reg_out" frameborder="0"></iframe> --> | ||||||
| </form> | </form> | ||||||
| @ -1,2 +1,11 @@ | |||||||
|  | <script> | ||||||
|  |     if(document.title == "login"){ | ||||||
|  |         console.log(document.title); | ||||||
|  |         log_by_sid(); | ||||||
|  |     }else if(document.title != "login"){ | ||||||
|  |         check_sid(true); | ||||||
|  |         console.log("check"); | ||||||
|  |     } | ||||||
|  | </script> | ||||||
| </body> | </body> | ||||||
| </html> | </html> | ||||||
|  | |||||||
| @ -10,15 +10,6 @@ | |||||||
|     <meta charset="UTF-8"> |     <meta charset="UTF-8"> | ||||||
|     <meta name="viewport" content="width=device-width, initial-scale=1.0"> |     <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||||||
|     <title> <%= name %> </title> |     <title> <%= name %> </title> | ||||||
|     <script> |  | ||||||
|         if(document.title == "login"){ |  | ||||||
|             console.log(document.title); |  | ||||||
|             log_by_sid(); |  | ||||||
|         }else if(document.title != "login"){ |  | ||||||
|             check_sid(true); |  | ||||||
|             console.log("check"); |  | ||||||
|         } |  | ||||||
|     </script> |  | ||||||
|     <!-- <script> document.querySelector("title").innerHTML += $.cookie("uuid"); </script> --> |     <!-- <script> document.querySelector("title").innerHTML += $.cookie("uuid"); </script> --> | ||||||
| </head> | </head> | ||||||
| <body> | <body> | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user