|
@@ -77,7 +77,7 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
try {
|
|
|
if (!request.TryGetProperty("sid", out JsonElement sid)) return BadRequest();
|
|
|
if (!request.TryGetProperty("id_token", out JsonElement id_token)) return BadRequest();
|
|
|
- if (!request.TryGetProperty("dev", out JsonElement dev)) return BadRequest();
|
|
|
+
|
|
|
IServerSentEventsClient sseClient;
|
|
|
if (Guid.TryParse($"{sid}", out Guid guid) && (sseClient = _sse.GetClient(guid)) != null) {
|
|
|
//var clientName = sseClient.GetProperty<string>("NAME");
|
|
@@ -89,9 +89,9 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
var id = jwt.Payload.Sub;
|
|
|
jwt.Payload.TryGetValue("name", out object name);
|
|
|
jwt.Payload.TryGetValue("picture", out object picture);
|
|
|
- List<object> schools = new List<object>();
|
|
|
- // object schools = null;
|
|
|
- string defaultschool = null;
|
|
|
+
|
|
|
+ List<ScanSchool> schools = new List<ScanSchool>();
|
|
|
+
|
|
|
//TODO 取得Teacher 個人相關數據(課程清單、虛擬教室清單、歷史紀錄清單等),學校數據另外API處理,多校切換時不同
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
var response = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync(id, new PartitionKey("Base"));
|
|
@@ -112,39 +112,34 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
//正式加入才会有
|
|
|
if (statusNow == "join")
|
|
|
{
|
|
|
- dynamic schoolExtobj = new ExpandoObject();
|
|
|
+ //dynamic schoolExtobj = new ExpandoObject();
|
|
|
var schoolJson = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync($"{obj.GetProperty("schoolId")}", new PartitionKey("Base"));
|
|
|
var school = await JsonDocument.ParseAsync(schoolJson.ContentStream);
|
|
|
- schoolExtobj.schoolId = obj.GetProperty("schoolId");
|
|
|
- schoolExtobj.name = obj.GetProperty("name");
|
|
|
- schoolExtobj.status = obj.GetProperty("status");
|
|
|
- if (obj.TryGetProperty("time", out JsonElement time))
|
|
|
- {
|
|
|
- schoolExtobj.time = obj.GetProperty("time");
|
|
|
+ var schoolId = obj.GetProperty("schoolId");
|
|
|
+ var schoolName = obj.GetProperty("name");
|
|
|
+ var schoolStatus = obj.GetProperty("status");
|
|
|
+ var schoolPicture = school.RootElement.GetProperty("picture");
|
|
|
+ //检查学校购买的模组是否包含阅卷模组
|
|
|
+ int count = 0;
|
|
|
+ string sql = $" SELECT value(count(serial)) FROM c join serial in c.serial where c.id ='{schoolId}' and c.pk='Product' and serial.prodCode='3222C6D2' ";
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<int>(sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Product") })) {
|
|
|
+ count = item;
|
|
|
}
|
|
|
+ if (count > 0) {
|
|
|
+ //生成token
|
|
|
+ var token = JwtAuthExtension.CreateAuthToken(_option.HostName, id, name?.ToString(), picture?.ToString(), _option.JwtSecretKey, roles: new[] { "teacher" }, schoolID: $"{schoolId}");
|
|
|
+ //获取线下阅卷评测
|
|
|
|
|
|
- schoolExtobj.picture = school.RootElement.GetProperty("picture");
|
|
|
- schools.Add(schoolExtobj);
|
|
|
- //如果有申请或者加入学校,但是未分配空间则都可以得到1G免费空间
|
|
|
- if (size == 0)
|
|
|
- {
|
|
|
- size = 1;
|
|
|
- Teacher tech = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Teacher>(id, new PartitionKey("Base"));
|
|
|
- tech.size = size;
|
|
|
- await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(tech, id, new PartitionKey("Base"));
|
|
|
+ schools.Add(new ScanSchool { name = $"schoolName", picture = $"{schoolPicture}", code = $"{schoolId}", status = $"{schoolStatus}" ,token=token});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //預設學校ID
|
|
|
- if (json.RootElement.TryGetProperty("defaultSchool", out JsonElement valueD) && !string.IsNullOrEmpty(valueD.ToString()))
|
|
|
- {
|
|
|
- defaultschool = valueD.ToString();
|
|
|
- }
|
|
|
+
|
|
|
//換取AuthToken,提供給前端
|
|
|
- var auth_token = JwtAuthExtension.CreateAuthToken(_option.HostName, id, name?.ToString(), picture?.ToString(), _option.JwtSecretKey, roles: new[] { "teacher" });
|
|
|
- await sseClient.SendEventAsync(new { auth_token, schools }.ToJsonString());
|
|
|
- return Ok(new { auth_token, schools });
|
|
|
+ var data = new { name, picture, id, schools };
|
|
|
+ await sseClient.SendEventAsync(data.ToJsonString());
|
|
|
+ return Ok(data);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -157,5 +152,18 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
}
|
|
|
return Ok();
|
|
|
}
|
|
|
+ private void GetExam(string schoolId ,string tmdid)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public class ScanSchool {
|
|
|
+ public string name { get; set; }
|
|
|
+ public string picture { get; set; }
|
|
|
+ public string code { get; set; }
|
|
|
+ public string status { get; set; }
|
|
|
+ public string token { get; set; }
|
|
|
}
|
|
|
}
|