Skip to content

Commit

Permalink
Merge remote-tracking branch 'another/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mnixry committed Sep 14, 2024
2 parents c19c150 + 4783e89 commit f37e7bb
Show file tree
Hide file tree
Showing 20 changed files with 114 additions and 50 deletions.
47 changes: 22 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: ["develop", "ci/*", "v*"]
tags: ["v*"]
paths: ["src/GZCTF/**"]
paths: ["src/GZCTF/**", ".github/workflows/**"]
workflow_dispatch:

jobs:
Expand All @@ -14,6 +14,10 @@ jobs:
run:
working-directory: src/GZCTF

permissions:
packages: write
contents: read

steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -51,12 +55,6 @@ jobs:
- name: Docker setup Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: gztime
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
Expand All @@ -78,14 +76,13 @@ jobs:
# latest tag is only created for `v*.*.*` or `v*.*.*-patch.*` tags
RELEASE: ${{ startsWith(github.ref, 'refs/tags/v') && (contains(github.ref, 'patch') || !contains(github.ref, '-')) }}
with:
images: |
gztime/gzctf
ghcr.io/${{ github.repository }}/gzctf
registry.cn-shanghai.aliyuncs.com/gztime/gzctf
images: ghcr.io/${{ github.repository }}
github-token: ${{ secrets.GITHUB_TOKEN }}
flavor: |
latest=${{ env.RELEASE }}
tags: |
type=ref,event=branch
develop,enable=${{ startsWith(github.ref, 'refs/heads/develop') }}
type=sha,enable=true,priority=100,prefix=,suffix=,format=short
type=match,enable=${{ env.RELEASE }},pattern=v\d+,group=0
type=match,enable=${{ env.RELEASE }},pattern=v\d+.\d+,group=0
Expand All @@ -100,17 +97,17 @@ jobs:
platforms: linux/amd64,linux/arm64
push: true

- name: Prune old packages
uses: vlaurin/[email protected]
with:
dry-run: false
token: ${{ secrets.PACKAGE_TOKEN }}
container: ${{ github.event.repository.name }}/gzctf
keep-tags-regexes: ^v\d+\.\d+\.\d+$
prune-tags-regexes: ^[0-9a-f]{6,40}
keep-tags: |
latest
main
develop
keep-last: 20
prune-untagged: false
#- name: Prune old packages
# uses: vlaurin/[email protected]
# with:
# dry-run: false
# token: ${{ secrets.PACKAGE_TOKEN }}
# container: ${{ github.event.repository.name }}/gzctf
# keep-tags-regexes: ^v\d+\.\d+\.\d+$
# prune-tags-regexes: ^[0-9a-f]{6,40}
# keep-tags: |
# latest
# main
# develop
# keep-last: 20
# prune-untagged: false
7 changes: 7 additions & 0 deletions src/GZCTF/ClientApp/src/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ export type RegisterModel = ModelWithCaptcha & {
* @minLength 1
*/
password: string;
/**
* 学号
* @minLength 1
* @pattern ^20\d{8}$
*/
stdNumber: string
/**
* 邮箱
* @format email
Expand Down Expand Up @@ -633,6 +639,7 @@ export enum ChallengeTag {
Mobile = "Mobile",
PPC = "PPC",
AI = "AI",
Abstract = 'Abstract',
}

/** 列表响应 */
Expand Down
2 changes: 1 addition & 1 deletion src/GZCTF/ClientApp/src/components/GameJoinModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const GameJoinModal: FC<GameJoinModalProps> = (props) => {

const [inviteCode, setInviteCode] = useState('')
const [organization, setOrganization] = useState('')
const [team, setTeam] = useState('')
const [team, setTeam] = useState(teams?.[0]?.id?.toString() ?? '')
const [disabled, setDisabled] = useState(false)

const { t } = useTranslation()
Expand Down
2 changes: 1 addition & 1 deletion src/GZCTF/ClientApp/src/components/WithNavbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const WithNavBar: FC<WithNavBarProps> = ({
const openColorModal = () => setColorModalOpened(true)

return (
<WithWiderScreen minWidth={minWidth}>
<WithWiderScreen minWidth={minWidth} override={true}>
<Watermark
text={user?.userId ?? ''}
textColor={colorScheme === 'dark' ? theme.colors.gray[3] : theme.colors.gray[7]}
Expand Down
10 changes: 8 additions & 2 deletions src/GZCTF/ClientApp/src/components/WithWiderScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ import IconWiderScreenRequired from '@Components/icon/WiderScreenRequiredIcon'

interface WithWiderScreenProps extends React.PropsWithChildren {
minWidth?: number
override?: boolean
}

const WithWiderScreen: FC<WithWiderScreenProps> = ({ children, minWidth = 1080 }) => {
const WithWiderScreen: FC<WithWiderScreenProps> = ({
children,
minWidth = 1080,
override = false,
}) => {
const view = useViewportSize()

const { t } = useTranslation()
const theme = useMantineTheme()

const tooSmall = minWidth > 0 && view.width > 0 && view.width < minWidth
let tooSmall = minWidth > 0 && view.width > 0 && view.width < minWidth
if (override) tooSmall = false

return tooSmall ? (
<Stack gap={0} align="center" justify="center" h="calc(100vh - 32px)">
Expand Down
1 change: 1 addition & 0 deletions src/GZCTF/ClientApp/src/locales/en_US/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"email_new": "New Email",
"real_name": "Real Name",
"student_id": "Student ID",
"stdNumber": "Student ID",
"password_old": "Original password",
"password_retype": "Confirm password",
"username_or_email": "Username or Email"
Expand Down
3 changes: 2 additions & 1 deletion src/GZCTF/ClientApp/src/locales/en_US/challenge.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@
"ppc": "PPC",
"pwn": "Pwn",
"reverse": "Reverse",
"web": "Web"
"web": "Web",
"abstract": "Abstract"
},
"type": {
"dynamic_attachment": {
Expand Down
1 change: 1 addition & 0 deletions src/GZCTF/ClientApp/src/locales/ja_JP/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"email_new": "新メール",
"real_name": "氏名",
"student_id": "学生番号",
"stdNumber": "学生番号",
"password_old": "現在のパスワード",
"password_retype": "パスワード再確認",
"username_or_email": "ユーザー名またはメール"
Expand Down
3 changes: 2 additions & 1 deletion src/GZCTF/ClientApp/src/locales/ja_JP/challenge.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@
"ppc": "プログラミング",
"pwn": "Pwn",
"reverse": "リバースエンジニアリング",
"web": "Web"
"web": "Web",
"abstract": "抽象"
},
"type": {
"dynamic_attachment": {
Expand Down
1 change: 1 addition & 0 deletions src/GZCTF/ClientApp/src/locales/zh_CN/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"email_new": "新邮箱",
"real_name": "真实姓名",
"student_id": "学工号",
"stdNumber": "学号",
"password_old": "原密码",
"password_retype": "确认密码",
"username_or_email": "用户名或邮箱"
Expand Down
3 changes: 2 additions & 1 deletion src/GZCTF/ClientApp/src/locales/zh_CN/challenge.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@
"ppc": "编程",
"pwn": "Pwn",
"reverse": "逆向",
"web": "Web"
"web": "Web",
"abstract": "抽象"
},
"type": {
"dynamic_attachment": {
Expand Down
33 changes: 24 additions & 9 deletions src/GZCTF/ClientApp/src/pages/account/Register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const Register: FC = () => {
const [retypedPwd, setRetypedPwd] = useInputState('')
const [uname, setUname] = useInputState('')
const [email, setEmail] = useInputState('')
const [stdNumber, setStdNumber] = useInputState('')
const [disabled, setDisabled] = useState(false)

const navigate = useNavigate()
Expand Down Expand Up @@ -91,6 +92,7 @@ const Register: FC = () => {
userName: uname,
password: pwd,
email: email,
stdNumber: stdNumber,
challenge: token,
})
const data = RegisterStatusMap.get(res.data.data)
Expand Down Expand Up @@ -127,23 +129,36 @@ const Register: FC = () => {
<AccountView onSubmit={onRegister}>
<TextInput
required
label={t('account.label.email')}
type="email"
placeholder="[email protected]"
label={t('account.label.username')}
type="text"
placeholder="ctfer"
w="100%"
value={email}
value={uname}
disabled={disabled}
onChange={(event) => setEmail(event.currentTarget.value)}
onChange={(event) => setUname(event.currentTarget.value)}
/>
<TextInput
required
label={t('account.label.username')}
label={t('account.label.stdNumber')}
type="text"
placeholder="ctfer"
placeholder="2024000000"
w="100%"
value={uname}
value={stdNumber}
disabled={disabled}
onChange={(event) => setUname(event.currentTarget.value)}
onChange={(event) => [
setStdNumber(event.currentTarget.value),
setEmail(event.currentTarget.value + '@bupt.cn'),
]}
/>
<TextInput
required
label={t('account.label.email')}
type="email"
placeholder="[email protected]"
w="100%"
value={email}
disabled={disabled}
onChange={(event) => setEmail(event.currentTarget.value)}
/>
<StrengthPasswordInput
value={pwd}
Expand Down
11 changes: 11 additions & 0 deletions src/GZCTF/ClientApp/src/utils/Shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
mdiChip,
mdiClose,
mdiConsole,
mdiEmoticonLolOutline,
mdiEthereum,
mdiFingerprint,
mdiFlag,
Expand Down Expand Up @@ -216,6 +217,16 @@ export const useChallengeTagLabelMap = () => {
colors: theme.colors['green'],
},
],
[
ChallengeTag.Abstract,
{
desrc: t('challenge.tag.abstract'),
icon: mdiEmoticonLolOutline,
name: ChallengeTag.Abstract,
color: 'yellow',
colors: theme.colors['yellow'],
},
],
])
}

Expand Down
8 changes: 7 additions & 1 deletion src/GZCTF/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class AccountController(
IOptionsSnapshot<AccountPolicy> accountPolicy,
IOptionsSnapshot<GlobalConfig> globalConfig,
UserManager<UserInfo> userManager,
ITeamRepository teamRepository,
SignInManager<UserInfo> signInManager,
ILogger<AccountController> logger,
IStringLocalizer<Program> localizer) : ControllerBase
Expand Down Expand Up @@ -58,7 +59,7 @@ public async Task<IActionResult> Register([FromBody] RegisterModel model, Cancel
return BadRequest(new RequestResponse(localizer[nameof(Resources.Program.Account_AvailableEmailDomain),
accountPolicy.Value.EmailDomainList]));

var user = new UserInfo { UserName = model.UserName, Email = model.Email, Role = Role.User };
var user = new UserInfo { UserName = model.UserName, Email = model.Email, StdNumber = model.StdNumber, Role = Role.User };

user.UpdateByHttpContext(HttpContext);

Expand All @@ -76,7 +77,12 @@ public async Task<IActionResult> Register([FromBody] RegisterModel model, Cancel

user = current;
}
var team = await teamRepository.CreateTeam(new(){ Name = model.UserName }, user);

if (team is null)
{
logger.Log("用户个人队伍创建失败", user, TaskStatus.Failed);
}
if (accountPolicy.Value.ActiveOnRegister)
{
user.EmailConfirmed = true;
Expand Down
9 changes: 9 additions & 0 deletions src/GZCTF/Models/Request/Account/RegisterModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ public class RegisterModel : ModelWithCaptcha
ErrorMessageResourceType = typeof(Resources.Program))]
public string Password { get; set; } = string.Empty;

/// <summary>
/// 学号
/// </summary>
[Required(ErrorMessageResourceName = nameof(Resources.Program.Model_StdNumberRequired),
ErrorMessageResourceType = typeof(Resources.Program))]
[RegularExpression(@"^20\d{8}$", ErrorMessageResourceName = nameof(Resources.Program.Model_MalformedStdNumber),
ErrorMessageResourceType = typeof(Resources.Program))]
public string StdNumber { get; set; } = string.Empty;

/// <summary>
/// 邮箱
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions src/GZCTF/Resources/Program.resx
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,12 @@
<data name="Model_UserNameTooShort" xml:space="preserve">
<value>用户名过短</value>
</data>
<data name="Model_StdNumberRequired" xml:space="preserve">
<value>学号是必需的</value>
</data>
<data name="Model_MalformedStdNumber" xml:space="preserve">
<value>学号格式错误</value>
</data>
<data name="Model_ValidationFailed" xml:space="preserve">
<value>校验失败,请检查输入。</value>
</data>
Expand Down
4 changes: 2 additions & 2 deletions src/GZCTF/Services/Container/Manager/DockerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ CreateContainerParameters GetCreateContainerParameters(ContainerConfig config) =
},
Name = DockerMetadata.GetName(config),
Env = config.Flag is null
? [$"GZCTF_TEAM_ID={config.TeamId}"]
: [$"GZCTF_FLAG={config.Flag}", $"GZCTF_TEAM_ID={config.TeamId}"],
? [$"TEAM_ID={config.TeamId}"]
: [$"FLAG={config.Flag}", $"TEAM_ID={config.TeamId}"],
HostConfig = new()
{
Memory = config.MemoryLimit * 1024 * 1024,
Expand Down
6 changes: 3 additions & 3 deletions src/GZCTF/Services/Container/Manager/KubernetesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ authSecretName is null
ImagePullPolicy = "Always",
Env =
config.Flag is null
? [new V1EnvVar("GZCTF_TEAM_ID", config.TeamId)]
? [new V1EnvVar("TEAM_ID", config.TeamId)]
:
[
new V1EnvVar("GZCTF_FLAG", config.Flag),
new V1EnvVar("GZCTF_TEAM_ID", config.TeamId)
new V1EnvVar("FLAG", config.Flag),
new V1EnvVar("TEAM_ID", config.TeamId)
],
Ports = [new V1ContainerPort(config.ExposedPort)],
Resources = new V1ResourceRequirements
Expand Down
4 changes: 2 additions & 2 deletions src/GZCTF/Services/Container/Manager/SwarmManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ ServiceCreateParameters GetServiceCreateParameters(ContainerConfig config) =>
Image = config.Image,
Env =
config.Flag is null
? [$"GZCTF_TEAM_ID={config.TeamId}"]
: [$"GZCTF_FLAG={config.Flag}", $"GZCTF_TEAM_ID={config.TeamId}"],
? [$"TEAM_ID={config.TeamId}"]
: [$"FLAG={config.Flag}", $"GTEAM_ID={config.TeamId}"],
},
Resources = new()
{
Expand Down
3 changes: 2 additions & 1 deletion src/GZCTF/Utils/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ public enum ChallengeTag : byte
Hardware = 7,
Mobile = 8,
PPC = 9,
AI = 10
AI = 10,
Abstract = 11,
}

/// <summary>
Expand Down

0 comments on commit f37e7bb

Please sign in to comment.