using Microsoft.AspNetCore.Mvc; using Shadow.Data; using Shadow.DTOs; using Shadow.Entities; using Shadow.Tools; namespace Shadow.Controllers; [ApiController] [Route("rest")] [Produces("application/json")] public class MiscController : ControllerBase { private readonly ApplicationDbContext db; private readonly GeneralUseHelpers guhf; public MiscController(ApplicationDbContext _db, GeneralUseHelpers _guhf) { db = _db; guhf = _guhf; } [HttpGet("ping")] [ProducesResponseType(200)] public async Task Ping() { User? user = await guhf.GetUserFromParams(Request); // Wrong credentials? if (user == null) { // Craft an error return Ok(new ResponseWrapper { SubsonicResponse = new SubsonicResponseDTO { Status = "failed", error = new ErrorDTO { code = 40, message = "Wrong username or password." } } }); } return Ok(new ResponseWrapper { SubsonicResponse = new SubsonicResponseDTO() }); } [HttpPost("ping.view")] [ProducesResponseType(200)] public async Task PingForm() { User? user = await guhf.GetUserFromForm(Request); // Wrong credentials? if (user == null) { // Craft an error return Ok(new ResponseWrapper { SubsonicResponse = new SubsonicResponseDTO { Status = "failed", error = new ErrorDTO { code = 40, message = "Wrong username or password." } } }); } return Ok(new ResponseWrapper { SubsonicResponse = new SubsonicResponseDTO() }); } [HttpGet("getUser")] [ProducesResponseType(200)] public async Task GetUser() { User? user = await guhf.GetUserFromParams(Request); // Wrong credentials? if (user == null) { // Craft an error return Ok(new ResponseWrapper { SubsonicResponse = new SubsonicResponseDTO { Status = "failed", error = new ErrorDTO { code = 40, message = "Wrong username or password." } } }); } return Ok(new ResponseWrapper { SubsonicResponse = new SubsonicResponseDTO { userPing = new UserPingDTO { username = user.Name, adminRole = user.IsAdmin() } } }); } [HttpPost("getUser.view")] [ProducesResponseType(200)] public async Task GetUserForm() { User? user = await guhf.GetUserFromForm(Request); // Wrong credentials? if (user == null) { // Craft an error return Ok(new ResponseWrapper { SubsonicResponse = new SubsonicResponseDTO { Status = "failed", error = new ErrorDTO { code = 40, message = "Wrong username or password." } } }); } return Ok(new ResponseWrapper { SubsonicResponse = new SubsonicResponseDTO { userPing = new UserPingDTO { username = user.Name, adminRole = user.IsAdmin() } } }); } }