login endpoint

This commit is contained in:
jvyden 2021-10-06 00:36:05 -04:00
commit 782f04726a
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
9 changed files with 68 additions and 56 deletions

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="DiscordProjectSettings"> <component name="DiscordProjectSettings">
<option name="show" value="ASK" /> <option name="show" value="PROJECT_FILES" />
<option name="description" value="" /> <option name="description" value="" />
</component> </component>
</project> </project>

View file

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
namespace ProjectLighthouse.Controllers {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/login")]
[Produces("text/xml")]
public class LoginController : ControllerBase {
[HttpGet]
[HttpPost]
public IActionResult Post() {
return this.Ok(new LoginResult {
AuthTicket = "d2c6bbec59162a1e786ed24ad95f2b73",
LbpEnvVer = "rLBP_Cepheus"
}.Serialize());
}
}
}

View file

@ -1,33 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace ProjectLighthouse.Controllers {
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase {
private static readonly string[] Summaries = new[] {
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger) {
_logger = logger;
}
[HttpGet]
public IEnumerable<WeatherForecast> Get() {
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast {
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray();
}
}
}

View file

@ -0,0 +1,17 @@
using System.Collections.Generic;
using System.Xml.Serialization;
using ProjectLighthouse.Serialization;
namespace ProjectLighthouse {
public class LoginResult {
public string AuthTicket { get; set; }
public string LbpEnvVer { get; set; }
public string Serialize() {
return LbpSerializer.GetElements(
new KeyValuePair<string, object>("authTicket", AuthTicket),
new KeyValuePair<string, object>("lbpEnvVer", LbpEnvVer)
);
}
}
}

View file

@ -11,8 +11,6 @@
"profiles": { "profiles": {
"IIS Express": { "IIS Express": {
"commandName": "IISExpress", "commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }
@ -20,8 +18,6 @@
"ProjectLighthouse": { "ProjectLighthouse": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": "true", "dotnetRunMessages": "true",
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:5001;http://localhost:5000", "applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"

View file

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace ProjectLighthouse.Serialization {
public static class LbpSerializer {
public static string GetBlankElement(string key) => $"<{key}></{key}>";
public static string GetStringElement(KeyValuePair<string, object> pair) => $"<{pair.Key}>{pair.Value}</{pair.Key}>";
public static string GetStringElement(string key, object value) => $"<{key}>{value}</{key}>";
public static string GetElements(params KeyValuePair<string, object>[] pairs) =>
pairs.Aggregate(string.Empty, (current, pair) => current + GetStringElement(pair));
}
}

View file

@ -0,0 +1,10 @@
using Microsoft.AspNetCore.Mvc.Formatters;
namespace ProjectLighthouse.Serialization {
public class XmlOutputFormatter : StringOutputFormatter {
public XmlOutputFormatter() {
SupportedMediaTypes.Add("text/xml");
SupportedMediaTypes.Add("application/xml");
}
}
}

View file

@ -11,6 +11,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
using ProjectLighthouse.Serialization;
namespace ProjectLighthouse { namespace ProjectLighthouse {
public class Startup { public class Startup {
@ -24,17 +25,14 @@ namespace ProjectLighthouse {
public void ConfigureServices(IServiceCollection services) { public void ConfigureServices(IServiceCollection services) {
services.AddControllers(); services.AddControllers();
services.AddSwaggerGen(c => { services.AddMvc(options =>
c.SwaggerDoc("v1", new OpenApiInfo { Title = "ProjectLighthouse", Version = "v1" }); options.OutputFormatters.Add(new XmlOutputFormatter()));
});
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
if(env.IsDevelopment()) { if(env.IsDevelopment()) {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "ProjectLighthouse v1"));
} }
app.UseHttpsRedirection(); app.UseHttpsRedirection();

View file

@ -1,13 +0,0 @@
using System;
namespace ProjectLighthouse {
public class WeatherForecast {
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string Summary { get; set; }
}
}