Skip to content

Instantly share code, notes, and snippets.

View MoienTajik's full-sized avatar
😎

Moien Tajik MoienTajik

😎
View GitHub Profile
@MoienTajik
MoienTajik / IClock.cs
Last active March 18, 2021 09:18
IClock abstracts DateTime & DateTimeOffset so you can easily mock time and unit-test.
public interface IClock
{
DateTimeOffset UtcNow { get; }
}
public static class Clock
{
private static IClock _instance = new SystemClock();
public static IClock Instance
@MoienTajik
MoienTajik / ConstraintsList.md
Last active May 31, 2019 15:42
ASP.NET Core default Route Constraints list

ASP.NET Core default Route Constraints list

Constraints for Checking Data Type

The following Constrains checks the data type :

Constraint Inline Class Description
int {id:int} IntRouteConstraint Constrains a route parameter to represent only 32-bit integer values
alpha {id:alpha} AlphaRouteConstraint Constrains a route parameter to contain only lowercase or uppercase letters A through Z in the English alphabet.
bool {id:bool} BoolRouteConstraint Constrains a route parameter to represent only Boolean values.
@MoienTajik
MoienTajik / ISO-639-1-language.json
Created August 19, 2018 12:48
ISO-639-1-language codes
[
{
"code": "ab",
"name": "Abkhaz"
},
{
"code": "aa",
"name": "Afar"
},
{

Keybase proof

I hereby claim:

  • I am MoienTajik on github.
  • I am moientajik (https://keybase.io/moientajik) on keybase.
  • I have a public key whose fingerprint is 2DD5 FC89 6B33 D440 B3AD E5DA 5E0E C9D1 C341 C464

To claim this, I am signing this object:

@MoienTajik
MoienTajik / Create.cshtml
Created February 17, 2018 13:03
Using Google reCAPTCHA in ASP.NET MVC - Create View
@using GoogleRecaptcha.Infrastructure.HtmlHelpers
@{
ViewBag.Title = "Create";
}
<h2>@ViewBag.Title</h2>
<h4>Some test form that needs reCAPTCHA !</h4>
<hr />
@MoienTajik
MoienTajik / TestController.cs
Created February 17, 2018 13:01
Using Google reCAPTCHA in ASP.NET MVC - Test Controller
public class TestController : Controller
{
[HttpGet]
public ActionResult Create()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
@MoienTajik
MoienTajik / ValidateGoogleCaptchaAttribute.cs
Created February 17, 2018 12:48
Using Google reCAPTCHA in ASP.NET MVC - Validate reCAPTCHA Attribute
public class ValidateGoogleCaptchaAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
const string urlToPost = "https://www.google.com/recaptcha/api/siteverify";
const string secretKey = SiteSettings.GoogleRecaptchaSecretKey;
var captchaResponse = filterContext.HttpContext.Request.Form["g-recaptcha-response"];
if (string.IsNullOrWhiteSpace(captchaResponse)) AddErrorAndRedirectToGetAction(filterContext);
@MoienTajik
MoienTajik / InvalidGoogleCaptchaLabel.cs
Created February 17, 2018 12:38
Using Google reCAPTCHA in ASP.NET MVC - Invalid reCAPTCHA Label
public static class InvalidGoogleCaptchaHelper
{
public static IHtmlString InvalidGoogleCaptchaLabel(this HtmlHelper helper, string errorText)
{
var invalidCaptchaObj = helper.ViewContext.Controller.TempData["InvalidCaptcha"];
var invalidCaptcha = invalidCaptchaObj?.ToString();
if (string.IsNullOrWhiteSpace(invalidCaptcha)) return MvcHtmlString.Create("");
var buttonTag = new TagBuilder("span")
@MoienTajik
MoienTajik / GoogleCaptchaHelper.cs
Last active February 17, 2018 12:32
Using Google reCAPTCHA in ASP.NET MVC - reCAPTCHA Generator
public static class GoogleCaptchaHelper
{
public static IHtmlString GoogleCaptcha(this HtmlHelper helper)
{
const string publicSiteKey = SiteSettings.GoogleRecaptchaSiteKey;
var mvcHtmlString = new TagBuilder("div")
{
Attributes =
{
@MoienTajik
MoienTajik / SiteSettings.cs
Last active February 17, 2018 10:12
Using Google reCAPTCHA in ASP.NET MVC - Site Settings
public static class SiteSettings
{
public const string GoogleRecaptchaSecretKey = "6Lea1EYUAAAAACn3pDs7EL8msJh0h0KgH-ajakZ_";
public const string GoogleRecaptchaSiteKey = "6Lea1EYUAAAAAHvvT5xIFXt1UknyKUf1C1w5Ko77";
}