mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
首次登录自动生成随机密码
This commit is contained in:
@@ -4,6 +4,7 @@ import { Logger } from 'winston';
|
||||
import * as fs from 'fs';
|
||||
import config from '../config';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { createPassword } from '../config/util';
|
||||
const route = Router();
|
||||
|
||||
export default (app: Router) => {
|
||||
@@ -19,6 +20,23 @@ export default (app: Router) => {
|
||||
if (err) console.log(err);
|
||||
const authInfo = JSON.parse(data);
|
||||
if (username && password) {
|
||||
if (
|
||||
authInfo.username === 'admin' &&
|
||||
authInfo.password === 'adminadmin'
|
||||
) {
|
||||
const newPassword = createPassword(16, 22);
|
||||
fs.writeFileSync(
|
||||
config.authConfigFile,
|
||||
JSON.stringify({
|
||||
username: authInfo.username,
|
||||
password: newPassword,
|
||||
}),
|
||||
);
|
||||
return res.send({
|
||||
code: 100,
|
||||
msg: '已初始化密码,请前往auth.json查看并重新登录',
|
||||
});
|
||||
}
|
||||
if (
|
||||
username == authInfo.username &&
|
||||
password == authInfo.password
|
||||
|
||||
+3
-3
@@ -65,7 +65,7 @@ export default (app: Router) => {
|
||||
const cookieService = Container.get(CookieService);
|
||||
const data = await cookieService.addCookie(req.body.cookies);
|
||||
if (data) {
|
||||
return res.send({ code: 500, data });
|
||||
return res.send({ code: 400, data });
|
||||
} else {
|
||||
return res.send({ code: 200, data: '新建成功' });
|
||||
}
|
||||
@@ -84,7 +84,7 @@ export default (app: Router) => {
|
||||
const cookieService = Container.get(CookieService);
|
||||
const data = await cookieService.updateCookie(req.body);
|
||||
if (data) {
|
||||
return res.send({ code: 500, data });
|
||||
return res.send({ code: 400, data });
|
||||
} else {
|
||||
return res.send({ code: 200, data: '新建成功' });
|
||||
}
|
||||
@@ -105,7 +105,7 @@ export default (app: Router) => {
|
||||
req.body.cookie as string,
|
||||
);
|
||||
if (data) {
|
||||
return res.send({ code: 500, data });
|
||||
return res.send({ code: 400, data });
|
||||
} else {
|
||||
return res.send({ code: 200, data: '新建成功' });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user