This repository has been archived by the owner on Aug 7, 2021. It is now read-only.
forked from VahidN/DNTCaptcha.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NgxController.cs
52 lines (48 loc) · 1.92 KB
/
NgxController.cs
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
45
46
47
48
49
50
51
52
using DNTCaptcha.Core;
using DNTCaptcha.TestWebApp.Models;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
namespace DNTCaptcha.TestWebApp.Controllers
{
[Route("api/[controller]")]
[EnableCors("CorsPolicy")]
public class NgxController : Controller
{
private readonly IDNTCaptchaApiProvider _apiProvider;
public NgxController(IDNTCaptchaApiProvider apiProvider)
{
_apiProvider = apiProvider;
}
[HttpPost("[action]")]
[ValidateDNTCaptcha(ErrorMessage = "Please enter the security code as a number.",
CaptchaGeneratorLanguage = Language.English,
CaptchaGeneratorDisplayMode = DisplayMode.NumberToWord)]
public IActionResult Login([FromBody] AccountViewModel data)
{
if (ModelState.IsValid) // If `ValidateDNTCaptcha` fails, it will set a `ModelState.AddModelError`.
{
//TODO: Save data
return Ok(new { name = data.Username });
}
return BadRequest(ModelState);
}
[HttpGet("[action]")]
[ResponseCache(Location = ResponseCacheLocation.None, NoStore = true, Duration = 0)]
public ActionResult<DNTCaptchaApiResponse> CreateDNTCaptchaParams()
{
// Note: For security reasons, a JavaScript client shouldn't be able to provide these attributes directly.
// Otherwise an attacker will be able to change them and make them easier!
return _apiProvider.CreateDNTCaptcha(new DNTCaptchaTagHelperHtmlAttributes
{
BackColor = "#f7f3f3",
FontName = "Tahoma",
FontSize = 18,
ForeColor = "#111111",
Language = Language.English,
DisplayMode = DisplayMode.SumOfTwoNumbers,
Max = 90,
Min = 1
});
}
}
}