mirror of
https://github.com/Empostor/Empostor.git
synced 2026-11-19 13:16:48 +00:00
Port
This commit is contained in:
1 parent
5d01be5b93
commit
5ea1184813
1 file changed
-49
@@ -1,49 +0,0 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using Empostor.Api.Service.Admin.Verify;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Empostor.Server.Http;
|
||||
|
||||
[Route("/api/verify")]
|
||||
[ApiController]
|
||||
public sealed class VerifyController : ControllerBase
|
||||
{
|
||||
private readonly IVerifyStore _store;
|
||||
|
||||
public VerifyController(IVerifyStore store)
|
||||
{
|
||||
_store = store;
|
||||
}
|
||||
|
||||
[HttpPost("confirm")]
|
||||
public IActionResult Confirm([FromBody] VerifyConfirmRequest req)
|
||||
{
|
||||
if (!_store.ValidateSecret(req.Secret))
|
||||
{
|
||||
return Unauthorized(new { ok = false, error = "Invalid bot secret." });
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(req.FriendCode) || string.IsNullOrWhiteSpace(req.UserOpenid))
|
||||
{
|
||||
return BadRequest(new { ok = false, error = "friendCode and userOpenid are required." });
|
||||
}
|
||||
|
||||
var ok = _store.TryConfirm(req.FriendCode, req.UserOpenid);
|
||||
if (ok)
|
||||
{
|
||||
return Ok(new { ok = true });
|
||||
}
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
ok = false,
|
||||
error = "no_pending_or_expired",
|
||||
message = "No record found or the record has expired.",
|
||||
});
|
||||
}
|
||||
|
||||
public sealed record VerifyConfirmRequest(
|
||||
[property: JsonPropertyName("friendCode")] string FriendCode,
|
||||
[property: JsonPropertyName("userOpenid")] string UserOpenid,
|
||||
[property: JsonPropertyName("secret")] string Secret);
|
||||
}
|
||||
Reference in new issue
Block a user