|
@@ -79,33 +79,36 @@ 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("id", out JsonElement id_token)) return BadRequest();
|
|
|
|
|
|
//IServerSentEventsClient sseClient;
|
|
|
//if (Guid.TryParse($"{sid}", out Guid guid) && (sseClient = _sse.GetClient(guid)) != null) {
|
|
|
//var clientName = sseClient.GetProperty<string>("NAME");
|
|
|
//var clientDID= sseClient.GetProperty<string>("DID");
|
|
|
// var isHiTeach = clientName.Contains("HiScan", StringComparison.OrdinalIgnoreCase);
|
|
|
- var jwt = new JwtSecurityToken(id_token.GetString());
|
|
|
+ //var jwt = new JwtSecurityToken(id_token.GetString());
|
|
|
//TODO 此驗證IdToken先簡單檢查,後面需向Core ID新API,驗證Token
|
|
|
- if (!jwt.Payload.Iss.Equals("account.teammodel", StringComparison.OrdinalIgnoreCase)) return BadRequest();
|
|
|
- var id = jwt.Payload.Sub;
|
|
|
- jwt.Payload.TryGetValue("name", out object name);
|
|
|
- jwt.Payload.TryGetValue("picture", out object picture);
|
|
|
+ // if (!jwt.Payload.Iss.Equals("account.teammodel", StringComparison.OrdinalIgnoreCase)) return BadRequest();
|
|
|
+ // var id = jwt.Payload.Sub;
|
|
|
+ //jwt.Payload.TryGetValue("name", out object name);
|
|
|
+ //jwt.Payload.TryGetValue("picture", out object picture);
|
|
|
|
|
|
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"));
|
|
|
+ if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
+ //TODO 取得Teacher 個人相關數據(課程清單、虛擬教室清單、歷史紀錄清單等),學校數據另外API處理,多校切換時不同
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ var response = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync($"{id}", new PartitionKey("Base"));
|
|
|
int size = 0;
|
|
|
//老師個人資料(含初始化)
|
|
|
if (response.Status == 200)
|
|
|
{
|
|
|
var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("schools", out JsonElement value))
|
|
|
+ string name = $"{json.RootElement.GetProperty("name")}";
|
|
|
+ string picture = $"{json.RootElement.GetProperty("picture")}";
|
|
|
+ if (json.RootElement.TryGetProperty("schools", out JsonElement value))
|
|
|
{
|
|
|
- if (json.RootElement.TryGetProperty("size", out JsonElement _size) && _size.ValueKind.Equals(JsonValueKind.Number))
|
|
|
+
|
|
|
+ if (json.RootElement.TryGetProperty("size", out JsonElement _size) && _size.ValueKind.Equals(JsonValueKind.Number))
|
|
|
{
|
|
|
size = _size.GetInt32();
|
|
|
}
|
|
@@ -130,7 +133,7 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
}
|
|
|
if (count > 0) {
|
|
|
//生成token
|
|
|
- var stoken = JwtAuthExtension.CreateAuthToken(_option.HostName, id, name?.ToString(), picture?.ToString(), _option.JwtSecretKey, roles: new[] { "teacher" }, schoolID: $"{schoolId}");
|
|
|
+ var stoken = JwtAuthExtension.CreateAuthToken(_option.HostName, $"{id}", name?.ToString(), picture?.ToString(), _option.JwtSecretKey, roles: new[] { "teacher" }, schoolID: $"{schoolId}");
|
|
|
//获取学校线下阅卷评测
|
|
|
var sexams= await GetExam($"{schoolId}", "school", client);
|
|
|
var container = _azureStorage.GetBlobContainerClient($"{schoolId}");
|
|
@@ -141,8 +144,8 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- var ttoken = JwtAuthExtension.CreateAuthToken(_option.HostName, id, name?.ToString(), picture?.ToString(), _option.JwtSecretKey, roles: new[] { "teacher" });
|
|
|
- var (tblob_uri, tblob_sas) = _azureStorage.GetBlobContainerSAS(id, BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Delete);
|
|
|
+ var ttoken = JwtAuthExtension.CreateAuthToken(_option.HostName, $"{id}", name?.ToString(), picture?.ToString(), _option.JwtSecretKey, roles: new[] { "teacher" });
|
|
|
+ var (tblob_uri, tblob_sas) = _azureStorage.GetBlobContainerSAS($"{id}", BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Delete);
|
|
|
//获取个人线下阅卷评测
|
|
|
var exams = await GetExam($"{id}", "private", client);
|
|
|
//換取AuthToken,提供給前端
|
|
@@ -170,15 +173,24 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
//await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<Correct>(queryText: "SELECT * FROM c where c.source='2' and c.progress='going' order by c.createTime ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Correct-{code}") }))
|
|
|
await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<Correct>(queryText: "SELECT * FROM c order by c.createTime ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Correct-{code}") }))
|
|
|
{
|
|
|
- ExamInfo exam = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(item.id, new PartitionKey($"Exam-{code}"));
|
|
|
-
|
|
|
+
|
|
|
+ ExamInfo exam =null;
|
|
|
+ try {
|
|
|
+ exam= await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(item.id, new PartitionKey($"Exam-{code}"));
|
|
|
+ } catch (CosmosException ex) {
|
|
|
+ if (ex.Status == 404) {
|
|
|
+ exam = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
List<ExamClass> classes = new List<ExamClass>();
|
|
|
- foreach (var cls in exam.classes) {
|
|
|
- (List<string> tmdids, List<Students> students) stulist = await TriggerStuActivity.GetStuList(client, _dingDing, new List<string> { cls }, code);
|
|
|
- classes.Add(new ExamClass { classId = cls, tmdids = stulist.tmdids, stulist = stulist.students });
|
|
|
+ if (exam != null) {
|
|
|
+ foreach (var cls in exam.classes)
|
|
|
+ {
|
|
|
+ (List<string> tmdids, List<Students> students) stulist = await TriggerStuActivity.GetStuList(client, _dingDing, new List<string> { cls }, code);
|
|
|
+ classes.Add(new ExamClass { classId = cls, tmdids = stulist.tmdids, stulist = stulist.students });
|
|
|
+ }
|
|
|
+ corrects.Add(new ExamData { exam = exam, correct = item, classes = classes });
|
|
|
}
|
|
|
- corrects.Add(new ExamData { exam = exam, correct = item, classes= classes });
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
else if(scope.Equals("private")){
|