From 0725e4f7cf4c6f723264b6d461b91c660d144cb7 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Sun, 30 Oct 2022 22:40:03 +0700 Subject: feat: Apiwork --- code/api/src/Utilities/BasicAuthenticationHandler.cs | 4 ++-- code/api/src/Utilities/DateTimeExtensions.cs | 8 ++++++++ code/api/src/Utilities/QueryableExtensions.cs | 12 ++++++++++++ code/api/src/Utilities/Validators.cs | 12 ++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 code/api/src/Utilities/DateTimeExtensions.cs create mode 100644 code/api/src/Utilities/QueryableExtensions.cs create mode 100644 code/api/src/Utilities/Validators.cs (limited to 'code/api/src/Utilities') diff --git a/code/api/src/Utilities/BasicAuthenticationHandler.cs b/code/api/src/Utilities/BasicAuthenticationHandler.cs index 6138193..b0a2d1a 100644 --- a/code/api/src/Utilities/BasicAuthenticationHandler.cs +++ b/code/api/src/Utilities/BasicAuthenticationHandler.cs @@ -7,7 +7,7 @@ namespace IOL.GreatOffice.Api.Utilities; public class BasicAuthenticationHandler : AuthenticationHandler { - private readonly AppDbContext _context; + private readonly MainAppDatabase _context; private readonly AppConfiguration _configuration; private readonly ILogger _logger; @@ -16,7 +16,7 @@ public class BasicAuthenticationHandler : AuthenticationHandler ForTenant(this IQueryable queryable, LoggedInUserModel loggedInUserModel) where T : BaseWithOwner { + return queryable.Where(c => c.TenantId == loggedInUserModel.TenantId); + } + + public static IQueryable ForUser(this IQueryable queryable, LoggedInUserModel loggedInUserModel) where T : BaseWithOwner { + return queryable.Where(c => c.UserId == loggedInUserModel.Id); + } +} \ No newline at end of file diff --git a/code/api/src/Utilities/Validators.cs b/code/api/src/Utilities/Validators.cs new file mode 100644 index 0000000..fa3a144 --- /dev/null +++ b/code/api/src/Utilities/Validators.cs @@ -0,0 +1,12 @@ +using System.Text.RegularExpressions; + +namespace IOL.GreatOffice.Api.Utilities; + +public static class Validators +{ + private static readonly Regex EMAIL_REGEX = new(""); + + public static bool IsValidEmail(this string email) { + return EMAIL_REGEX.IsMatch(email); + } +} \ No newline at end of file -- cgit v1.3