-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathStatelessController.cs
More file actions
44 lines (37 loc) · 1.21 KB
/
StatelessController.cs
File metadata and controls
44 lines (37 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using Edi.Captcha.SampleApp.Models;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Diagnostics;
namespace Edi.Captcha.SampleApp.Controllers;
public class StatelessController(IStatelessCaptcha captcha) : Controller
{
public IActionResult Index()
{
return View(new StatelessCaptchaModel());
}
[HttpPost]
public IActionResult Index(StatelessCaptchaModel model)
{
if (ModelState.IsValid)
{
bool isValidCaptcha = captcha.Validate(model.CaptchaCode, model.CaptchaToken);
return Content(isValidCaptcha ? "Success - Stateless captcha validated!" : "Invalid captcha code");
}
return BadRequest();
}
[Route("get-stateless-captcha")]
public IActionResult GetStatelessCaptcha()
{
var result = captcha.GenerateCaptcha(100, 36);
return Json(new
{
token = result.Token,
imageBase64 = Convert.ToBase64String(result.ImageBytes)
});
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}