user-admin

This commit is contained in:
unknown
2025-11-02 13:55:41 +08:00
parent 2b1f604285
commit 210663123a
4 changed files with 185 additions and 4 deletions

View File

@@ -174,7 +174,7 @@
</div>
</div>
<div id="detail2" hidden>
<div class="col-xl-8 col-md-6 mb-4">
<div class="col-xl-12 col-md-6 mb-4">
<div class="card shadow" style="margin-top:1.5rem;border-radius:10px">
<div class="card-body" >
<table id="table">
@@ -188,7 +188,7 @@
<td style="min-width:100px">
消息量
</td>
<td style="min-width:100px">
<td style="min-width:300px">
执行操作
</td>
</thead>
@@ -285,6 +285,53 @@
}
})
}
var resetPassword = function(userName){
if (!confirm(`确定要重置用户 ${userName} 的密码吗?新密码将设置为 "123456"`)) {
return;
}
const modald = showmodaltext("<div style='text-align:center'><i class='fa fa-spin fa-cog' style='font-size:2rem;color:#4e73df'></i><p style='margin-top:6px;margin-bottom:0;color:#4e73df;font-size:1rem;font-weight:bold'>重置密码中...</p></div>");
$.get('resetf',{
"username":userName,
"password":"123456"
},function(res){
if(res == 1)
{
modald.close()
showtext("操作成功!")
setTimeout(function(){
window.location.href = window.location.href
},1000)
}
else
{
modald.close()
showtext("操作失败")
}
})
}
var removeUser = function(userName){
if (!confirm(`确定要删除用户 ${userName} 的账号吗?此操作将不可恢复!`)) {
return;
}
const modald = showmodaltext("<div style='text-align:center'><i class='fa fa-spin fa-cog' style='font-size:2rem;color:#4e73df'></i><p style='margin-top:6px;margin-bottom:0;color:#4e73df;font-size:1rem;font-weight:bold'>重置密码中...</p></div>");
$.get('deletef',{
"username":userName
},function(res){
if(res == 1)
{
modald.close()
showtext("操作成功!")
setTimeout(function(){
window.location.href = window.location.href
},1000)
}
else
{
modald.close()
showtext("操作失败")
}
})
}
$("#time").html(new Date().toLocaleTimeString())
setInterval(() => {
$("#time").html(new Date().toLocaleTimeString())

View File

@@ -769,7 +769,7 @@ var arrLang = {
"ADMIN": "管理",
"BASICADMIN": "基础设置",
"USERADMIN": "批量注册",
"DATAADMIN": "数据管理",
"DATAADMIN": "用户管理",
"UPEMAIL": "注册邮箱:",
"EMAIL": "placeholder$请输入电子邮箱地址",
"PASSWORD": "placeholder$请输入密码",

View File

@@ -2,7 +2,7 @@ $(function(){
$.getJSON("queryData",function(res){
for(var i = 0;i<=res.length-1;i = i+1)
{
$("#tbody").append("<tr><td>"+res[i]["username"]+"</td><td>"+res[i]["projects"]+"</td><td>"+res[i]["messages"]+"</td><td>"+ "<a class='btn btn-primary' style='cursor:pointer;' onclick=\"clearMessage('"+res[i]["username"]+"')\" >清空消息</a>"+"</td></tr>")
$("#tbody").append("<tr><td>"+res[i]["username"]+"</td><td>"+res[i]["projects"]+"</td><td>"+res[i]["messages"]+"</td><td>"+ "<a class='btn btn-primary' style='cursor:pointer;' onclick=\"clearMessage('"+res[i]["username"]+"')\" >清空消息</a>&nbsp;"+ "<a class='btn btn-success' style='cursor:pointer;' onclick=\"resetPassword('"+res[i]["username"]+"')\" >重置密码</a>&nbsp;"+"<a class='btn btn-danger' style='cursor:pointer;' onclick=\"removeUser('"+res[i]["username"]+"')\" >删除用户</a>"+"</td></tr>")
}
datatable = $("#table").DataTable({
"order": [[ 2, "desc" ]],

134
mixio.js
View File

@@ -706,6 +706,106 @@ async function daemon_start() {
})
app.get('/resetf', function(req, res2) {
var userName = req.query.username
var password = req.query.password
if (userName && password) {
if(configs["MIXIO_HTTP_PORT"] !=0)
{
require('http').get('http://localhost:' + configs["MIXIO_HTTP_PORT"] + "/resetf?target=" + userName + "&pass=" + password, function(req, res) {
var html = '';
req.on('data', function(data) {
html += data;
});
req.on('end', function() {
res2.send(html)
});
}).on('error', function() {
res2.send('3')
})
}
else
{
const https = require('https');
// 对参数进行编码
const encodedPath = "/resetf?target=" + encodeURIComponent(userName) +
"&pass=" + encodeURIComponent(password)
const options = {
hostname: 'localhost',
port: configs["MIXIO_HTTPS_PORT"],
path: encodedPath,
method: 'GET',
rejectUnauthorized: false, // 忽略证书验证
agent: false
};
https.get(options, function(res) {
var html = '';
res.on('data', function(data) {
html += data;
});
res.on('end', function() {
res2.send(html);
});
}).on('error', function(e) {
console.log(e);
res2.send('3');
});
}
}
})
app.get('/deletef', function(req, res2) {
var userName = req.query.username
if (userName) {
if(configs["MIXIO_HTTP_PORT"] !=0)
{
require('http').get('http://localhost:' + configs["MIXIO_HTTP_PORT"] + "/deletef?target=" + userName, function(req, res) {
var html = '';
req.on('data', function(data) {
html += data;
});
req.on('end', function() {
res2.send(html)
});
}).on('error', function() {
res2.send('3')
})
}
else
{
const https = require('https');
// 对参数进行编码
const encodedPath = "/deletef?target=" + encodeURIComponent(userName)
const options = {
hostname: 'localhost',
port: configs["MIXIO_HTTPS_PORT"],
path: encodedPath,
method: 'GET',
rejectUnauthorized: false, // 忽略证书验证
agent: false
};
https.get(options, function(res) {
var html = '';
res.on('data', function(data) {
html += data;
});
res.on('end', function() {
res2.send(html);
});
}).on('error', function(e) {
console.log(e);
res2.send('3');
});
}
}
})
app.get('/start', async function(req, res) {
if (!serverStatus) {
console.log("[INFO] Starting MixIO Server...")
@@ -1744,6 +1844,40 @@ var mixioServer = async function() {
res.send('2')
})
app.get('/resetf', function(req, res) {
if (req.query.target && req.query.pass) {
db.get("select * from `user` where username=?", [req.query.target], function(err, row) {
if (err)
console.log(err)
else
if (row) {
var salt = randomString(16, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
var password = md5(req.query.pass + salt)
db.run("update `user` set password = ?,salt = ?, verified = 0 where username=?", [password, salt, req.query.target], function(err) {
if (err)
console.log(err)
else
res.send('1')
})
} else
res.send('2')
})
} else
res.send('2')
})
app.get('/deletef', function(req, res) {
if (req.query.target) {
db.get("delete from `user` where username=?", [req.query.target], function(err, row) {
if (err)
console.log(err)
else
res.send('1')
})
} else
res.send('2')
})
app.get('/setProtect', function(req, res) {
if (req.session.userName && req.query.question && req.query.answer) {
db.run("update `user` set question=? , answer=? , verified=1 where username=?", [req.query.question, req.query.answer, req.session.userName], function(err) {