-
Notifications
You must be signed in to change notification settings - Fork 1
/
LoginController.cs
65 lines (54 loc) · 2.04 KB
/
LoginController.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
53
54
55
56
57
58
59
60
61
62
63
64
65
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Recaptcha.Verify.Net.AspNetCoreAngular.Models;
using Recaptcha.Verify.Net.Attribute;
using System.Threading;
using System.Threading.Tasks;
namespace Recaptcha.Verify.Net.AspNetCoreAngular.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class LoginController : Controller
{
private const string _loginAction = "login";
private readonly ILogger _logger;
private readonly IRecaptchaService _recaptchaService;
public LoginController(ILoggerFactory loggerFactory, IRecaptchaService recaptchaService)
{
_logger = loggerFactory.CreateLogger<LoginController>();
_recaptchaService = recaptchaService;
}
[HttpPost]
public async Task<IActionResult> Login([FromBody] Credentials credentials, CancellationToken cancellationToken)
{
var checkResult = await _recaptchaService.VerifyAndCheckAsync(
credentials.RecaptchaToken,
_loginAction,
cancellationToken);
if (!checkResult.Success)
{
if (!checkResult.Response.Success)
{
// Handle unsuccessful verification response
_logger.LogError("Recaptcha error: {errorCodes}", JsonConvert.SerializeObject(checkResult.Response.ErrorCodes));
}
if (!checkResult.ScoreSatisfies)
{
// Handle score less than specified threshold for v3
}
// Unsuccessful verification and check
return BadRequest();
}
// Process login
return Ok();
}
[Recaptcha("login")]
[HttpPost("Login_RecaptchaAttribute")]
public IActionResult Login_RecaptchaAttribute([FromForm] Credentials credentials, CancellationToken cancellationToken)
{
// Process login
return Ok();
}
}
}