From ecb5bb171840ef3c4c4a0ee37d44046c93332af4 Mon Sep 17 00:00:00 2001 From: whyour Date: Sun, 21 Mar 2021 11:57:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=94=A8=E6=88=B7=E5=90=8D?= =?UTF-8?q?=E5=AF=86=E7=A0=81=E4=BF=AE=E6=94=B9=EF=BC=8Cdiff=E8=A7=86?= =?UTF-8?q?=E5=9B=BE=E6=BB=9A=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/api/auth.ts | 22 +++++++++++++++++++--- package.json | 3 ++- shell/git_pull.sh | 8 ++++---- src/layouts/index.less | 2 +- src/pages/login/index.tsx | 2 +- src/pages/setting/index.tsx | 16 ++++++---------- 6 files changed, 33 insertions(+), 20 deletions(-) diff --git a/back/api/auth.ts b/back/api/auth.ts index f78b3291..8a30cb96 100644 --- a/back/api/auth.ts +++ b/back/api/auth.ts @@ -25,12 +25,12 @@ export default (app: Router) => { config.secret as any, { expiresIn: 60 * 60 * 24 * 7, algorithm: 'HS384' }, ); - res.send({ err: 0, token }); + res.send({ code: 200, token }); } else { - res.send({ err: 1, msg: config.authError }); + res.send({ code: 400, msg: config.authError }); } } else { - res.send({ err: 1, msg: '请输入用户名密码!' }); + res.send({ err: 400, msg: '请输入用户名密码!' }); } }); } catch (e) { @@ -39,4 +39,20 @@ export default (app: Router) => { } }, ); + + route.post( + '/user', + async (req: Request, res: Response, next: NextFunction) => { + const logger: Logger = Container.get('logger'); + try { + fs.writeFile(config.authConfigFile, JSON.stringify(req.body), (err) => { + if (err) console.log(err); + res.send({ code: 200, msg: '更新成功' }); + }); + } catch (e) { + logger.error('🔥 error: %o', e); + return next(e); + } + }, + ); }; diff --git a/package.json b/package.json index af9ed44a..dfb114b8 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "react": "17.x", "react-dom": "17.x", "typescript": "^4.1.2", - "yorkie": "^2.0.0" + "yorkie": "^2.0.0", + "ts-node": "^9.0.0" } } diff --git a/shell/git_pull.sh b/shell/git_pull.sh index d927a650..989ffffd 100755 --- a/shell/git_pull.sh +++ b/shell/git_pull.sh @@ -88,10 +88,10 @@ function Git_PullScripts { echo -e "更新scripts...\n" cd ${ScriptsDir} git fetch --all - git rm -f i-chenzhe* - git rm -f moposmall* - git rm -f qq34347476* - git rm -f whyour* + git rm -f --ignore-unmatch i-chenzhe* + git rm -f --ignore-unmatch moposmall* + git rm -f --ignore-unmatch qq34347476* + git rm -f --ignore-unmatch whyour* git stash git pull ExitStatusScripts=$? diff --git a/src/layouts/index.less b/src/layouts/index.less index 52a2c941..f2b9f1ca 100644 --- a/src/layouts/index.less +++ b/src/layouts/index.less @@ -18,7 +18,7 @@ body { overflow: auto; .ant-pro-page-container-children-content { overflow: auto; - min-height: calc(100vh - 96px); + height: calc(100vh - 96px); background-color: #fff; } } diff --git a/src/pages/login/index.tsx b/src/pages/login/index.tsx index 355640b9..3b60ec78 100644 --- a/src/pages/login/index.tsx +++ b/src/pages/login/index.tsx @@ -18,7 +18,7 @@ const Login = () => { }, }) .then((data) => { - if (data.err == 0) { + if (data.code == 200) { localStorage.setItem(config.authKey, data.token); history.push('/cookie'); } else { diff --git a/src/pages/setting/index.tsx b/src/pages/setting/index.tsx index a2af9962..54bc4d65 100644 --- a/src/pages/setting/index.tsx +++ b/src/pages/setting/index.tsx @@ -29,22 +29,18 @@ const Password = () => { const handleOk = (values: any) => { request - .post(`${config.apiPrefix}auth?t=${Date.now()}`, { + .post(`${config.apiPrefix}user?t=${Date.now()}`, { data: { username: values.username, password: values.password, }, }) - .then((data) => { - if (data.err == 0) { - localStorage.setItem(config.authKey, 'true'); - } else { - notification.open({ - message: data.msg, - }); - } + .then((data: any) => { + notification.success({ + message: data.msg, + }); }) - .catch(function (error) { + .catch((error: any) => { console.log(error); }); };