|
@@ -45,6 +45,8 @@ using static TEAMModelOS.SDK.CoreAPIHttpService;
|
|
using Pipelines.Sockets.Unofficial.Arenas;
|
|
using Pipelines.Sockets.Unofficial.Arenas;
|
|
using System.Text.Json.Nodes;
|
|
using System.Text.Json.Nodes;
|
|
using TEAMModelOS.Services;
|
|
using TEAMModelOS.Services;
|
|
|
|
+using static TEAMModelOS.Controllers.Client.HiTAControlller;
|
|
|
|
+using DocumentFormat.OpenXml.Office2010.Excel;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers
|
|
namespace TEAMModelOS.Controllers
|
|
{
|
|
{
|
|
@@ -412,6 +414,197 @@ namespace TEAMModelOS.Controllers
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <summary>
|
|
|
|
+ ///
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="json"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
|
+ [HttpPost("qrcode/login")]
|
|
|
|
+ //[Authorize(Roles = "HiTA")]
|
|
|
|
+ public async Task<IActionResult> SchoolJoin(HiTAJoinSchool join)
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ Dictionary<string, object> dict = new Dictionary<string, object>();
|
|
|
|
+ Dictionary<string, object> qure = new Dictionary<string, object>();
|
|
|
|
+ foreach (var a in HttpContext.Request.Query)
|
|
|
|
+ {
|
|
|
|
+ qure.Add(a.Key, a.Value);
|
|
|
|
+ }
|
|
|
|
+ foreach (var a in HttpContext.Request.Headers)
|
|
|
|
+ {
|
|
|
|
+ dict.Add(a.Key, a.Value);
|
|
|
|
+ }
|
|
|
|
+ //await _dingDing.SendBotMsg(join.ToJsonString()+ dict.ToJsonString(), GroupNames.成都开发測試群組);
|
|
|
|
+
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(join.id_token) && !string.IsNullOrWhiteSpace(join.school) && join.school.Contains("login:"))
|
|
|
|
+ {
|
|
|
|
+ var jwt = new JwtSecurityToken(join.id_token);
|
|
|
|
+ //await _dingDing.SendBotMsg(join.ToJsonString(), GroupNames.成都开发測試群組);
|
|
|
|
+ var id = jwt.Payload.Sub;
|
|
|
|
+ await _azureRedis.GetRedisClient(8).StringSetAsync($"HiTA:Login:{join.school.Replace("login:", "")}", id, expiry: new TimeSpan(0, 0, 30));
|
|
|
|
+ return Ok(new { name = "关闭弹窗以获取登录信息" });
|
|
|
|
+ }
|
|
|
|
+ else { return Ok(new { error = 400, msg = "参数错误" }); }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ await _dingDing.SendBotMsg($"{ex.Message},{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
|
+ return Ok(new { error = 400, msg = "参数错误" });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
|
+ [HttpGet("qrcode/check")]
|
|
|
|
+ public async Task<IActionResult> QRCodeCheck([FromQuery] HiTAJoinSchool join)
|
|
|
|
+ {
|
|
|
|
+ int timezone = 8;
|
|
|
|
+ if (HttpContext.Request.Headers.TryGetValue("Time-Zone", out var Time_Zone) && int.TryParse(Time_Zone, out int tz))
|
|
|
|
+ {
|
|
|
|
+ timezone = tz;
|
|
|
|
+ }
|
|
|
|
+ string tmdid = string.Empty;
|
|
|
|
+ string school = join.school;
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(join.code)&& !string.IsNullOrWhiteSpace(school))
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ var data = await _azureRedis.GetRedisClient(8).StringGetAsync($"HiTA:Login:{school}:{join.code}");
|
|
|
|
+ if (data.HasValue)
|
|
|
|
+ {
|
|
|
|
+ tmdid = data.ToString();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(tmdid))
|
|
|
|
+ {
|
|
|
|
+ var location = _option.Location;
|
|
|
|
+ var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
|
+ TmdidImplicit implicit_token = await _coreAPIHttpService.Implicit(new Dictionary<string, string>()
|
|
|
|
+ {
|
|
|
|
+ { "grant_type", "implicit" },
|
|
|
|
+ { "client_id",clientID },
|
|
|
|
+ { "account",tmdid },
|
|
|
|
+ { "nonce",Guid.NewGuid().ToString()}
|
|
|
|
+ }, location, _configuration);
|
|
|
|
+ IEnumerable<dynamic> schools = new List<dynamic>();
|
|
|
|
+
|
|
|
|
+ object name = null, picture = null;
|
|
|
|
+ var jwt = new JwtSecurityToken(implicit_token.id_token);
|
|
|
|
+ jwt.Payload.TryGetValue("name", out name);
|
|
|
|
+ jwt.Payload.TryGetValue("picture", out picture);
|
|
|
|
+ jwt.Payload.TryGetValue("lang", out object _jwtlang);
|
|
|
|
+
|
|
|
|
+ School schoolBase = null;
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(school))
|
|
|
|
+ {
|
|
|
|
+ ResponseMessage responseSchool = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemStreamAsync(school, new PartitionKey("Base"));
|
|
|
|
+ if (responseSchool.IsSuccessStatusCode)
|
|
|
|
+ {
|
|
|
|
+ schoolBase = JsonDocument.Parse(responseSchool.Content).RootElement.ToObject<School>();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Teacher teacher = null;
|
|
|
|
+ ResponseMessage response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemStreamAsync(tmdid, new PartitionKey("Base"));
|
|
|
|
+ if (response.IsSuccessStatusCode)
|
|
|
|
+ {
|
|
|
|
+ teacher = JsonDocument.Parse(response.Content).RootElement.ToObject<Teacher>();
|
|
|
|
+ if (schoolBase != null)
|
|
|
|
+ {
|
|
|
|
+ // teacher.defaultSchool = school;
|
|
|
|
+ var sch = teacher.schools.Find(x => x.schoolId.Equals(school));
|
|
|
|
+ if (sch == null)
|
|
|
|
+ {
|
|
|
|
+ teacher.schools.Add(new Teacher.TeacherSchool
|
|
|
|
+ {
|
|
|
|
+ areaId = schoolBase.areaId,
|
|
|
|
+ schoolId = schoolBase.id,
|
|
|
|
+ status = "join",
|
|
|
|
+ name = schoolBase.name,
|
|
|
|
+ picture = schoolBase.picture,
|
|
|
|
+ roles = new List<string> { "teacher" },
|
|
|
|
+ time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
|
|
|
|
+ });
|
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync<Teacher>(teacher, new PartitionKey("Base"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ schools = teacher.schools.Where(x => x.status.Equals("join")).Select(x => new { id = x.schoolId, name = x.name, picture = x.picture });
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ //如果沒有,則初始化Teacher基本資料到Cosmos
|
|
|
|
+ teacher = new Teacher
|
|
|
|
+ {
|
|
|
|
+ createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
|
+ id = tmdid,
|
|
|
|
+ pk = "Base",
|
|
|
|
+ code = "Base",
|
|
|
|
+ name = name?.ToString(),
|
|
|
|
+ picture = picture?.ToString(),
|
|
|
|
+ //创建账号并第一次登录IES5则默认赠送1G
|
|
|
|
+ size = 1,
|
|
|
|
+ defaultSchool = null,
|
|
|
|
+ schools = new List<Teacher.TeacherSchool>(),
|
|
|
|
+ lang = "zh-cn",
|
|
|
|
+ timezone = timezone,
|
|
|
|
+ };
|
|
|
|
+ if (schoolBase != null)
|
|
|
|
+ {
|
|
|
|
+ teacher.defaultSchool = school;
|
|
|
|
+ teacher.schools.Add(new Teacher.TeacherSchool
|
|
|
|
+ {
|
|
|
|
+ areaId = schoolBase.areaId,
|
|
|
|
+ schoolId = schoolBase.id,
|
|
|
|
+ status = "join",
|
|
|
|
+ name = schoolBase.name,
|
|
|
|
+ picture = schoolBase.picture,
|
|
|
|
+ roles = new List<string> { "teacher" },
|
|
|
|
+ time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ var container = _azureStorage.GetBlobContainerClient(tmdid);
|
|
|
|
+ await container.CreateIfNotExistsAsync(PublicAccessType.None); //嘗試創建Teacher私有容器,如存在則不做任何事,保障容器一定存在
|
|
|
|
+ teacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
|
|
|
|
+ }
|
|
|
|
+ if (schoolBase != null)
|
|
|
|
+ {
|
|
|
|
+ school = schoolBase.id;
|
|
|
|
+ ResponseMessage responseTeacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemStreamAsync(tmdid, new PartitionKey($"Teacher-{school}"));
|
|
|
|
+ if (!responseTeacher.IsSuccessStatusCode)
|
|
|
|
+ {
|
|
|
|
+ SchoolTeacher schoolTeacher = new SchoolTeacher
|
|
|
|
+ {
|
|
|
|
+ id = tmdid,
|
|
|
|
+ code = $"Teacher-{school}",
|
|
|
|
+ name = teacher.name,
|
|
|
|
+ picture = teacher.picture,
|
|
|
|
+ status = "join",
|
|
|
|
+ pk = "Teacher",
|
|
|
|
+ roles = new List<string> { "teacher" },
|
|
|
|
+ ttl = -1,
|
|
|
|
+ periodId = schoolBase.period.FirstOrDefault()?.id,
|
|
|
|
+ createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
|
|
|
|
+ };
|
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).UpsertItemAsync(schoolTeacher, new PartitionKey($"Teacher-{school}"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ school = null;
|
|
|
|
+ }
|
|
|
|
+ (string ip, string region) = await LoginService.LoginIp(HttpContext, _searcher);
|
|
|
|
+ TeacherInfo teacherInfo = await TeacherService.TeacherInfoLite(_azureCosmos, $"{name}", $"{picture}", $"{jwt.Payload.Sub}", _azureStorage, _option, _azureRedis, "", _httpTrigger, $"{_jwtlang}", timezone,school);
|
|
|
|
+ string x_auth_token = string.Empty;
|
|
|
|
+ if (teacherInfo != null)
|
|
|
|
+ {
|
|
|
|
+ x_auth_token = teacherInfo.auth_token;
|
|
|
|
+ }
|
|
|
|
+ return Ok(new { code = 200, implicit_token, schools, x_auth_token });
|
|
|
|
+ }
|
|
|
|
+ return Ok(new { code = 400 });
|
|
|
|
+ }
|
|
|
|
+ /// <summary>
|
|
///{"grant_type":"create","client_id":"c7317f88-7cea-4e48-ac57-a16071f7b884","nonce":"habook","name":"User","pin_code":"985395","account":"+86-15283771540"}
|
|
///{"grant_type":"create","client_id":"c7317f88-7cea-4e48-ac57-a16071f7b884","nonce":"habook","name":"User","pin_code":"985395","account":"+86-15283771540"}
|
|
///{"error":2,"message":"帳號已存在"}
|
|
///{"error":2,"message":"帳號已存在"}
|
|
///{"error":3,"message":"驗證PIN碼失敗"}
|
|
///{"error":3,"message":"驗證PIN碼失敗"}
|
|
@@ -436,6 +629,7 @@ namespace TEAMModelOS.Controllers
|
|
}
|
|
}
|
|
var pin_code = request["pin_code"];
|
|
var pin_code = request["pin_code"];
|
|
var account = request["account"];
|
|
var account = request["account"];
|
|
|
|
+ var school = $"{request["school"]}";
|
|
TmdidImplicit implicit_token = null;
|
|
TmdidImplicit implicit_token = null;
|
|
var loginData= await _coreAPIHttpService.Auth2Login($"{pin_code}", $"{account}", _option.Location, _configuration, _dingDing);
|
|
var loginData= await _coreAPIHttpService.Auth2Login($"{pin_code}", $"{account}", _option.Location, _configuration, _dingDing);
|
|
if (loginData.code.Equals(HttpStatusCode.OK))
|
|
if (loginData.code.Equals(HttpStatusCode.OK))
|
|
@@ -470,7 +664,7 @@ namespace TEAMModelOS.Controllers
|
|
msg=$"验证失败!{loginData.content}";
|
|
msg=$"验证失败!{loginData.content}";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (implicit_token!=null)
|
|
|
|
|
|
+ if (implicit_token != null)
|
|
{
|
|
{
|
|
object name = null, picture = null;
|
|
object name = null, picture = null;
|
|
var jwt = new JwtSecurityToken(implicit_token.id_token);
|
|
var jwt = new JwtSecurityToken(implicit_token.id_token);
|
|
@@ -479,15 +673,104 @@ namespace TEAMModelOS.Controllers
|
|
jwt.Payload.TryGetValue("lang", out object _jwtlang);
|
|
jwt.Payload.TryGetValue("lang", out object _jwtlang);
|
|
var tmdid = jwt.Payload.Sub;
|
|
var tmdid = jwt.Payload.Sub;
|
|
IEnumerable<dynamic> schools = new List<dynamic>();
|
|
IEnumerable<dynamic> schools = new List<dynamic>();
|
|
- var response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemStreamAsync(tmdid, new PartitionKey("Base"));
|
|
|
|
- if (response.StatusCode==System.Net.HttpStatusCode.OK)
|
|
|
|
|
|
+ School schoolBase = null;
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(school))
|
|
|
|
+ {
|
|
|
|
+ ResponseMessage responseSchool = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemStreamAsync(school, new PartitionKey("Base"));
|
|
|
|
+ if (responseSchool.IsSuccessStatusCode)
|
|
|
|
+ {
|
|
|
|
+ schoolBase = JsonDocument.Parse(responseSchool.Content).RootElement.ToObject<School>();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Teacher teacher = null;
|
|
|
|
+ ResponseMessage response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemStreamAsync(tmdid, new PartitionKey("Base"));
|
|
|
|
+ if (response.IsSuccessStatusCode)
|
|
{
|
|
{
|
|
- Teacher teacher = JsonDocument.Parse(response.Content).RootElement.ToObject<Teacher>();
|
|
|
|
- schools= teacher.schools.Where(x => x.status.Equals("join")).Select(x => new { id = x.schoolId, name = x.name, picture = x.picture });
|
|
|
|
|
|
+ teacher = JsonDocument.Parse(response.Content).RootElement.ToObject<Teacher>();
|
|
|
|
+ if (schoolBase != null)
|
|
|
|
+ {
|
|
|
|
+ // teacher.defaultSchool = school;
|
|
|
|
+ var sch = teacher.schools.Find(x => x.schoolId.Equals(school));
|
|
|
|
+ if (sch == null)
|
|
|
|
+ {
|
|
|
|
+ teacher.schools.Add(new Teacher.TeacherSchool
|
|
|
|
+ {
|
|
|
|
+ areaId = schoolBase.areaId,
|
|
|
|
+ schoolId = schoolBase.id,
|
|
|
|
+ status = "join",
|
|
|
|
+ name = schoolBase.name,
|
|
|
|
+ picture = schoolBase.picture,
|
|
|
|
+ roles = new List<string> { "teacher" },
|
|
|
|
+ time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
|
|
|
|
+ });
|
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync<Teacher>(teacher, new PartitionKey("Base"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ schools = teacher.schools.Where(x => x.status.Equals("join")).Select(x => new { id = x.schoolId, name = x.name, picture = x.picture });
|
|
}
|
|
}
|
|
|
|
+ else {
|
|
|
|
|
|
|
|
+ //如果沒有,則初始化Teacher基本資料到Cosmos
|
|
|
|
+ teacher = new Teacher
|
|
|
|
+ {
|
|
|
|
+ createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
|
+ id = tmdid,
|
|
|
|
+ pk = "Base",
|
|
|
|
+ code = "Base",
|
|
|
|
+ name = name?.ToString(),
|
|
|
|
+ picture = picture?.ToString(),
|
|
|
|
+ //创建账号并第一次登录IES5则默认赠送1G
|
|
|
|
+ size = 1,
|
|
|
|
+ defaultSchool = null,
|
|
|
|
+ schools = new List<Teacher.TeacherSchool>() ,
|
|
|
|
+ lang = "zh-cn",
|
|
|
|
+ timezone = timezone,
|
|
|
|
+ };
|
|
|
|
+ if (schoolBase != null)
|
|
|
|
+ {
|
|
|
|
+ teacher.defaultSchool = school;
|
|
|
|
+ teacher.schools.Add(new Teacher.TeacherSchool
|
|
|
|
+ {
|
|
|
|
+ areaId = schoolBase.areaId,
|
|
|
|
+ schoolId = schoolBase.id,
|
|
|
|
+ status = "join",
|
|
|
|
+ name = schoolBase.name,
|
|
|
|
+ picture = schoolBase.picture,
|
|
|
|
+ roles = new List<string> { "teacher" },
|
|
|
|
+ time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ var container = _azureStorage.GetBlobContainerClient(tmdid);
|
|
|
|
+ await container.CreateIfNotExistsAsync(PublicAccessType.None); //嘗試創建Teacher私有容器,如存在則不做任何事,保障容器一定存在
|
|
|
|
+ teacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
|
|
|
|
+ }
|
|
|
|
+ if (schoolBase != null)
|
|
|
|
+ {
|
|
|
|
+ school = schoolBase.id;
|
|
|
|
+ ResponseMessage responseTeacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemStreamAsync(tmdid, new PartitionKey($"Teacher-{school}"));
|
|
|
|
+ if (!responseTeacher.IsSuccessStatusCode)
|
|
|
|
+ {
|
|
|
|
+ SchoolTeacher schoolTeacher = new SchoolTeacher
|
|
|
|
+ {
|
|
|
|
+ id = tmdid,
|
|
|
|
+ code = $"Teacher-{school}",
|
|
|
|
+ name = teacher.name,
|
|
|
|
+ picture = teacher.picture,
|
|
|
|
+ status = "join",
|
|
|
|
+ pk = "Teacher",
|
|
|
|
+ roles = new List<string> { "teacher" },
|
|
|
|
+ ttl = -1,
|
|
|
|
+ periodId = schoolBase.period.FirstOrDefault()?.id,
|
|
|
|
+ createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
|
|
|
|
+ };
|
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).UpsertItemAsync(schoolTeacher, new PartitionKey($"Teacher-{school}"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ school =null;
|
|
|
|
+ }
|
|
(string ip, string region) = await LoginService.LoginIp(HttpContext, _searcher);
|
|
(string ip, string region) = await LoginService.LoginIp(HttpContext, _searcher);
|
|
- TeacherInfo teacherInfo = await TeacherService.TeacherInfoLite(_azureCosmos, $"{name}", $"{picture}", $"{jwt.Payload.Sub}", _azureStorage, _option, _azureRedis, "", _httpTrigger, $"{_jwtlang}", timezone);
|
|
|
|
|
|
+ TeacherInfo teacherInfo = await TeacherService.TeacherInfoLite(_azureCosmos, $"{name}", $"{picture}", $"{jwt.Payload.Sub}", _azureStorage, _option, _azureRedis, "", _httpTrigger, $"{_jwtlang}", timezone,school);
|
|
string x_auth_token = string.Empty;
|
|
string x_auth_token = string.Empty;
|
|
if (teacherInfo!=null)
|
|
if (teacherInfo!=null)
|
|
{
|
|
{
|
|
@@ -1003,7 +1286,8 @@ namespace TEAMModelOS.Controllers
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
+ public class QRCodeLoginCheck
|
|
|
|
+ { }
|
|
public record ApplySchool
|
|
public record ApplySchool
|
|
{
|
|
{
|
|
/// <summary>
|
|
/// <summary>
|