CrazyIter_Bin 4 kuukautta sitten
vanhempi
commit
3ca0936517

+ 13 - 5
TEAMModelOS.Extension/IES.Exam/IES.ExamServer/Controllers/IndexController.cs

@@ -149,15 +149,21 @@ namespace IES.ExamServer.Controllers
                     List<School>? schools = null;
                     JsonNode? jsonNode = null;
                     long time = DateTimeOffset.Now.ToUnixTimeMilliseconds();
+                    _memoryCache.TryGetValue(Constant._KeyServerDevice, out ServerDevice? server);
+                    School? school = null;
+                    if (server!=null) 
+                    {
+                    school = server.school;
+                    }
                     switch (true)
                     {
                         //跳过忽略,但是仍然要以访客身份登录
                         case bool when $"{type}".Equals(ExamConstant.ScopeVisitor):
                             {
                                 string id = $"{DateTimeOffset.Now.ToUnixTimeSeconds()}";
-                                string name = $"访客教师-{Random.Shared.Next(100, 999)}";
-                                x_auth_token = JwtAuthExtension.CreateAuthToken("www.teammodel.cn",id ,name,null
-                                    ,ExamConstant.JwtSecretKey,ExamConstant.ScopeVisitor,8,null,new string[] { "visitor" }, expire: 1);
+                                string name = $"{school?.name}教师-{Random.Shared.Next(100, 999)}";
+                                x_auth_token = JwtAuthExtension.CreateAuthToken("www.teammodel.cn",id ,name,picture: school?.picture
+                                    , ExamConstant.JwtSecretKey,ExamConstant.ScopeVisitor,8,schoolID:school?.id,new string[] { "visitor" }, expire: 1);
                                 //  _memoryCache.Set($"Teacher:{id}", new Teacher { id = id, name = $"{name}", implicit_token = token, picture = null, schools = schools, x_auth_token = x_auth_token });
                                 _liteDBFactory.GetLiteDatabase().GetCollection<Teacher>().Upsert(new Teacher { id = id, name = $"{name}", implicit_token = token, picture = null, schools = schools, x_auth_token = x_auth_token,loginTime=time });
                                 return Ok(new { code = 200,x_auth_token = x_auth_token });
@@ -167,7 +173,7 @@ namespace IES.ExamServer.Controllers
                                 string randomCode = $"{json["randomCode"]}";
                                 System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
 
-                                var response = await _httpClientFactory.CreateClient().GetAsync($"{CenterUrl}/hita/check-login?code={randomCode}");
+                                var response = await _httpClientFactory.CreateClient().GetAsync($"{CenterUrl}/hita/check-login?code={randomCode}&school={school?.id}");
                                 if (response.IsSuccessStatusCode)
                                 {
                                     string content = await response.Content.ReadAsStringAsync();
@@ -192,7 +198,7 @@ namespace IES.ExamServer.Controllers
                             {
                                 string pin_code = $"{json["pin_code"]}";
                                 string account = $"{json["account"]}";
-                                var response = await _httpClientFactory.CreateClient().PostAsJsonAsync($"{CenterUrl}/core/sendsms/check", new { pin_code, account });
+                                var response = await _httpClientFactory.CreateClient().PostAsJsonAsync($"{CenterUrl}/core/sendsms/check", new { pin_code, account,school=school?.id });
                                 if (response.IsSuccessStatusCode)
                                 {
                                     string content = await response.Content.ReadAsStringAsync();
@@ -272,6 +278,7 @@ namespace IES.ExamServer.Controllers
                         Random random = new Random();
                         randomCode = $"{random.Next(1000, 9999)}";
                         string? CenterUrl = _configuration.GetValue<string>("ExamServer:CenterUrl");
+                        CenterUrl= CenterUrl.Equals("https://localhost:5001") ? "https://www.teammodel.cn":CenterUrl;
                         string content = $"{CenterUrl}/joinSchool?schoolCode=login:{randomCode}&m=%E7%99%BB%E5%BD%95&o=1";
                         var  str= QRCodeHelper.GenerateQRCode(content, 300, 300,QRCodeHelper.logo);
                         qrcode = $"data:image/png;base64,{str}";
@@ -283,6 +290,7 @@ namespace IES.ExamServer.Controllers
                         Random random = new Random();
                         randomCode = $"{random.Next(1000, 9999)}";
                         string? CenterUrl = _configuration.GetValue<string>("ExamServer:CenterUrl");
+                        CenterUrl= CenterUrl.Equals("https://localhost:5001") ? "https://www.teammodel.cn" : CenterUrl;
                         string content = $"{CenterUrl}/joinSchool?schoolCode=login:{randomCode}&m=%E7%99%BB%E5%BD%95&o=1";
                         Bitmap qrCodeImage = QRCodeHelper.GetBitmap(content, 200, 200);
                         using (MemoryStream stream = new MemoryStream())

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

@@ -33,7 +33,7 @@ namespace IES.ExamServer
         }
 
 
-        public static string CreateAuthToken(string issuer, string id, string name, string picture, string salt, string scope,   int timezone,   string? schoolID =null,string[]? roles = null,   int expire = 1, int year = -1)
+        public static string CreateAuthToken(string? issuer, string? id, string? name, string? picture, string? salt, string? scope,   int timezone,   string? schoolID =null,string[]? roles = null,   int expire = 1, int year = -1)
         {
             // 設定要加入到 JWT Token 中的聲明資訊(Claims)  
             var payload = new JwtPayload {