CrazyIter_Bin 3 mēneši atpakaļ
vecāks
revīzija
c4c420a25b

+ 22 - 1
TEAMModelOS.Extension/IES.Exam/IES.ExamServer/Controllers/BaseController.cs

@@ -1,4 +1,7 @@
-using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.DataProtection.KeyManagement;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Primitives;
 
 namespace IES.ExamServer.Controllers
 {
@@ -78,6 +81,24 @@ namespace IES.ExamServer.Controllers
             return HttpContext.Request.Headers["Authorization"].ToString();
         }
 
+        /// <summary>
+        /// 取得驗證金鑰,Authorization
+        /// </summary>        
+        public string? GetXAuthToken()
+        {
+            //return HttpContext.Request.Headers["X-Auth-AuthToken"].ToString();
+            try
+            {
+                if (HttpContext.Request.Headers.TryGetValue("X-Auth-AuthToken", out StringValues value))
+                    return value.ToString();
+                else
+                    return null;
+            }
+            catch
+            {
+                return null;
+            }
+        }
         /// <summary>
         /// 取得JWT驗證金鑰,Authorization Bearer
         /// </summary>

+ 7 - 4
TEAMModelOS.Extension/IES.Exam/IES.ExamServer/Controllers/ManageController.cs

@@ -108,8 +108,8 @@ namespace IES.ExamServer.Controllers
                     EvaluationClient? evaluationClient = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>().FindOne(x => x.id!.Equals(id) && x.shortCode!.Equals(shortCode));
                     if (teacher != null && evaluationClient!= null)
                     {
-                        var dataInfo=  await GetEvaluationFromCenter(teacher, _configuration, _httpClientFactory, shortCode, evaluationClient.id!);
-                        if (dataInfo.centerCode.Equals("200"))
+                        var dataInfo=  await GetEvaluationFromCenter(GetXAuthToken(), _configuration, _httpClientFactory, shortCode, evaluationClient.id!);
+                        if (dataInfo.centerCode.Equals("200")&& dataInfo.evaluationCloud!=null)
                         {
                             string? CenterUrl = _configuration.GetValue<string>("ExamServer:CenterUrl");
                             var client = _httpClientFactory.CreateClient();
@@ -255,7 +255,9 @@ namespace IES.ExamServer.Controllers
                                 }
                             }
 
-                            (successMsgs, errorMsgs) = await ManageService.CheckFile(evaluationClient, successMsgs, errorMsgs, _signalRExamServerHub, _memoryCache, _logger, deviceId, evaluationPath);
+                            _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>().Upsert(dataInfo.evaluationCloud!);
+
+                            (successMsgs, errorMsgs) = await ManageService.CheckFile(dataInfo.evaluationCloud!, successMsgs, errorMsgs, _signalRExamServerHub, _memoryCache, _logger, deviceId, evaluationPath);
                             //下载完成后,对数据进行检查,然后在加密压缩。
                             string zipPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "zip");
                             if (!Directory.Exists(zipPath))
@@ -264,6 +266,7 @@ namespace IES.ExamServer.Controllers
                             }
                             string zipFilePath = Path.Combine(zipPath, $"{evaluationClient.id}-{evaluationClient.blobHash}.zip");
                             var zipInfo = ZipHelper.CreatePasswordProtectedZip(evaluationPath, zipFilePath, evaluationClient.openCode!);
+                          
                             if (zipInfo.res)
                             {
                                 successMsgs.Add("评测数据压缩包创建成功!");
@@ -451,7 +454,7 @@ namespace IES.ExamServer.Controllers
                         Teacher? teacher = _liteDBFactory.GetLiteDatabase().GetCollection<Teacher>().FindOne(x => x.id!.Equals(token.id));
                         if (teacher != null)
                         {
-                          (evaluationCloud, centerCode, centerMsg)=  await ManageService.GetEvaluationFromCenter(teacher, _configuration,_httpClientFactory,shortCode,evaluationId);
+                          (evaluationCloud, centerCode, centerMsg)=  await ManageService.GetEvaluationFromCenter(GetXAuthToken(), _configuration,_httpClientFactory,shortCode,evaluationId);
                         }
                         else
                         {

+ 1 - 1
TEAMModelOS.Extension/IES.Exam/IES.ExamServer/Helpers/JwtAuthExtension.cs

@@ -46,7 +46,7 @@ namespace IES.ExamServer
                 { "roles",roles}, // 登入者的角色,角色類型 (Admin、Teacher、Student) 
                 { "scope",scope},  //登入者的入口类型。 (teacher 教师端登录的醍摩豆ID、tmduser学生端登录的醍摩豆ID、student学生端登录校内账号的学生ID)
                 { "timezone",timezone},
-               
+                { JwtRegisteredClaimNames.Jti,Guid.NewGuid().ToString()}
             };
             // 建立一組對稱式加密的金鑰,主要用於 JWT 簽章之用
             var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(salt));

+ 2 - 2
TEAMModelOS.Extension/IES.Exam/IES.ExamServer/Services/ManageService.cs

@@ -15,7 +15,7 @@ namespace IES.ExamServer.Services
     public class ManageService
     {
 
-        public async static Task<(EvaluationClient? evaluationCloud, string centerCode, string centerMsg)> GetEvaluationFromCenter(Teacher teacher,IConfiguration _configuration,IHttpClientFactory _httpClientFactory, string shortCode, string evaluationId)
+        public async static Task<(EvaluationClient? evaluationCloud, string centerCode, string centerMsg)> GetEvaluationFromCenter(string? x_auth_token, IConfiguration _configuration,IHttpClientFactory _httpClientFactory, string shortCode, string evaluationId)
         {
             EvaluationClient? evaluationCloud = null;
             string centerCode = string.Empty, centerMsg = string.Empty;
@@ -25,7 +25,7 @@ namespace IES.ExamServer.Services
             {
                 client.DefaultRequestHeaders.Remove(Constant._X_Auth_AuthToken);
             }
-            client.DefaultRequestHeaders.Add(Constant._X_Auth_AuthToken, teacher!.x_auth_token);
+            client.DefaultRequestHeaders.Add(Constant._X_Auth_AuthToken, x_auth_token);
             try
             {
                 HttpResponseMessage message = await client.PostAsJsonAsync($"{CenterUrl}/evaluation-sync/find-sync-info", new { shortCode, evaluationId });