Browse Source

session; WIP auth

HOME 2 years ago
parent
commit
f1b7c5d9e0

+ 7 - 0
VCommonCoreExample/AppServices/Basic/DbAppServiceBase.cs

@@ -1,5 +1,7 @@
 using VCommon.Ioc;
 using VCommon.VApplication;
+using VCommon.VApplication.EntityFrameworkCore;
+using VCommon.VEntity;
 using VCommonCoreExample.Audit;
 using VCommonCoreExample.EntityFrameworkCore;
 
@@ -9,4 +11,9 @@ namespace VCommonCoreExample.AppServices.Basic
     {
         protected ExampleDbContext GetDbContext() => IocManager.Resolve<ExampleDbContext>();
     }
+
+    public class DbTableAppServiceBase<TEntity> : AppServiceBase where TEntity : VEntityBase
+    {
+        protected VAppEfRepository<ExampleDbContext, TEntity> GetRepository() => new();
+    }
 }

+ 8 - 0
VCommonCoreExample/AppServices/Session/SessionService.cs

@@ -12,10 +12,13 @@ namespace VCommonCoreExample.AppServices.Session
 
         [VServiceAuthorize]
         SessionOutput GetSession();
+
+        void Dummy();
     }
 
     public class SessionService : DbAppServiceBase, ISessionService
     {
+
         SessionOutput ISessionService.Login(SessionLoginInput input)
         {
             throw new System.NotImplementedException();
@@ -26,6 +29,11 @@ namespace VCommonCoreExample.AppServices.Session
             throw new System.NotImplementedException();
         }
 
+        void ISessionService.Dummy()
+        {
+            using var db = GetDbContext();
+        }
+
         void ISessionService.Logout()
         {
             throw new System.NotImplementedException();

+ 37 - 0
VCommonCoreExample/Authorization/PermissionManager.cs

@@ -0,0 +1,37 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using VCommon.Ioc;
+using VCommon.VApplication.Authorization;
+
+namespace VCommonCoreExample.Authorization
+{
+    public partial class PermissionManager : ISingletonIocClass, IPermissionManager
+    {
+        public bool ValidPermission(string permission)
+        {
+            throw new NotImplementedException();
+        }
+
+        public bool CheckPermission(Guid tenantId, Guid userId, params string[] hasAnyPermission)
+        {
+            throw new NotImplementedException();
+        }
+
+        public IReadOnlyCollection<PermissionNode> GetAllPermissionTree()
+        {
+            throw new NotImplementedException();
+        }
+
+        public IReadOnlyCollection<PermissionNodeOutput> GetPermissionTreeOutput()
+        {
+            throw new NotImplementedException();
+        }
+
+        public string[] GetUserPermissionCodes()
+        {
+            throw new NotImplementedException();
+        }
+    }
+}

+ 21 - 0
VCommonCoreExample/Caches/UserTokenStore.cs

@@ -0,0 +1,21 @@
+using System;
+using VCommon.Ioc;
+using VCommon.VOpenApi.VAspNetCore;
+
+namespace VCommonCoreExample.Caches
+{
+    public class UserTokenStore : IUserTokenStore, ISingletonIocClass
+    {
+        private const int NormalSessionExpireDays = 1;
+        private const int RememberMeSessionExpireDays = 7;
+
+
+        public void Validate(string token, out Guid? tenantId, out Guid? userId)
+        {
+            //TODO: Check user delete/disable/passChanged extend expire
+            
+            tenantId = null;
+            userId = null;
+        }
+    }
+}

+ 5 - 1
VCommonCoreExample/EntityFrameworkCore/ExampleDbContextFactory.cs

@@ -1,4 +1,5 @@
-using Microsoft.EntityFrameworkCore;
+using System.Diagnostics;
+using Microsoft.EntityFrameworkCore;
 using Microsoft.EntityFrameworkCore.Design;
 using Microsoft.Extensions.Configuration;
 using VCommonCoreExample.Configuration;
@@ -11,6 +12,9 @@ namespace VCommonCoreExample.EntityFrameworkCore
     {
         public ExampleDbContext CreateDbContext(string[] args)
         {
+            Debugger.Launch();
+            Debugger.Break();
+
             var builder = new DbContextOptionsBuilder<ExampleDbContext>();
 
             var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

+ 5 - 1
VCommonCoreExample/VCommonCoreExample.csproj

@@ -6,6 +6,10 @@
 
   <ItemGroup>
     <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.7" />
+    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.7">
+      <PrivateAssets>all</PrivateAssets>
+      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+    </PackageReference>
     <PackageReference Include="MySql.EntityFrameworkCore" Version="5.0.3.1" />
   </ItemGroup>
 
@@ -17,8 +21,8 @@
   </ItemGroup>
 
   <ItemGroup>
-    <Folder Include="Authorization\" />
     <Folder Include="Entity\" />
+    <Folder Include="Migrations\" />
   </ItemGroup>
 
 </Project>

+ 0 - 34
VCommonCoreExample/VSession.cs

@@ -1,34 +0,0 @@
-using System;
-using Microsoft.AspNetCore.Http;
-using VCommon.Ioc;
-using VCommon.VApplication;
-
-namespace VCommonCoreExample
-{
-    public class VSession : IVSession, ITransientIocClass
-    {
-        public VSession(HttpContext ctx)
-        {
-            //extract token
-            //and hold in context items?
-        }
-
-        public Guid GetTenantId()
-        {
-            throw new NotImplementedException();
-        }
-
-        public Guid GetUserId()
-        {
-            throw new NotImplementedException();
-        }
-
-        public string Token { get; set; }
-        public Guid? UserId { get; }
-        public Guid? TenantId { get; }
-        public void DemandAuth()
-        {
-            throw new NotImplementedException();
-        }
-    }
-}