Skip to content

Commit

Permalink
Allow creating single-user groups, allow auto-generating group name
Browse files Browse the repository at this point in the history
  • Loading branch information
JanWichelmann committed Oct 16, 2024
1 parent 26df681 commit 6f74a0c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public async Task<IActionResult> HandleGroupSelectionAsync(GroupSelection groupS
// Filter group codes
var groupSizeMin = await configurationService.GroupSizeMin.GetAsync(HttpContext.RequestAborted);
var groupSizeMax = await configurationService.GroupSizeMax.GetAsync(HttpContext.RequestAborted);
var codes = groupSelection.OtherUserCodes
.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries)
var codes = (groupSelection.OtherUserCodes ?? "")
.Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries)
.Where(c => !string.IsNullOrWhiteSpace(c))
.Append(currentUser.GroupFindingCode)
.Select(c => c.Trim())
Expand All @@ -80,7 +80,7 @@ public async Task<IActionResult> HandleGroupSelectionAsync(GroupSelection groupS
// The service method will do further error checking (i.e., validity of codes, whether users are already in a group, ...)
var group = new Group
{
DisplayName = groupSelection.DisplayName,
DisplayName = groupSelection.DisplayName ?? $"group{Random.Shared.Next(10000, 100000)}",
SlotId = groupSelection.SlotId,
ShowInScoreboard = groupSelection.ShowInScoreboard
};
Expand Down Expand Up @@ -128,11 +128,11 @@ public async Task<IActionResult> HandleGroupSelectionAsync(GroupSelection groupS
{
GetLogger().LogError(ex, "Start default lab on group creation");
PostStatusMessage = new StatusMessage(StatusMessageType.Error, Localizer["HandleGroupSelectionAsync:DefaultLabStartError"]);
return await RedirectAsync(null);
return RedirectToAction("RenderLabPage", "UserDashboard");
}

// Success
PostStatusMessage = new StatusMessage(StatusMessageType.Success, Localizer["HandleGroupSelectionAsync:Success"]);
return await RedirectAsync(null);
return RedirectToAction("RenderLabPage", "UserDashboard");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<comment>Form:DisplayName</comment>
</data>
<data name="Form:DisplayName:Description" xml:space="preserve">
<value>Dieses Feld hat volle Unicode-Unterstützung, Ihrer Kreativität sind abgesehen von der Längenbeschränkung also keine Grenzen gesetzt. Der Gruppenname kann anschließend nicht mehr geändert werden.</value>
<value>Dieses Feld hat volle Unicode-Unterstützung, Ihrer Kreativität sind abgesehen von der Längenbeschränkung also keine Grenzen gesetzt. Der Gruppenname kann anschließend nicht mehr geändert werden. Wenn Sie keinen Namen angeben, wird ein automatisch erzeugter Name verwendet.</value>
<comment>Form:DisplayName:Description</comment>
</data>
<data name="Form:ShowInScoreboard" xml:space="preserve">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<comment>Form:DisplayName</comment>
</data>
<data name="Form:DisplayName:Description" xml:space="preserve">
<value>This field has full Unicode support, so apart from the length limitation there are no limits to your creativity. Afterwards, the group name cannot be changed anymore.</value>
<value>This field has full Unicode support, so apart from the length limitation there are no limits to your creativity. Afterwards, the group name cannot be changed anymore. If you don't specify a name, an autogenerated one will be used.</value>
<comment>Form:DisplayName:Description</comment>
</data>
<data name="Form:ShowInScoreboard" xml:space="preserve">
Expand Down
3 changes: 0 additions & 3 deletions src/Ctf4e.Server/ViewModels/GroupSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ namespace Ctf4e.Server.ViewModels;

public class GroupSelection
{
[Required(AllowEmptyStrings = true, ErrorMessage = ValidationStrings.FieldIsRequired)]
[DisplayFormat(ConvertEmptyStringToNull = false)]
public string OtherUserCodes { get; set; }

[Required(AllowEmptyStrings = false, ErrorMessage = ValidationStrings.FieldIsRequired)]
[StringLength(50)]
public string DisplayName { get; set; }

Expand Down
30 changes: 18 additions & 12 deletions src/Ctf4e.Server/Views/Authentication/SelectGroup.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,25 @@

@Html.Raw(MarkdownService.GetRenderedHtml(await ConfigurationService.GroupSelectionPageText.GetAsync(Context.RequestAborted)))

<p>
@Localizer["YourCode", currentUser.GroupFindingCode]
</p>
@if(await ConfigurationService.GroupSizeMax.GetAsync(Context.RequestAborted) > 1)
{
<p>
@Localizer["YourCode", currentUser.GroupFindingCode]
</p>
}

<form asp-controller="Authentication" asp-action="HandleGroupSelection" method="post">
<div class="mb-3">
<label class="form-label" asp-for="OtherUserCodes">@Localizer["Form:OtherUserCodes"]</label>
<textarea asp-for="OtherUserCodes" class="form-control font-monospace" placeholder="Codes eingeben" rows="4" cols="40"></textarea>
<small class="form-text text-muted">
@Localizer["Form:OtherUserCodes:Description"]
</small>
<span asp-validation-for="OtherUserCodes" class="text-danger"></span>
</div>
<form asp-controller="Authentication" asp-action="HandleGroupSelection" method="post">
@if(await ConfigurationService.GroupSizeMax.GetAsync(Context.RequestAborted) > 1)
{
<div class="mb-3">
<label class="form-label" asp-for="OtherUserCodes">@Localizer["Form:OtherUserCodes"]</label>
<textarea asp-for="OtherUserCodes" class="form-control font-monospace" placeholder="Codes eingeben" rows="4" cols="40"></textarea>
<small class="form-text text-muted">
@Localizer["Form:OtherUserCodes:Description"]
</small>
<span asp-validation-for="OtherUserCodes" class="text-danger"></span>
</div>
}
<div class="mb-3">
<label class="form-label" asp-for="SlotId">@Localizer["Form:SlotId"]</label>
<select asp-for="SlotId" asp-items="@(new SelectList(slots, nameof(Slot.Id), nameof(Slot.Name)))" class="form-select"></select>
Expand Down

0 comments on commit 6f74a0c

Please sign in to comment.