-
Notifications
You must be signed in to change notification settings - Fork 49
/
HomeController.cs
104 lines (82 loc) · 2.98 KB
/
HomeController.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using reCAPTCHA.AspNetCore.Attributes;
using reCAPTCHA.AspNetCore.Example.Models;
namespace reCAPTCHA.AspNetCore.Example.Controllers
{
public class HomeController : Controller
{
private readonly IRecaptchaService _recaptcha;
private readonly double _minimumScore;
private readonly string _errorMessage;
public HomeController(IRecaptchaService recaptcha)
{
_recaptcha = recaptcha;
_minimumScore = 0.5;
_errorMessage = "There was an error validating the google recaptcha response. Please try again, or contact the site owner.";
}
public IActionResult Index()
{
return View();
}
public IActionResult Contact()
{
ViewData["Message"] = "Your contact page.";
return View(new ContactModel());
}
public IActionResult Contact2()
{
ViewData["Message"] = "Your contact page.";
return View(new ContactModel());
}
public IActionResult Contact3()
{
ViewData["Message"] = "Your contact page.";
return View(new ContactModel());
}
public IActionResult Contact4()
{
ViewData["Message"] = "Your contact page.";
return View(new ContactModel());
}
[HttpPost]
[ValidateRecaptcha(0.5)]
public IActionResult Contact(ContactModel model)
{
ViewData["Message"] = "Your contact page.";
return View(!ModelState.IsValid ? model : new ContactModel());
}
[HttpPost]
public async Task<IActionResult> Contact2(ContactModel model)
{
ViewData["Message"] = "Your contact page.";
var recaptcha = await _recaptcha.Validate(Request);
if (!recaptcha.success || recaptcha.score != 0 && recaptcha.score < _minimumScore)
ModelState.AddModelError("Recaptcha", _errorMessage);
return View(!ModelState.IsValid ? model : new ContactModel());
}
[HttpPost]
public async Task<IActionResult> Contact3(ContactModel model)
{
ViewData["Message"] = "Your contact page.";
return View(!ModelState.IsValid ? model : new ContactModel());
}
[HttpPost]
[ValidateRecaptcha(0.5)]
public IActionResult Contact4(ContactModel model)
{
ViewData["Message"] = "Your contact page.";
return View(!ModelState.IsValid ? model : new ContactModel());
}
public IActionResult Privacy()
{
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}