added admin panel & fixed user registration
This commit is contained in:
parent
4538d122c5
commit
73630d4bb6
37
index.js
37
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');
|
||||
// });
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1><%= name %></h1>
|
||||
<style>
|
||||
iframe{
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
|
||||
<%- include('./static/start.ejs',{name:"admin",async: true}) %>
|
||||
<%- include('./header.ejs') %>
|
||||
|
||||
<h1>hello admin</h1>
|
||||
<form action="/add_user">
|
||||
<input type="submit" value="add">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
<iframe src="/reg" frameborder="0"></iframe>
|
||||
|
||||
<%- include('./static/end.ejs') %>
|
|
@ -30,7 +30,7 @@
|
|||
left.innerHTML += `<div id="user_name">${res["login"]}</div>`;
|
||||
|
||||
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>";
|
||||
});
|
||||
|
|
|
@ -1,9 +1,33 @@
|
|||
<script src="/lib/fn.js"></script>
|
||||
<%- include('./static/start.ejs',{name:"reg",async: true}) %>
|
||||
|
||||
<form action="/reg_user" method="post">
|
||||
<input type="text" name="login">
|
||||
<input type="password" name="pass">
|
||||
<form action="" method="get" onsubmit="return false;">
|
||||
<input type="text" id="login" name="login">
|
||||
<input type="password" id="pass" name="pass">
|
||||
<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> -->
|
||||
</form>
|
||||
<!-- <iframe id="reg_out" frameborder="0"></iframe> -->
|
||||
</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>
|
||||
</html>
|
||||
|
|
|
@ -10,15 +10,6 @@
|
|||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<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> -->
|
||||
</head>
|
||||
<body>
|
||||
|
|
Loading…
Reference in New Issue
Block a user