CrazyIter_Bin 1 year ago
parent
commit
12290b34b4
1 changed files with 20 additions and 16 deletions
  1. 20 16
      TEAMModelOS/Controllers/Common/ActivityController.cs

+ 20 - 16
TEAMModelOS/Controllers/Common/ActivityController.cs

@@ -1393,26 +1393,30 @@ namespace TEAMModelOS.Controllers
                     
                     
                      }
                      }
             }
             }
-            if (tmdid == null  && !string.IsNullOrWhiteSpace($"{_token}"))
+            
+            if (tmdid == null   )
             {
             {
-                var jwt = new JwtSecurityToken(_token.GetString());
-                if (JwtAuthExtension.ValidateAuthTokenRefresh(_token.GetString(), _option.JwtSecretKey))
+                if (!string.IsNullOrWhiteSpace($"{_token}"))
                 {
                 {
-                    tmdid = jwt.Payload.Sub;
-
-                    if (HttpContext.Request.Headers.TryGetValue("lang", out var _lang))
+                    var jwt = new JwtSecurityToken(_token.GetString());
+                    if (JwtAuthExtension.ValidateAuthTokenRefresh(_token.GetString(), _option.JwtSecretKey))
                     {
                     {
-                        head_lang = $"{_lang}";
+                        tmdid = jwt.Payload.Sub;
+
+                        if (HttpContext.Request.Headers.TryGetValue("lang", out var _lang))
+                        {
+                            head_lang = $"{_lang}";
+                        }
+                        jwt.Payload.TryGetValue("name", out name);
+                        jwt.Payload.TryGetValue("picture", out picture);
+                        jwt.Payload.TryGetValue("lang", out object _jwtlang);
+                        head_lang = !string.IsNullOrWhiteSpace($"{_jwtlang}") ? $"{_jwtlang}" : head_lang;
                     }
                     }
-                    jwt.Payload.TryGetValue("name", out name);
-                    jwt.Payload.TryGetValue("picture", out picture);
-                    jwt.Payload.TryGetValue("lang", out object _jwtlang);
-                    head_lang = !string.IsNullOrWhiteSpace($"{_jwtlang}") ? $"{_jwtlang}" : head_lang;
+                    else { return Ok(new { code = 2, msg = "Token验证失败" }); }
                 }
                 }
-                else { return Ok(new { code = 2, msg = "Token验证失败" }); }
-
+                else { return Ok(new { code = 3, msg = "凭证验证失败" }); }
             }
             }
-            else { return Ok(new { code = 3, msg = "凭证验证失败" }); }
+           
             teacherInfo = await TeacherService.TeacherInfoLite(_azureCosmos,  $"{name}", $"{picture}", tmdid, _azureStorage, _option, _azureRedis, ip, _httpTrigger, head_lang);
             teacherInfo = await TeacherService.TeacherInfoLite(_azureCosmos,  $"{name}", $"{picture}", tmdid, _azureStorage, _option, _azureRedis, ip, _httpTrigger, head_lang);
             string sql = $"select value c from c where c.route='{_route}'";
             string sql = $"select value c from c where c.route='{_route}'";
             var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).GetList<ActivityWebsite>(sql, "ActivityWebsite");
             var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).GetList<ActivityWebsite>(sql, "ActivityWebsite");
@@ -1448,8 +1452,8 @@ namespace TEAMModelOS.Controllers
                 { JwtRegisteredClaimNames.Exp,DateTimeOffset.UtcNow.AddHours(2).ToUnixTimeSeconds()},  // 到期的時間,必須為數字
                 { JwtRegisteredClaimNames.Exp,DateTimeOffset.UtcNow.AddHours(2).ToUnixTimeSeconds()},  // 到期的時間,必須為數字
                 { "name",name}, // 用戶的顯示名稱
                 { "name",name}, // 用戶的顯示名稱
                 { "picture",picture}, // 用戶頭像
                 { "picture",picture}, // 用戶頭像
-                { "roles", roles}, // 登入者的角色,角色類型 (Admin、Teacher、Student) 
-                { JwtRegisteredClaimNames.Website,website.route},
+                { "roles", roles.ToArray()}, // 登入者的角色,角色類型 (Admin、Teacher、Student) 
+                { JwtRegisteredClaimNames.Website,website?.route},
             };
             };
             var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_option.JwtSecretKey));
             var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_option.JwtSecretKey));
             var signingCredentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256Signature);
             var signingCredentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256Signature);