154 lines
2.8 KiB
C#
154 lines
2.8 KiB
C#
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<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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()
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|