From aed08b0f5965a0f31b68ce66afc8b69da4ecd437 Mon Sep 17 00:00:00 2001 From: whyour Date: Fri, 17 Sep 2021 18:06:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=80=9A=E7=9F=A5api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/api/auth.ts | 32 +++++++++++++++++++++++++++++++- back/services/auth.ts | 10 +++++----- shell/update.sh | 2 +- src/pages/setting/security.tsx | 14 +++++++------- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/back/api/auth.ts b/back/api/auth.ts index 76a2255a..21bf5484 100644 --- a/back/api/auth.ts +++ b/back/api/auth.ts @@ -86,7 +86,7 @@ export default (app: Router) => { code: 200, data: { username: authInfo.username, - twoFactorActived: authInfo.twoFactorActived, + twoFactorActivated: authInfo.twoFactorActivated, }, }); } catch (e) { @@ -182,4 +182,34 @@ export default (app: Router) => { } }, ); + + route.get( + '/user/notification', + async (req: Request, res: Response, next: NextFunction) => { + const logger: Logger = Container.get('logger'); + try { + const authService = Container.get(AuthService); + const data = await authService.getNotificationMode(); + res.send({ code: 200, data }); + } catch (e) { + logger.error('🔥 error: %o', e); + return next(e); + } + }, + ); + + route.put( + '/user/notification', + async (req: Request, res: Response, next: NextFunction) => { + const logger: Logger = Container.get('logger'); + try { + const authService = Container.get(AuthService); + const data = await authService.updateNotificationMode(req.body); + res.send({ code: 200, data }); + } catch (e) { + logger.error('🔥 error: %o', e); + return next(e); + } + }, + ); }; diff --git a/back/services/auth.ts b/back/services/auth.ts index 45ac539a..bb874942 100644 --- a/back/services/auth.ts +++ b/back/services/auth.ts @@ -47,7 +47,7 @@ export default class AuthService { lastlogon, lastip, lastaddr, - twoFactorActived, + twoFactorActivated, } = content; if ( @@ -72,7 +72,7 @@ export default class AuthService { const { ip, address } = await getNetIp(req); if (username === cUsername && password === cPassword) { - if (twoFactorActived && needTwoFactor) { + if (twoFactorActivated && needTwoFactor) { this.updateAuthInfo(content, { isTwoFactorChecking: true, }); @@ -83,7 +83,7 @@ export default class AuthService { } const data = createRandomString(50, 100); - const expiration = twoFactorActived ? 30 : 3; + const expiration = twoFactorActivated ? 30 : 3; let token = jwt.sign({ data }, config.secret as any, { expiresIn: 60 * 60 * 24 * expiration, algorithm: 'HS384', @@ -206,7 +206,7 @@ export default class AuthService { secret: authInfo.twoFactorSecret, }); if (isValid) { - this.updateAuthInfo(authInfo, { twoFactorActived: true }); + this.updateAuthInfo(authInfo, { twoFactorActivated: true }); } return isValid; } @@ -236,7 +236,7 @@ export default class AuthService { public deactiveTwoFactor() { const authInfo = this.getAuthInfo(); this.updateAuthInfo(authInfo, { - twoFactorActived: false, + twoFactorActivated: false, twoFactorSecret: '', }); return true; diff --git a/shell/update.sh b/shell/update.sh index f7425937..ec2fbb18 100755 --- a/shell/update.sh +++ b/shell/update.sh @@ -494,7 +494,7 @@ main() { ;; resettfa) echo -e "## 开始执行... $begin_time\n" >>$log_path - auth_value=$(cat $file_auth_user | jq '.twoFactorActived =false' -c) + auth_value=$(cat $file_auth_user | jq '.twoFactorActivated =false' -c) echo -e "禁用两步验证成功 \n $auth_value" >>$log_path echo "$auth_value" >$file_auth_user ;; diff --git a/src/pages/setting/security.tsx b/src/pages/setting/security.tsx index 2fa6217f..ebf9074d 100644 --- a/src/pages/setting/security.tsx +++ b/src/pages/setting/security.tsx @@ -9,7 +9,7 @@ const { Title, Link } = Typography; const SecuritySettings = ({ user, userChange }: any) => { const [loading, setLoading] = useState(false); - const [twoFactorActived, setTwoFactorActived] = useState(); + const [twoFactorActivated, setTwoFactorActivated] = useState(); const [twoFactoring, setTwoFactoring] = useState(false); const [twoFactorInfo, setTwoFactorInfo] = useState(); const [code, setCode] = useState(); @@ -32,7 +32,7 @@ const SecuritySettings = ({ user, userChange }: any) => { }; const activeOrDeactiveTwoFactor = () => { - if (twoFactorActived) { + if (twoFactorActivated) { deactiveTowFactor(); } else { getTwoFactorInfo(); @@ -45,7 +45,7 @@ const SecuritySettings = ({ user, userChange }: any) => { .put(`${config.apiPrefix}user/two-factor/deactive`) .then((data: any) => { if (data.data) { - setTwoFactorActived(false); + setTwoFactorActivated(false); userChange(); } }) @@ -62,7 +62,7 @@ const SecuritySettings = ({ user, userChange }: any) => { if (data.data) { message.success('激活成功'); setTwoFactoring(false); - setTwoFactorActived(true); + setTwoFactorActivated(true); userChange(); } else { message.success('验证失败'); @@ -86,7 +86,7 @@ const SecuritySettings = ({ user, userChange }: any) => { }; useEffect(() => { - setTwoFactorActived(user && user.twoFactorActived); + setTwoFactorActivated(user && user.twoFactorActivated); }, [user]); return twoFactoring ? ( @@ -198,10 +198,10 @@ const SecuritySettings = ({ user, userChange }: any) => { );