|
@@ -36,7 +36,7 @@ namespace TEAMModelOS.Controllers.Third
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
|
//[Authorize(Roles = "IES5")]
|
|
|
- [Route("sc")]
|
|
|
+ //[Route("")]
|
|
|
//[Route("api/[controller]")]
|
|
|
[ApiController]
|
|
|
public class ScController : ControllerBase
|
|
@@ -51,6 +51,7 @@ namespace TEAMModelOS.Controllers.Third
|
|
|
private readonly CoreAPIHttpService _accountHttpService;
|
|
|
private readonly ThirdApisService _scsApisService;
|
|
|
public readonly string type = "scsyxpt";
|
|
|
+ private readonly HttpTrigger _httpTrigger;
|
|
|
/// <summary>
|
|
|
/// 机构安全码
|
|
|
/// </summary>
|
|
@@ -69,7 +70,7 @@ namespace TEAMModelOS.Controllers.Third
|
|
|
public string _sc_url;
|
|
|
public IConfiguration _configuration { get; set; }
|
|
|
public ScController(AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage,
|
|
|
- AzureRedisFactory azureRedis, AzureServiceBusFactory serviceBus, IConfiguration configuration, CoreAPIHttpService accountHttpService, ThirdApisService scsApisService)
|
|
|
+ AzureRedisFactory azureRedis, AzureServiceBusFactory serviceBus, IConfiguration configuration, CoreAPIHttpService accountHttpService, ThirdApisService scsApisService, HttpTrigger httpTrigger)
|
|
|
{
|
|
|
_azureCosmos = azureCosmos;
|
|
|
_snowflakeId = snowflakeId;
|
|
@@ -85,6 +86,210 @@ namespace TEAMModelOS.Controllers.Third
|
|
|
_sc_trainComID = _configuration.GetValue<string>("Third:scsyxpt:trainComID");
|
|
|
_sc_privateKey = _configuration.GetValue<string>("Third:scsyxpt:privateKey");
|
|
|
_sc_url = _configuration.GetValue<string>("Third:scsyxpt:url");
|
|
|
+ _httpTrigger = httpTrigger;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ ///
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("sc/bind")]
|
|
|
+ [AllowAnonymous]
|
|
|
+ public async Task<IActionResult> Bind(SSO sso) {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ Teacher teacher = null;
|
|
|
+ if (string.IsNullOrEmpty(sso.id_token)) {
|
|
|
+ return Ok(new
|
|
|
+ {
|
|
|
+ location = _option.Location,
|
|
|
+ status = 2,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ var jwt = new JwtSecurityToken(sso.id_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);
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ teacher = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>(id, new PartitionKey("Base"));
|
|
|
+ //先检查绑定的平台是否已经被绑定
|
|
|
+ //四川研训平台跳转隐式登录/或者绑定IES平台接入规范
|
|
|
+ ScSSO scsso= sso.param.ToObject<ScSSO>();
|
|
|
+ string sql = $"SELECT distinct value(c) FROM c join A1 in c.binds where A1.webid='{scsso.Webid}' and A1.tid='{scsso.tid}'";
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(queryText: sql,
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
|
|
|
+ {
|
|
|
+ teacher = item;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (teacher != null)
|
|
|
+ {
|
|
|
+ if (teacher.id.Equals(id))
|
|
|
+ {
|
|
|
+ var bind = teacher.binds.Find(x => x.source.Equals($"{scsso.Webid}") && x.userid.Equals($"{scsso.tid}"));
|
|
|
+ if (bind == null)
|
|
|
+ {
|
|
|
+ teacher.binds=new List<Teacher.ThirdBind> { new Teacher.ThirdBind { pxid = new HashSet<string> { $"{scsso.Pxid}" }, userid = $"{scsso.tid}", source = $"{scsso.Webid}", type = type } };
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (bind.pxid != null)
|
|
|
+ {
|
|
|
+ if (bind.pxid.Add(scsso.Pxid))
|
|
|
+ {
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ bind.pxid = new HashSet<string> { scsso.Pxid };
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return Ok(new
|
|
|
+ {
|
|
|
+ location = _option.Location,
|
|
|
+ //账号已被别的醍摩豆id绑定
|
|
|
+ status = 3,
|
|
|
+ tmdid = teacher.id,
|
|
|
+ name=teacher.name,
|
|
|
+ tid = scsso.tid
|
|
|
+ }) ;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ teacher = new Teacher
|
|
|
+ {
|
|
|
+ id = id,
|
|
|
+ pk = "Base",
|
|
|
+ code = "Base",
|
|
|
+ name = name?.ToString(),
|
|
|
+ picture = picture?.ToString(),
|
|
|
+ //创建账号并第一次登录IES5则默认赠送1G
|
|
|
+ size = 1,
|
|
|
+ defaultSchool = null,
|
|
|
+ schools = new List<Teacher.TeacherSchool>(),
|
|
|
+ binds= new List<Teacher.ThirdBind> { new Teacher.ThirdBind { pxid = new HashSet<string> { $"{scsso.Pxid}" }, userid = $"{scsso.tid}", source = $"{scsso.Webid}", type = type } }
|
|
|
+ };
|
|
|
+ var container = _azureStorage.GetBlobContainerClient(id);
|
|
|
+ await container.CreateIfNotExistsAsync(PublicAccessType.None); //嘗試創建Teacher私有容器,如存在則不做任何事,保障容器一定存在
|
|
|
+ teacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
|
|
|
+ }
|
|
|
+ return Ok(new
|
|
|
+ {
|
|
|
+ location = _option.Location,
|
|
|
+ status = 200,
|
|
|
+ });
|
|
|
+
|
|
|
+ } catch (Exception ) {
|
|
|
+ return Ok(new
|
|
|
+ {
|
|
|
+ location = _option.Location,
|
|
|
+ status = 2,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ ///
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+
|
|
|
+ [HttpGet("{path}/sso")]
|
|
|
+ [AllowAnonymous]
|
|
|
+ public async Task<IActionResult> Sso([FromQuery] ScSSO sso,string path)
|
|
|
+ {
|
|
|
+ if (path.Equals("sc"))
|
|
|
+ {
|
|
|
+ path = $"scpjx";
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ path = $"sc{path}";
|
|
|
+ }
|
|
|
+ var rurl = new StringBuilder($"https://{_option.HostName}/sso");
|
|
|
+ string parmas = $"Pxid={sso.Pxid}&Webid={sso.Webid}&tid={sso.tid}&time={sso.time}";
|
|
|
+ if (Md5Hash.GetMd5String(parmas).Equals($"{sso.Encrypt}"))
|
|
|
+ {
|
|
|
+ //四川研训平台跳转隐式登录/或者绑定IES平台接入规范
|
|
|
+
|
|
|
+ long ssotime = long.Parse($"{sso.time}");
|
|
|
+ long nowtime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
|
|
+ if (nowtime - ssotime > 60 * 10)//10分钟有效期
|
|
|
+ {
|
|
|
+ // return Ok(new { status = 2, msg = "登录超时!" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Redirect(rurl.Append($"?status=1").ToString());
|
|
|
+ }
|
|
|
+ Dictionary<string, object> dict = new Dictionary<string, object> { { "pxid",sso.Pxid },{ "tid",sso.tid} };
|
|
|
+ (int status,string json ) =await _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetSingleTeacherByProject");
|
|
|
+ Teacher teacher = null;
|
|
|
+ //四川研训平台跳转隐式登录/或者绑定IES平台接入规范
|
|
|
+ //string sql = $"SELECT distinct value(c) FROM c join A1 in c.binds where A1.pxid='{sso.Pxid}' and A1.webid='{sso.Webid}' and A1.tid='{sso.tid}'";
|
|
|
+ string sql = $"SELECT distinct value(c) FROM c join A1 in c.binds where A1.source='{sso.Webid}' and A1.userid='{sso.tid}'";
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(queryText: sql,
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
|
|
|
+ {
|
|
|
+ teacher = item;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (teacher == null)
|
|
|
+ {
|
|
|
+ return Redirect(rurl.Append($"?status=4¶m={sso.ToJsonString()}&type={type}&bindurl=sc/bind").ToString());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var url = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
|
|
|
+ var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
+ var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
|
|
|
+ var location = _option.Location;
|
|
|
+ (int code, string content) = await _accountHttpService.Implicit(clientID, clientSecret, location, $"{url}/oauth2/implicit",
|
|
|
+ new Dictionary<string, string>()
|
|
|
+ {
|
|
|
+ { "grant_type", "implicit" },
|
|
|
+ { "client_id",clientID },
|
|
|
+ { "account",teacher.id },
|
|
|
+ { "nonce",Guid.NewGuid().ToString()}
|
|
|
+ });
|
|
|
+ TmdidImplicit implicit_token = new TmdidImplicit();
|
|
|
+ if (!string.IsNullOrEmpty(content) && code==200)
|
|
|
+ {
|
|
|
+ implicit_token = content.ToObject<TmdidImplicit>();
|
|
|
+ var bind = teacher.binds.Find(x => x.userid.Equals(sso.tid) && x.source.Equals(sso.Webid));
|
|
|
+ if (bind != null) {
|
|
|
+ if (bind.pxid != null)
|
|
|
+ {
|
|
|
+ if (bind.pxid.Add(sso.Pxid))
|
|
|
+ {
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ bind.pxid = new HashSet<string> { sso.Pxid };
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Redirect(rurl.Append($"?status=200&id_token={implicit_token.id_token}&access_token={implicit_token.access_token}&expires_in={implicit_token.expires_in}&token_type={implicit_token.token_type}").ToString());
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ //绑定失效
|
|
|
+ if (teacher.binds.IsNotEmpty()) {
|
|
|
+ teacher.binds.RemoveAll(x => x.userid.Equals(sso.tid) && x.source.Equals(sso.Webid));
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher,teacher.id,new PartitionKey(teacher.code));
|
|
|
+ }
|
|
|
+ return Redirect(rurl.Append($"?status=4¶m={sso.ToJsonString()}&type={type}&bindurl=sc/bind").ToString());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
/// <summary>
|
|
|
///
|
|
@@ -92,20 +297,21 @@ namespace TEAMModelOS.Controllers.Third
|
|
|
/// <param name="json"></param>
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
- [HttpPost("get-list")]
|
|
|
+ [HttpPost("sc/get-list")]
|
|
|
[AllowAnonymous]
|
|
|
- public async Task<IActionResult> GetProjectList(JsonElement json) {
|
|
|
+ public async Task<IActionResult> GetProjectList(JsonElement json)
|
|
|
+ {
|
|
|
|
|
|
// 5.3.1.1获取项目列表
|
|
|
string trainComID = _sc_trainComID;
|
|
|
string Code = "GetProjectInfoByTrainComID";
|
|
|
Dictionary<string, object> parameterMap = new Dictionary<string, object>();
|
|
|
parameterMap.Add("TrainComID", _sc_trainComID);
|
|
|
- ScsResult GetProjectInfoByTrainComID = await _scsApisService.Post(_sc_url, Code, _sc_passKey,_sc_privateKey, parameterMap);
|
|
|
+ ScsResult GetProjectInfoByTrainComID = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
|
|
|
GetProjectInfoByTrainComID.code = Code;
|
|
|
GetProjectInfoByTrainComID.title = "5.3.1.1获取项目列表";
|
|
|
|
|
|
-
|
|
|
+
|
|
|
// 5.3.1.2获取学员名单,暂不对接。
|
|
|
Code = "GetTeachersListByProject";
|
|
|
parameterMap = new Dictionary<string, object>();
|
|
@@ -143,7 +349,8 @@ namespace TEAMModelOS.Controllers.Third
|
|
|
|
|
|
ScsResult UpdateTeacherSituation = null;
|
|
|
// 5.3.1.4学员培训基本情况回写
|
|
|
- try {
|
|
|
+ try
|
|
|
+ {
|
|
|
Code = "UpdateTeacherSituation";
|
|
|
parameterMap = new Dictionary<string, object>();
|
|
|
parameterMap.Add("TrainComID", trainComID);
|
|
@@ -156,7 +363,8 @@ namespace TEAMModelOS.Controllers.Third
|
|
|
UpdateTeacherSituation = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
|
|
|
UpdateTeacherSituation.code = Code;
|
|
|
UpdateTeacherSituation.title = "5.3.1.4学员培训基本情况回写";
|
|
|
- } catch (Exception ex) { }
|
|
|
+ }
|
|
|
+ catch (Exception ex) { }
|
|
|
ScsResult UpdateTeacherDiagnosis = null;
|
|
|
try
|
|
|
{
|
|
@@ -185,7 +393,8 @@ namespace TEAMModelOS.Controllers.Third
|
|
|
UpdateTeacherDiagnosis.code = Code;
|
|
|
UpdateTeacherDiagnosis.title = "5.3.1.5学员能力点测评结果回写";
|
|
|
}
|
|
|
- catch (Exception ex) {
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
}
|
|
|
|
|
|
|
|
@@ -256,8 +465,8 @@ namespace TEAMModelOS.Controllers.Third
|
|
|
try
|
|
|
{ // 5.3.1.12学员培训基本情况批量回写
|
|
|
Code = "UpdateTeacherListSituation";
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
parameterContent.Add("TrainComID", trainComID);
|
|
|
parameterContent.Add("List", list);
|
|
|
// {"TrainComID":"39","List":[{"ResearchText":"","ComPassed":1,"PXID":"35455","CourseHour":"50.0","TID":"411105","TeacherName":"付绍令"}]}
|
|
@@ -376,11 +585,12 @@ namespace TEAMModelOS.Controllers.Third
|
|
|
pfiles.Add(pfileMap);
|
|
|
list.Add(parameterMapData);
|
|
|
}
|
|
|
- UpdateTeacherListDiagnosis = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterContent);
|
|
|
+ UpdateTeacherListDiagnosis = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterContent);
|
|
|
UpdateTeacherListDiagnosis.code = Code;
|
|
|
UpdateTeacherListDiagnosis.title = "5.3.1.13学员能力点测评结果批量回写";
|
|
|
}
|
|
|
- catch (Exception ex) {
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
}
|
|
|
|
|
|
|
|
@@ -402,7 +612,8 @@ namespace TEAMModelOS.Controllers.Third
|
|
|
UploadSBTARPDF.code = Code;
|
|
|
UploadSBTARPDF.title = "5.3.1.14学员校本研修PDF回写";
|
|
|
}
|
|
|
- catch (Exception ex) {
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
}
|
|
|
|
|
|
ScsResult UploadSBTARPDFList = null;
|
|
@@ -455,10 +666,11 @@ namespace TEAMModelOS.Controllers.Third
|
|
|
parameterMap.Add("fileSize", "247767");
|
|
|
parameterMap.Add("md5", "9c3da8c5c07c2c660cd73c01f56d7fca");
|
|
|
parameterMap.Add("fileType", "mp4");
|
|
|
- UploadKTSL = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
|
|
|
+ UploadKTSL = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
|
|
|
UploadKTSL.code = Code;
|
|
|
UploadKTSL.title = "5.3.1.16学员课堂实录回写";
|
|
|
- } catch (Exception ex) { }
|
|
|
+ }
|
|
|
+ catch (Exception ex) { }
|
|
|
ScsResult UploadKTSLList = null;
|
|
|
try
|
|
|
{
|
|
@@ -558,203 +770,10 @@ namespace TEAMModelOS.Controllers.Third
|
|
|
GetProjectDiagnosis,
|
|
|
GetSchoolDiagnosis
|
|
|
});
|
|
|
-
|
|
|
- //return Ok(GetProjectInfoByTrainComID);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- ///
|
|
|
- /// </summary>
|
|
|
- /// <param name="request"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [ProducesDefaultResponseType]
|
|
|
- [HttpPost("bind")]
|
|
|
- [AllowAnonymous]
|
|
|
- public async Task<IActionResult> Bind(SSO sso) {
|
|
|
- try
|
|
|
- {
|
|
|
- Teacher teacher = null;
|
|
|
- if (string.IsNullOrEmpty(sso.id_token)) {
|
|
|
- return Ok(new
|
|
|
- {
|
|
|
- location = _option.Location,
|
|
|
- status = 2,
|
|
|
- });
|
|
|
- }
|
|
|
- var jwt = new JwtSecurityToken(sso.id_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);
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
- teacher = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>(id, new PartitionKey("Base"));
|
|
|
- //先检查绑定的平台是否已经被绑定
|
|
|
- //四川研训平台跳转隐式登录/或者绑定IES平台接入规范
|
|
|
- ScSSO scsso= sso.param.ToObject<ScSSO>();
|
|
|
- string sql = $"SELECT distinct value(c) FROM c join A1 in c.binds where A1.webid='{scsso.Webid}' and A1.tid='{scsso.tid}'";
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(queryText: sql,
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
|
|
|
- {
|
|
|
- teacher = item;
|
|
|
- break;
|
|
|
- }
|
|
|
- if (teacher != null)
|
|
|
- {
|
|
|
- if (teacher.id.Equals(id))
|
|
|
- {
|
|
|
- var bind = teacher.binds.Find(x => x.source.Equals($"{scsso.Webid}") && x.userid.Equals($"{scsso.tid}"));
|
|
|
- if (bind == null)
|
|
|
- {
|
|
|
- teacher.binds=new List<Teacher.ThirdBind> { new Teacher.ThirdBind { pxid = new HashSet<string> { $"{scsso.Pxid}" }, userid = $"{scsso.tid}", source = $"{scsso.Webid}", type = type } };
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (bind.pxid != null)
|
|
|
- {
|
|
|
- if (bind.pxid.Add(scsso.Pxid))
|
|
|
- {
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- bind.pxid = new HashSet<string> { scsso.Pxid };
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- return Ok(new
|
|
|
- {
|
|
|
- location = _option.Location,
|
|
|
- //账号已被别的醍摩豆id绑定
|
|
|
- status = 3,
|
|
|
- tmdid = teacher.id,
|
|
|
- name=teacher.name,
|
|
|
- tid = scsso.tid
|
|
|
- }) ;
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- teacher = new Teacher
|
|
|
- {
|
|
|
- id = id,
|
|
|
- pk = "Base",
|
|
|
- code = "Base",
|
|
|
- name = name?.ToString(),
|
|
|
- picture = picture?.ToString(),
|
|
|
- //创建账号并第一次登录IES5则默认赠送1G
|
|
|
- size = 1,
|
|
|
- defaultSchool = null,
|
|
|
- schools = new List<Teacher.TeacherSchool>(),
|
|
|
- binds= new List<Teacher.ThirdBind> { new Teacher.ThirdBind { pxid = new HashSet<string> { $"{scsso.Pxid}" }, userid = $"{scsso.tid}", source = $"{scsso.Webid}", type = type } }
|
|
|
- };
|
|
|
- var container = _azureStorage.GetBlobContainerClient(id);
|
|
|
- await container.CreateIfNotExistsAsync(PublicAccessType.None); //嘗試創建Teacher私有容器,如存在則不做任何事,保障容器一定存在
|
|
|
- teacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
|
|
|
- }
|
|
|
- return Ok(new
|
|
|
- {
|
|
|
- location = _option.Location,
|
|
|
- status = 200,
|
|
|
- });
|
|
|
-
|
|
|
- } catch (Exception ) {
|
|
|
- return Ok(new
|
|
|
- {
|
|
|
- location = _option.Location,
|
|
|
- status = 2,
|
|
|
- });
|
|
|
- }
|
|
|
|
|
|
+ //return Ok(GetProjectInfoByTrainComID);
|
|
|
}
|
|
|
- /// <summary>
|
|
|
- ///
|
|
|
- /// </summary>
|
|
|
- /// <param name="request"></param>
|
|
|
- /// <returns></returns>
|
|
|
|
|
|
- [HttpGet("sso")]
|
|
|
- [AllowAnonymous]
|
|
|
- public async Task<IActionResult> Sso([FromQuery] ScSSO sso)
|
|
|
- {
|
|
|
- var rurl = new StringBuilder($"https://{_option.HostName}/sso");
|
|
|
- string parmas = $"Pxid={sso.Pxid}&Webid={sso.Webid}&tid={sso.tid}&time={sso.time}";
|
|
|
- if (Md5Hash.GetMd5String(parmas).Equals($"{sso.Encrypt}"))
|
|
|
- {
|
|
|
- //四川研训平台跳转隐式登录/或者绑定IES平台接入规范
|
|
|
-
|
|
|
- long ssotime = long.Parse($"{sso.time}");
|
|
|
- long nowtime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
|
|
- if (nowtime - ssotime > 60 * 10)//10分钟有效期
|
|
|
- {
|
|
|
- // return Ok(new { status = 2, msg = "登录超时!" });
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return Redirect(rurl.Append($"?status=1").ToString());
|
|
|
- }
|
|
|
- Teacher teacher = null;
|
|
|
- //四川研训平台跳转隐式登录/或者绑定IES平台接入规范
|
|
|
- //string sql = $"SELECT distinct value(c) FROM c join A1 in c.binds where A1.pxid='{sso.Pxid}' and A1.webid='{sso.Webid}' and A1.tid='{sso.tid}'";
|
|
|
- string sql = $"SELECT distinct value(c) FROM c join A1 in c.binds where A1.source='{sso.Webid}' and A1.userid='{sso.tid}'";
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(queryText: sql,
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
|
|
|
- {
|
|
|
- teacher = item;
|
|
|
- break;
|
|
|
- }
|
|
|
- if (teacher == null)
|
|
|
- {
|
|
|
- return Redirect(rurl.Append($"?status=4¶m={sso.ToJsonString()}&type={type}&bindurl=sc/bind").ToString());
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- var url = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
|
|
|
- var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
- var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
|
|
|
- var location = _option.Location;
|
|
|
- (int code, string content) = await _accountHttpService.Implicit(clientID, clientSecret, location, $"{url}/oauth2/implicit",
|
|
|
- new Dictionary<string, string>()
|
|
|
- {
|
|
|
- { "grant_type", "implicit" },
|
|
|
- { "client_id",clientID },
|
|
|
- { "account",teacher.id },
|
|
|
- { "nonce",Guid.NewGuid().ToString()}
|
|
|
- });
|
|
|
- TmdidImplicit implicit_token = new TmdidImplicit();
|
|
|
- if (!string.IsNullOrEmpty(content) && code==200)
|
|
|
- {
|
|
|
- implicit_token = content.ToObject<TmdidImplicit>();
|
|
|
- var bind = teacher.binds.Find(x => x.userid.Equals(sso.tid) && x.source.Equals(sso.Webid));
|
|
|
- if (bind != null) {
|
|
|
- if (bind.pxid != null)
|
|
|
- {
|
|
|
- if (bind.pxid.Add(sso.Pxid))
|
|
|
- {
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- bind.pxid = new HashSet<string> { sso.Pxid };
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
|
|
|
- }
|
|
|
- }
|
|
|
- return Redirect(rurl.Append($"?status=200&id_token={implicit_token.id_token}&access_token={implicit_token.access_token}&expires_in={implicit_token.expires_in}&token_type={implicit_token.token_type}").ToString());
|
|
|
- }
|
|
|
- else {
|
|
|
- //绑定失效
|
|
|
- if (teacher.binds.IsNotEmpty()) {
|
|
|
- teacher.binds.RemoveAll(x => x.userid.Equals(sso.tid) && x.source.Equals(sso.Webid));
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher,teacher.id,new PartitionKey(teacher.code));
|
|
|
- }
|
|
|
- return Redirect(rurl.Append($"?status=4¶m={sso.ToJsonString()}&type={type}&bindurl=sc/bind").ToString());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
public record ScSSO{
|
|
|
public string Webid { get; set; }
|
|
|
public string Pxid { get; set; }
|