feat(account): /account/update_birth persists viewer birth date

Strict yyyy-MM-dd parse (matches /load/index round-trip format) — rejects
malformed input. data_headers.servertime is emitted by the standard
envelope, which is what the client reads into BirthDayUpdateServerTime.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-13 11:35:41 -04:00
parent 715dd4dea8
commit a5fe484775
3 changed files with 77 additions and 0 deletions

View File

@@ -57,4 +57,24 @@ public class AccountController : SVSimController
// which is a first-set-vs-update signal we have no use for yet.
return new EmptyResponse();
}
[HttpPost("update_birth")]
public async Task<ActionResult<EmptyResponse>> UpdateBirth([FromBody] AccountUpdateBirthRequest request)
{
if (!TryGetViewerId(out long viewerId)) return Unauthorized();
// Wire format is "yyyy-MM-dd" (see /load/index UserInfo.Birthday round-trip).
// Parse strict; client only ever submits via its date-picker dialog.
if (!DateTime.TryParseExact(request.Birth, "yyyy-MM-dd",
System.Globalization.CultureInfo.InvariantCulture,
System.Globalization.DateTimeStyles.AssumeUniversal | System.Globalization.DateTimeStyles.AdjustToUniversal,
out var birth))
return BadRequest(new { error = "birth_invalid" });
var viewer = await _db.Viewers.FirstAsync(v => v.Id == viewerId);
viewer.Info.BirthDate = birth;
await _db.SaveChangesAsync();
// data_headers.servertime drives the client's BirthDayUpdateServerTime — the standard
// envelope already emits it, so an empty data payload is sufficient.
return new EmptyResponse();
}
}

View File

@@ -0,0 +1,13 @@
using System.Text.Json.Serialization;
using MessagePack;
using SVSim.EmulatedEntrypoint.Models.Dtos.Requests;
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Requests.Account;
[MessagePackObject]
public class AccountUpdateBirthRequest : BaseRequest
{
[JsonPropertyName("birth")]
[Key("birth")]
public string Birth { get; set; } = string.Empty;
}