Browse Source

Merge branch 'develop5.0-tmd' of http://106.12.23.251:10080/TEAMMODEL/TEAMModelOS into develop5.0-tmd

liqk 4 years ago
parent
commit
76dd3fb63f

+ 4 - 2
TEAMModelOS.SDK/Extension/JwtAuthExtension.cs

@@ -44,12 +44,14 @@ namespace TEAMModelOS.SDK.Extension
         }
         public static string CreateAppToken(string issuer, string id,  string salt, string schoolID = "", int expire = 1)
         {
+           
             // 設定要加入到 JWT Token 中的聲明資訊(Claims)  
             var payload = new JwtPayload {
                 { JwtRegisteredClaimNames.Iss, issuer }, //發行者
-                { JwtRegisteredClaimNames.Sub, id }, // 用戶ID                  
+                { JwtRegisteredClaimNames.Sub, id }, // APPID                  
                 { JwtRegisteredClaimNames.Azp,schoolID}, // 學校簡碼,如果有的話
-                { JwtRegisteredClaimNames.Exp,DateTimeOffset.UtcNow.AddHours(expire).ToUnixTimeSeconds().ToString()},  // 到期的時間,必須為數字
+                {"hash",Guid.NewGuid().ToString() }
+                //{ JwtRegisteredClaimNames.Exp,DateTimeOffset.UtcNow.AddHours(expire).ToUnixTimeSeconds().ToString()},  // 到期的時間,必須為數字
                 //{ "name",name}, // 用戶的顯示名稱
                 //{ "picture",picture}, // 用戶頭像
                 //{ "roles",roles}, // 登入者的角色,角色類型 (Admin、Teacher、Student) 

+ 6 - 1
TEAMModelOS.SDK/Models/Cosmos/Api/OpenApi.cs

@@ -26,7 +26,7 @@ namespace TEAMModelOS.SDK.Models
     {
         public OpenApi() {
 
-            PartitionKey = "OpenApi";
+            PartitionKey = "IES5-API";
         } 
         public string name { get; set; }
         public string url { get; set; }
@@ -36,11 +36,16 @@ namespace TEAMModelOS.SDK.Models
     }
 
     public class OpenApp : CosmosEntity {
+        public string icon { get; set; }
         public string name { get; set; }
         public string descr { get; set; }
         public List<string> apis { get; set; } = new List<string>();
         public string school { get; set; }
         public string token { get; set; }
+        /// <summary>
+        /// 0禁用,1正常,2 token封禁
+        /// </summary>
+        public int status { get; set; }
         public OpenApp()
         {
             pk = "OpenApp";

+ 1 - 0
TEAMModelOS/ClientApp/src/css/site.css

@@ -179,6 +179,7 @@ audio::-internal-media-controls-overflow-button {
 	color: #000;
 	display: flex;
 	align-items: center;
+	min-width: 240px;
 }
 
 .richText-audio .audio-name {

+ 14 - 18
TEAMModelOS/Controllers/Core/OpenApiController.cs

@@ -48,42 +48,37 @@ namespace TEAMModelOS.Controllers.Core
             return Ok(new { apis });
         }
         /// <summary>
-        /// {"code":"hbcn学校编码"} 
+        /// {"id":"uuid","code":"hbcn学校编码"} 
         /// </summary>
         /// <param name="requert"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [AuthToken(Roles = "admin")]
+        //[AuthToken(Roles = "admin")]
         [HttpPost("create-token")]
-        public async Task<IActionResult> CreateToken(OpenApp request) {
+        public async Task<IActionResult> CreateToken(JsonElement request) {
             try
             {
                 var client = _azureCosmos.GetCosmosClient();
-                request.pk = "OpenApp";
-                request.code = request.pk + "-" + request.code;
-                request.ttl = -1;
-                if (string.IsNullOrEmpty(request.id))
-                {
-                    return BadRequest();
-                }
-                else
-                {
-                    var response = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(request.id, new PartitionKey($"{request.code}"));
+                //id
+                if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
+                //
+                if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
+                
+                    var response = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(id.GetString(), new PartitionKey($"OpenApp-{code}")) ;
                     if (response.Status == 200)
                     {
-                        //创建Token
-                        var auth_token = JwtAuthExtension.CreateAppToken(_option.HostName, request.id,  _option.JwtSecretKey, request.school);
                         using var json = await JsonDocument.ParseAsync(response.ContentStream);
                         var info = json.ToObject<OpenApp>();
+                        //创建Token
+                        var auth_token = JwtAuthExtension.CreateAppToken(_option.HostName, info.id, _option.JwtSecretKey, info.school);
                         info.token = auth_token;
-                        request = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync(info, info.id, new PartitionKey($"{info.code}"));
+                        info = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync(info, info.id, new PartitionKey($"{info.code}"));
+                        return Ok(new { auth_token });
                     }
                     else
                     {
                         return BadRequest();
                     }
-                }
-                return Ok(new { app = request });
             }
             catch (Exception e)
             {
@@ -150,6 +145,7 @@ namespace TEAMModelOS.Controllers.Core
                     {
                         using var json = await JsonDocument.ParseAsync(response.ContentStream);
                         var info = json.ToObject<OpenApp>();
+                        request.token = info.token;
                         request = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync(request, info.id, new PartitionKey($"{info.code}"));
                     }
                     else

+ 1 - 0
TEAMModelOS/Controllers/School/SchoolController.cs

@@ -304,6 +304,7 @@ namespace TEAMModelOS.Controllers
                         if (serialDeviceBoundRow.deviceId != deviceRow.device_id)
                         {
                             deviceBoundRich deviceBoundUpdRow = new deviceBoundRich();
+                            deviceBoundUpdRow.serial = deviceRow.sn;
                             deviceBoundUpdRow.uuid = deviceBoundRow.uuid1;
                             deviceBoundUpdRow.uuid2 = deviceBoundRow.uuid2;
                             deviceBoundUpdRow.classId = deviceBoundRow.class_id;

+ 1 - 1
TEAMModelOS/appsettings.Development.json

@@ -45,7 +45,7 @@
       "userinfo": "https://api2.teammodel.cn/Oauth2/GetUserInfos"
     },
     "CoreService": {
-      "deviceinfo": "https://api2.teammodel.net/oauth2/getdeviceinfos"
+      "deviceinfo": "https://api2.teammodel.cn/oauth2/getdeviceinfos"
     }
   }
 }