Explorar el Código

提交登录验证

黄贺彬 hace 6 años
padre
commit
5e7916a924

+ 3 - 1
TEAMModelOS.Model/Common/Dtos/TeamModelIdInfo.cs

@@ -1,4 +1,5 @@
-using System;
+using MessagePack;
+using System;
 using System.Collections.Generic;
 using System.Text;
 
@@ -7,6 +8,7 @@ namespace TEAMModelOS.Model.Common.Dtos
     /// <summary>
     /// 对接醍摩豆ID封装信息
     /// </summary>
+    [MessagePackObject(keyAsPropertyName: true)]
     public class TeamModelIdInfo
     {
         public string name { get; set; }

+ 24 - 0
TEAMModelOS.Model/Syllabus/Models/TeacherTextbook.cs

@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using TEAMModelOS.SDK.Context.Attributes.Table;
+
+namespace TEAMModelOS.Model.Syllabus.Models
+{
+    [TableSpaceAttribute(Name = "Syllabus")]
+    public class TeacherTextbook : StandardTextbook
+    {
+        /// <summary>
+        /// 醍摩豆ID
+        /// </summary>
+        public string TeamModelId { get; set; }
+        /// <summary>
+        ///标准教材RowKey
+        /// </summary>
+        public string StandardRowKey { get; set; }
+        /// <summary>
+        ///添加时间
+        /// </summary>
+        public DateTimeOffset AddTime { get; set; }
+    }
+}

+ 3 - 1
TEAMModelOS.SDK/Extension/DataResult/JsonRpcRequest/JosnRPCRequest.cs

@@ -1,9 +1,11 @@
-using System;
+using MessagePack;
+using System;
 using System.Collections.Generic;
 using System.Text;
 
 namespace TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest
 {
+    [MessagePackObject(keyAsPropertyName: true)]
     public class JosnRPCRequest<T>:BaseJosnRPCRequest
     {
         public T @params { get; set; }

+ 43 - 0
TEAMModelOS.SDK/Helper/Common/CollectionHelper/CollectionHelper.cs

@@ -0,0 +1,43 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+using System.Text;
+
+namespace TEAMModelOS.SDK.Helper.Common.CollectionHelper
+{
+    public static class CollectionHelper
+    {
+        /// <summary>
+        /// 判断集合是否为空
+        /// </summary>
+        /// <param name="collection"></param>
+        /// <returns></returns>
+        public static bool IsEmpty(this ICollection collection)
+        {
+            if (collection != null && collection.Count > 0)
+            {
+                return false;
+            }
+            else {
+                return true;
+            }
+        }
+        /// <summary>
+        /// 判断集合是否不为空
+        /// </summary>
+        /// <param name="collection"></param>
+        /// <returns></returns>
+        public static bool IsNotEmpty(this ICollection collection)
+        {
+            if (collection != null && collection.Count > 0)
+            {
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+    }
+}

+ 0 - 10
TEAMModelOS.SDK/Helper/Common/CollectionHeper/CollectionHeper.cs

@@ -1,10 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace TEAMModelOS.SDK.Helper.Common.CollectionHeper
-{
-    public class CollectionHeper
-    {
-    }
-}

+ 26 - 0
TEAMModelOS.SDK/Helper/Network/HttpHelper/HttpContextHelper.cs

@@ -1,7 +1,12 @@
 using Microsoft.AspNetCore.Http;
 using Microsoft.Extensions.Primitives;
 using System;
+using System.Collections.Generic;
 using System.Linq;
+using System.Security.Claims;
+using TEAMModelOS.SDK.Context.Constant.Common;
+using TEAMModelOS.SDK.Extension.JwtAuth.JwtHelper;
+using TEAMModelOS.SDK.Extension.JwtAuth.Models;
 
 namespace TEAMModelOS.SDK.Helper.Network.HttpHelper
 {
@@ -92,5 +97,26 @@ namespace TEAMModelOS.SDK.Helper.Network.HttpHelper
             }
             return aktoken;
         }
+        public static string GetLoginUser(IHttpContextAccessor httpContextAccessor) {
+
+            var tokenHeader = "";
+
+            HttpRequest request = httpContextAccessor.HttpContext.Request;
+            if (request.Query.ContainsKey(Constants.ACCESS_TOKEN))
+            {
+                tokenHeader = request.Query[Constants.ACCESS_TOKEN];
+                tokenHeader = tokenHeader.ToString().Trim();
+            }
+            if (request.Headers.ContainsKey(Constants.AUTHORIZATION))
+            {
+                tokenHeader = request.Headers[Constants.AUTHORIZATION];
+                tokenHeader = tokenHeader.ToString().Substring("Bearer ".Length).Trim();
+            }
+            ClaimModel claimModel = JwtHelper.SerializeJWT(tokenHeader);
+
+            List<Claim> claims = claimModel.Claims; 
+            //foreach()
+            return null; 
+        }
     }
 }

+ 16 - 8
TEAMModelOS.Service/Syllabus/Implements/SyllabusService.cs

@@ -1,10 +1,12 @@
-using System;
+using Microsoft.AspNetCore.Http;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 using TEAMModelOS.Model.Syllabus.Dtos;
 using TEAMModelOS.Model.Syllabus.Models;
 using TEAMModelOS.SDK.Context.Exception;
+using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.Helper.Common.JsonHelper;
 using TEAMModelOS.SDK.Module.AzureTable.Interfaces;
 using TEAMModelOS.Service.Syllabus.Interfaces;
@@ -14,9 +16,11 @@ namespace TEAMModelOS.Service.Syllabus.Implements
     public class SyllabusService : ISyllabusService
     {
 
-        IAzureTableDBRepository _azureTableDBRepository;
-        public SyllabusService(IAzureTableDBRepository azureTableDBRepository) {
+        private IAzureTableDBRepository _azureTableDBRepository;
+        private IHttpContextAccessor _httpContextAccessor;
+        public SyllabusService(IAzureTableDBRepository azureTableDBRepository , IHttpContextAccessor httpContextAccessor) {
             _azureTableDBRepository = azureTableDBRepository;
+            _httpContextAccessor = httpContextAccessor;
         }
 
 
@@ -122,6 +126,9 @@ namespace TEAMModelOS.Service.Syllabus.Implements
         /// <param name="params"></param>
         /// <returns></returns>
         public async Task<StandardTextbook> FindTextbooksByDict(Dictionary<string, object> dict) {
+
+           
+
             Dictionary<string, object> parDict = new Dictionary<string, object>
             {
                 { "Period", dict["Period"] },
@@ -146,12 +153,13 @@ namespace TEAMModelOS.Service.Syllabus.Implements
             else
             {
                 // 校验 几个Code 是否存在
+                string RowKey = "RowKey";
                 StandardTextbook textbook = dict.DictToObj<StandardTextbook>();
-                List<Period> periods= await FindPeriodsByDict(new Dictionary<string, object> { { "RowKey", textbook.Period} });
-                List<PeriodSubject> subjects = await FindSubjectsByDict(new Dictionary<string, object> { { "RowKey", textbook.Subject } });
-                List<PeriodSubjectEdition> editions = await FindEditionsByDict(new Dictionary<string, object> { { "RowKey", textbook.Edition } });
-                List<PeriodSubjectEditionTerm> terms = await FindTermsByDict(new Dictionary<string, object> { { "RowKey", textbook.Term } });
-                if (periods != null && subjects != null && editions != null && terms != null && periods.Count > 0 && subjects.Count > 0 && editions.Count > 0 && terms.Count > 0)
+                List<Period> periods= await FindPeriodsByDict(new Dictionary<string, object> { { RowKey, textbook.Period} });
+                List<PeriodSubject> subjects = await FindSubjectsByDict(new Dictionary<string, object> { { RowKey, textbook.Subject } });
+                List<PeriodSubjectEdition> editions = await FindEditionsByDict(new Dictionary<string, object> { { RowKey, textbook.Edition } });
+                List<PeriodSubjectEditionTerm> terms = await FindTermsByDict(new Dictionary<string, object> { { RowKey, textbook.Term } });
+                if (periods.IsNotEmpty()&& subjects.IsNotEmpty()&& editions.IsNotEmpty()&& terms.IsNotEmpty())
                 {
                     textbook.RowKey = Guid.NewGuid().ToString();
                     textbook.PartitionKey = Guid.NewGuid().ToString();

+ 17 - 1
TEAMModelOS/Controllers/Common/LoginController.cs

@@ -11,6 +11,7 @@ using System.Security.Claims;
 using System.Text;
 using System.Threading.Tasks;
 using TEAMModelOS.Model.Common.Dtos;
+using TEAMModelOS.SDK.Context.Configuration;
 using TEAMModelOS.SDK.Context.Constant.Common;
 using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
 using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
@@ -37,7 +38,7 @@ namespace TEAMModelOS.Controllers.Common
 		/// </summary>
 		/// <param name="test"></param>
 		/// <returns></returns>
-		[HttpPost("Login")]
+		[HttpPost("CheckLogin")]
         [AllowAnonymous]
         public async Task<BaseJosnRPCResponse> CheckLogin(JosnRPCRequest<TicketInfo> request)
         {
@@ -60,6 +61,21 @@ namespace TEAMModelOS.Controllers.Common
             }
             return responseBuilder.build();
         }
+        /// <summary>
+		/// 登录验证
+		/// </summary>
+		/// <param name="test"></param>
+		/// <returns></returns>
+		[HttpPost("Login")]
+        [AllowAnonymous]
+        public async Task<BaseJosnRPCResponse> Login(JosnRPCRequest<Dictionary<string,object>> request)
+        {
+            JsonRPCResponseBuilder responseBuilder = JsonRPCResponseBuilder.custom();
+            responseBuilder.Data(BaseConfigModel.Configuration["HaBookAuth:TeamModelLoginUrl"]);
+            return await Task.Factory.StartNew(() => { return responseBuilder.build(); });
+        }
+
+        
 
         /// <summary>
         /// 授权

+ 1 - 9
TEAMModelOS/Controllers/Syllabus/SyllabusController.cs

@@ -69,19 +69,11 @@ namespace TEAMModelOS.Controllers.Syllabus
         }
 
         [HttpPost("FindTextbooks")]
-        public async Task<BaseJosnRPCResponse> FindTextbooks(JosnRPCRequest<Dictionary<string, object>> request)
+        public async Task<BaseJosnRPCResponse> FindTextbooksByDict(JosnRPCRequest<Dictionary<string, object>> request)
         {
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
             StandardTextbook data = await syllabusService.FindTextbooksByDict(request.@params);
             return builder.Data(data).build();
         }
-
-        [HttpGet("RSA")]
-        public  BaseJosnRPCResponse RSA()
-        {
-            JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
-          //  var data = RsaHelper.GenerateAndSaveKey("E://");
-            return builder.Data(null).build();
-        }
     }
 }

+ 1 - 1
TEAMModelOS/Controllers/ValuesController.cs

@@ -19,7 +19,7 @@ namespace TEAMModelOS.Controllers
         public ActionResult<IEnumerable<string>> Get()
         {
 
-            GetTableSpace<Textbook>();
+           // GetTableSpace<Textbook>();
             return new string[] { "value1", "value2" };
         }
 

+ 1 - 0
TEAMModelOS/appsettings.Development.json

@@ -25,6 +25,7 @@
     }
   },
   "HaBookAuth": {
+    "TeamModelLoginUrl": "https://account.habookaclass.biz/?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJsb2dpbiIsImF1ZCI6ImNoZW5nZHVMb2dpbiIsImlzcyI6Imh0dHBzOi8vYXBpLmhhYm9va2FjbGFzcy5iaXoiLCJpYXQiOjE1MzYxMzUwNDcsIm5iZiI6MTUzNjEzNTA0NywiZXhwIjoxNTY3NTU1MjAwLCJpZHAiOiJIYWJvb2sgQ29yZVNlcnZpY2UifQ.F4AnkbJrMRoZvJ6SC-lqZEYIYSoq5x8lvX6_a3YqSgM&callback=",
     "AccountUrl": "https://api.habookaclass.biz/account",
     "ServiceUrl": "https://api.habookaclass.biz/service",
     "UserInfoKey": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJpZCIsImF1ZCI6ImNoZW5nZHVJZCIsImlzcyI6Imh0dHBzOi8vYXBpLmhhYm9va2FjbGFzcy5iaXoiLCJpYXQiOjE1MzYwNTIzNjcsIm5iZiI6MTUzNjA1MjM2NywiZXhwIjoxNTY3NTU1MjAwLCJpZHAiOiJIYWJvb2sgQ29yZVNlcnZpY2UifQ.RGKDVtwFEp4OBctlHOuF6yqyI21fTz4cinCxjFCxkSQ",