Skip to content

Commit ba551a5

Browse files
committed
chore: add error handling and localization for encryption failures
1 parent 84cd37f commit ba551a5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+192
-162
lines changed

src/GZCTF/ClientApp/src/components/GameChallengeModal.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Icon } from '@mdi/react'
66
import React, { FC, useEffect, useState } from 'react'
77
import { useTranslation } from 'react-i18next'
88
import { ChallengeModal } from '@Components/ChallengeModal'
9-
import { showErrorNotification } from '@Utils/ApiHelper'
9+
import { showApiError } from '@Utils/ApiHelper'
1010
import { encryptApiData } from '@Utils/Crypto'
1111
import { ChallengeCategoryItemProps } from '@Utils/Shared'
1212
import { useConfig } from '@Hooks/useConfig'
@@ -65,7 +65,7 @@ export const GameChallengeModal: FC<GameChallengeModalProps> = (props) => {
6565
icon: <Icon path={mdiCheck} size={1} />,
6666
})
6767
} catch (e) {
68-
showErrorNotification(e, t)
68+
showApiError(e, t)
6969
} finally {
7070
setDisabled(false)
7171
}
@@ -93,7 +93,7 @@ export const GameChallengeModal: FC<GameChallengeModalProps> = (props) => {
9393
icon: <Icon path={mdiCheck} size={1} />,
9494
})
9595
} catch (e) {
96-
showErrorNotification(e, t)
96+
showApiError(e, t)
9797
}
9898
}
9999

@@ -120,7 +120,7 @@ export const GameChallengeModal: FC<GameChallengeModalProps> = (props) => {
120120
},
121121
})
122122
} catch (e) {
123-
showErrorNotification(e, t)
123+
showApiError(e, t)
124124
} finally {
125125
setDisabled(false)
126126
}
@@ -140,7 +140,7 @@ export const GameChallengeModal: FC<GameChallengeModalProps> = (props) => {
140140

141141
try {
142142
const res = await api.game.gameSubmit(gameId, challengeId, {
143-
flag: await encryptApiData(flag.trim(), config.apiPublicKey),
143+
flag: await encryptApiData(t, flag.trim(), config.apiPublicKey),
144144
})
145145
setSubmitId(res.data)
146146
notifications.clean()
@@ -153,7 +153,7 @@ export const GameChallengeModal: FC<GameChallengeModalProps> = (props) => {
153153
autoClose: false,
154154
})
155155
} catch (e) {
156-
showErrorNotification(e, t)
156+
showApiError(e, t)
157157
setDisabled(false)
158158
}
159159
}
@@ -174,7 +174,7 @@ export const GameChallengeModal: FC<GameChallengeModalProps> = (props) => {
174174
} catch (err) {
175175
setDisabled(false)
176176
setFlag('')
177-
showErrorNotification(err, t)
177+
showApiError(err, t)
178178
clearInterval(polling)
179179
}
180180
}, 500)

src/GZCTF/ClientApp/src/components/HashPow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { forwardRef, useState, useEffect, useImperativeHandle } from 'react'
44
import { useTranslation } from 'react-i18next'
55
import { CaptchaInstance } from '@Components/Captcha'
66
import { PowWorker } from '@Components/icon/PowWorker'
7-
import { showErrorNotification } from '@Utils/ApiHelper'
7+
import { showApiError } from '@Utils/ApiHelper'
88
import workerScript from '@Utils/PowWorker'
99
import api, { HashPowChallenge } from '@Api'
1010
import classes from '@Styles/HashPow.module.css'
@@ -43,7 +43,7 @@ export const usePowChallenge = () => {
4343
})
4444
}
4545
} catch (e) {
46-
showErrorNotification(e, t)
46+
showApiError(e, t)
4747
return null
4848
}
4949
}

src/GZCTF/ClientApp/src/components/PasswordChangeModal.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { FC } from 'react'
77
import { useTranslation } from 'react-i18next'
88
import { useNavigate } from 'react-router'
99
import { StrengthPasswordInput } from '@Components/StrengthPasswordInput'
10-
import { showErrorNotification } from '@Utils/ApiHelper'
10+
import { showApiError } from '@Utils/ApiHelper'
1111
import { encryptApiData } from '@Utils/Crypto'
1212
import { useConfig } from '@Hooks/useConfig'
1313
import api from '@Api'
@@ -33,8 +33,8 @@ export const PasswordChangeModal: FC<ModalProps> = (props) => {
3333
} else if (pwd === retypedPwd) {
3434
try {
3535
await api.account.accountChangePassword({
36-
old: await encryptApiData(oldPwd, config.apiPublicKey),
37-
new: await encryptApiData(pwd, config.apiPublicKey),
36+
old: await encryptApiData(t, oldPwd, config.apiPublicKey),
37+
new: await encryptApiData(t, pwd, config.apiPublicKey),
3838
})
3939
showNotification({
4040
color: 'teal',
@@ -45,7 +45,7 @@ export const PasswordChangeModal: FC<ModalProps> = (props) => {
4545
api.account.accountLogOut()
4646
navigate('/account/login')
4747
} catch (e) {
48-
showErrorNotification(e, t)
48+
showApiError(e, t)
4949
}
5050
} else {
5151
showNotification({

src/GZCTF/ClientApp/src/components/TeamCreateModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { mdiCheck, mdiCloseCircle } from '@mdi/js'
1515
import { Icon } from '@mdi/react'
1616
import { FC, useState } from 'react'
1717
import { Trans, useTranslation } from 'react-i18next'
18-
import { showErrorNotification } from '@Utils/ApiHelper'
18+
import { showApiError } from '@Utils/ApiHelper'
1919
import api, { TeamUpdateModel } from '@Api'
2020

2121
interface TeamEditModalProps extends ModalProps {
@@ -46,7 +46,7 @@ export const TeamCreateModal: FC<TeamEditModalProps> = (props) => {
4646
mutate()
4747
modalProps.onClose()
4848
} catch (e) {
49-
showErrorNotification(e, t)
49+
showApiError(e, t)
5050
} finally {
5151
setDisabled(false)
5252
}

src/GZCTF/ClientApp/src/components/TeamEditModal.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { mdiCheck, mdiClose, mdiRefresh, mdiStar } from '@mdi/js'
2626
import { Icon } from '@mdi/react'
2727
import { FC, useEffect, useState } from 'react'
2828
import { useTranslation } from 'react-i18next'
29-
import { showErrorNotification, tryGetErrorMsg } from '@Utils/ApiHelper'
29+
import { showApiError, tryGetErrorMsg } from '@Utils/ApiHelper'
3030
import { IMAGE_MIME_TYPES } from '@Utils/Shared'
3131
import api, { TeamInfoModel, TeamUserInfoModel } from '@Api'
3232
import misc from '@Styles/Misc.module.css'
@@ -131,7 +131,7 @@ export const TeamEditModal: FC<TeamEditModalProps> = (props) => {
131131
setTeamInfo(null)
132132
props.onClose()
133133
} catch (e) {
134-
showErrorNotification(e, t)
134+
showApiError(e, t)
135135
}
136136
}
137137

@@ -154,7 +154,7 @@ export const TeamEditModal: FC<TeamEditModalProps> = (props) => {
154154
)
155155
props.onClose()
156156
} catch (e) {
157-
showErrorNotification(e, t)
157+
showApiError(e, t)
158158
}
159159
}
160160

@@ -178,7 +178,7 @@ export const TeamEditModal: FC<TeamEditModalProps> = (props) => {
178178
}
179179
)
180180
} catch (e) {
181-
showErrorNotification(e, t)
181+
showApiError(e, t)
182182
}
183183
}
184184

@@ -200,7 +200,7 @@ export const TeamEditModal: FC<TeamEditModalProps> = (props) => {
200200
}
201201
)
202202
} catch (e) {
203-
showErrorNotification(e, t)
203+
showApiError(e, t)
204204
}
205205
}
206206

@@ -216,7 +216,7 @@ export const TeamEditModal: FC<TeamEditModalProps> = (props) => {
216216
icon: <Icon path={mdiCheck} size={1} />,
217217
})
218218
} catch (e) {
219-
showErrorNotification(e, t)
219+
showApiError(e, t)
220220
}
221221
}
222222

@@ -286,7 +286,7 @@ export const TeamEditModal: FC<TeamEditModalProps> = (props) => {
286286
}
287287
)
288288
} catch (e) {
289-
showErrorNotification(e, t)
289+
showApiError(e, t)
290290
}
291291
}
292292

src/GZCTF/ClientApp/src/components/WriteupSubmitModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import dayjs from 'dayjs'
2222
import { FC, useEffect, useState } from 'react'
2323
import { Trans, useTranslation } from 'react-i18next'
2424
import { Markdown } from '@Components/MarkdownRenderer'
25-
import { showErrorNotification } from '@Utils/ApiHelper'
25+
import { showApiError } from '@Utils/ApiHelper'
2626
import { useLanguage } from '@Utils/I18n'
2727
import { HunamizeSize } from '@Utils/Shared'
2828
import { OnceSWRConfig } from '@Hooks/useConfig'
@@ -79,7 +79,7 @@ export const WriteupSubmitModal: FC<WriteupSubmitModalProps> = ({ gameId, writeu
7979
mutate()
8080
setDisabled(false)
8181
} catch (err) {
82-
showErrorNotification(err, t)
82+
showApiError(err, t)
8383
} finally {
8484
setProgress(0)
8585
setDisabled(false)

src/GZCTF/ClientApp/src/components/WsrxProvider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Icon } from '@mdi/react'
55
import { Wsrx, WsrxError, WsrxErrorKind, WsrxFeature, WsrxOptions, WsrxState } from '@xdsec/wsrx'
66
import { t } from 'i18next'
77
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react'
8-
import { showErrorNotification } from '@Utils/ApiHelper'
8+
import { showApiError } from '@Utils/ApiHelper'
99
import { useConfig } from '@Hooks/useConfig'
1010

1111
interface CustomWsrxOptions {
@@ -60,7 +60,7 @@ export const HandleWsrxError = (err: unknown, t: (key: string) => string) => {
6060
})
6161
}
6262
} else {
63-
showErrorNotification(err, t)
63+
showApiError(err, t)
6464
}
6565
}
6666

src/GZCTF/ClientApp/src/components/admin/AttachmentRemoteEditModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Icon } from '@mdi/react'
55
import { FC, useEffect, useState } from 'react'
66
import { useTranslation } from 'react-i18next'
77
import { useParams } from 'react-router'
8-
import { showErrorNotification } from '@Utils/ApiHelper'
8+
import { showApiError } from '@Utils/ApiHelper'
99
import { useEditChallenge } from '@Hooks/useEdit'
1010
import api, { FileType, FlagCreateModel } from '@Api'
1111
import misc from '@Styles/Misc.module.css'
@@ -54,7 +54,7 @@ export const AttachmentRemoteEditModal: FC<ModalProps> = (props) => {
5454
mutate()
5555
props.onClose()
5656
} catch (e) {
57-
showErrorNotification(e, t)
57+
showApiError(e, t)
5858
} finally {
5959
setDisabled(false)
6060
}

src/GZCTF/ClientApp/src/components/admin/AttachmentUploadModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { Icon } from '@mdi/react'
2323
import { FC, useState } from 'react'
2424
import { useTranslation } from 'react-i18next'
2525
import { useParams } from 'react-router'
26-
import { showErrorNotification } from '@Utils/ApiHelper'
26+
import { showApiError } from '@Utils/ApiHelper'
2727
import { useEditChallenge } from '@Hooks/useEdit'
2828
import api, { FileType } from '@Api'
2929
import uploadClasses from '@Styles/Upload.module.css'
@@ -93,7 +93,7 @@ export const AttachmentUploadModal: FC<ModalProps> = (props) => {
9393
props.onClose()
9494
}
9595
} catch (err) {
96-
showErrorNotification(err, t)
96+
showApiError(err, t)
9797
} finally {
9898
setDisabled(false)
9999
}

src/GZCTF/ClientApp/src/components/admin/ChallengeCreateModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Icon } from '@mdi/react'
66
import { FC, useState } from 'react'
77
import { useTranslation } from 'react-i18next'
88
import { useNavigate, useParams } from 'react-router'
9-
import { showErrorNotification } from '@Utils/ApiHelper'
9+
import { showApiError } from '@Utils/ApiHelper'
1010
import {
1111
ChallengeCategoryItem,
1212
ChallengeCategoryList,
@@ -54,7 +54,7 @@ export const ChallengeCreateModal: FC<ChallengeCreateModalProps> = (props) => {
5454
onAddChallenge(res.data)
5555
navigate(`/admin/games/${id}/challenges/${res.data.id}`)
5656
} catch (e) {
57-
showErrorNotification(e, t)
57+
showApiError(e, t)
5858
} finally {
5959
setDisabled(false)
6060
}

0 commit comments

Comments
 (0)