using Microsoft.AspNetCore.Mvc; using sodoff.Attributes; using sodoff.Model; using sodoff.Schema; using sodoff.Util; namespace sodoff.Controllers.Common; public class ContentController : Controller { private readonly DBContext ctx; public ContentController(DBContext ctx) { this.ctx = ctx; } [HttpPost] [Produces("application/xml")] [Route("ContentWebService.asmx/GetDefaultNameSuggestion")] public IActionResult GetDefaultNameSuggestion() { // TODO: generate random names, and ensure they aren't already taken string[] suggestions = new string[] { "dragon1", "dragon2", "dragon3" }; return Ok(new DisplayNameUniqueResponse { Suggestions = new SuggestionResult { Suggestion = suggestions } }); } [HttpPost] [Produces("application/xml")] [Route("V2/ContentWebService.asmx/ValidateName")] [EncryptResponse] public IActionResult ValidateName([FromForm] string apiToken,[FromForm] string nameValidationRequest) { User? user = ctx.Sessions.FirstOrDefault(e => e.ApiToken == apiToken)?.User; if (user is null) { // TODO: better error handling than just replying not unique return Ok(new NameValidationResponse { Result = NameValidationResult.NotUnique }); } // Check if name populated NameValidationRequest request = XmlUtil.DeserializeXml(nameValidationRequest); if (request.Category == NameCategory.Default) { // This is an avatar we are checking // Check if viking exists bool exists = ctx.Vikings.Count(e => e.Name == request.Name) > 0; NameValidationResult result = exists ? NameValidationResult.NotUnique : NameValidationResult.Ok; return Ok(new NameValidationResponse { Result = result}); } else { // TODO: pets, groups, default return Ok(); } } }