|
@@ -141,7 +141,6 @@ namespace TEAMModeBI.Controllers
|
|
|
[AllowAnonymous]
|
|
|
public async Task<IActionResult> DingLogin(JsonElement jsonElement)
|
|
|
{
|
|
|
- string temp_mess = null;
|
|
|
//state 是前端传入的,钉钉并不会修改,比如有多种登录方式的时候,一个登录方法判断登录方式可以进行不同的处理。
|
|
|
try
|
|
|
{
|
|
@@ -149,16 +148,10 @@ namespace TEAMModeBI.Controllers
|
|
|
string str_appSecret = _configuration["DingDingAuth:appSecret"];
|
|
|
if (string.IsNullOrWhiteSpace(str_appKey) || string.IsNullOrWhiteSpace(str_appSecret))
|
|
|
{
|
|
|
- return BadRequest("请先配置钉钉扫码登录信息!");
|
|
|
+ return Ok(new { status = 0, message = "扫码登录失败" });
|
|
|
}
|
|
|
//自己传的code
|
|
|
if (!jsonElement.TryGetProperty("code", out JsonElement LoginTempCode)) return BadRequest();
|
|
|
- string loginTempCode = LoginTempCode.ToString();
|
|
|
- //判断参数是否为空
|
|
|
- if (string.IsNullOrEmpty(LoginTempCode.ToString()))
|
|
|
- {
|
|
|
- return BadRequest("temp code error");
|
|
|
- }
|
|
|
|
|
|
//获取企业内部应用的accessToken
|
|
|
DefaultDingTalkClient Iclient = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
|
|
@@ -169,17 +162,17 @@ namespace TEAMModeBI.Controllers
|
|
|
OapiGettokenResponse tokenResponse = Iclient.Execute(request);
|
|
|
if (tokenResponse.IsError)
|
|
|
{
|
|
|
- return Ok(new { ddbinds = $"status=-1"});
|
|
|
+ return Ok(new { status = 0, message = "扫码登录失败" });
|
|
|
}
|
|
|
|
|
|
string access_token = tokenResponse.AccessToken;
|
|
|
//获取临时授权码 获取授权用户的个人信息
|
|
|
DefaultDingTalkClient clientinfo = new DefaultDingTalkClient("https://oapi.dingtalk.com/sns/getuserinfo_bycode");
|
|
|
- OapiSnsGetuserinfoBycodeRequest req = new OapiSnsGetuserinfoBycodeRequest() { TmpAuthCode = loginTempCode }; //通过扫描二维码,跳转到指定的Url后,向Url中追加Code临时授权码
|
|
|
+ OapiSnsGetuserinfoBycodeRequest req = new OapiSnsGetuserinfoBycodeRequest() { TmpAuthCode = $"{LoginTempCode}" }; //通过扫描二维码,跳转到指定的Url后,向Url中追加Code临时授权码
|
|
|
OapiSnsGetuserinfoBycodeResponse response = clientinfo.Execute(req, str_appKey, str_appSecret);
|
|
|
if (response.IsError)
|
|
|
{
|
|
|
- return BadRequest();
|
|
|
+ return Ok(new { status = 0, message = "扫码登录失败" });
|
|
|
}
|
|
|
|
|
|
string unionid = response.UserInfo.Unionid;
|
|
@@ -188,7 +181,7 @@ namespace TEAMModeBI.Controllers
|
|
|
OapiUserGetbyunionidResponse byunionidResponse = client2.Execute(byunionidRequest, access_token);
|
|
|
if (byunionidResponse.IsError)
|
|
|
{
|
|
|
- return BadRequest();
|
|
|
+ return Ok(new { status = 0, message = "扫码登录失败" });
|
|
|
}
|
|
|
|
|
|
// 根据userId获取用户信息
|
|
@@ -203,7 +196,7 @@ namespace TEAMModeBI.Controllers
|
|
|
OapiV2UserGetResponse v2GetResponse = client3.Execute(v2GetRequest, access_token);
|
|
|
if (v2GetResponse.IsError)
|
|
|
{
|
|
|
- return BadRequest();
|
|
|
+ return Ok(new { status = 0, message = "扫码登录失败" });
|
|
|
}
|
|
|
|
|
|
var DDbind = v2GetResponse.Result;
|
|
@@ -230,7 +223,7 @@ namespace TEAMModeBI.Controllers
|
|
|
}
|
|
|
if (teacher == null)
|
|
|
{
|
|
|
- return Ok(new { status = $"0", dingDingBind = $"{dingDingBind.ToJsonString()}" });
|
|
|
+ return Ok(new { status = 1, dingDingBind = $"{dingDingBind.ToJsonString()}" });
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -255,15 +248,15 @@ namespace TEAMModeBI.Controllers
|
|
|
var ddbind = teacher.ddbinds.Find(x => x.userid.Equals($"{dingDingBind.userid}") && x.unionid.Equals($"{dingDingBind.unionid}"));
|
|
|
if (ddbind != null)
|
|
|
{
|
|
|
- return Ok(new { status = $"200", id_token = $"{implicit_token.id_token.ToJsonString()}&access_token={implicit_token.access_token}&expires_in={implicit_token.expires_in}&token_type={implicit_token.token_type}" });
|
|
|
+ return Ok(new { status = 200, id_token = $"{implicit_token.id_token.ToJsonString()}", access_token = $"{implicit_token.access_token}", expires_in = $"{implicit_token.expires_in}", token_type = $"{implicit_token.token_type}" });
|
|
|
}
|
|
|
}
|
|
|
- return Ok(new { status = $"1", param = $"{dingDingBind.ToJsonString()}&type={type}&bindurl=sc/bind" });
|
|
|
+ return Ok(new { status = 1, dingdinginfo = $"{dingDingBind.ToJsonString()}" });
|
|
|
}
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
- return BadRequest($"{temp_mess }{e.Message}{e.StackTrace} ");
|
|
|
+ return Ok(new { status = 1, message = "code失效" });
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -287,38 +280,19 @@ namespace TEAMModeBI.Controllers
|
|
|
HttpResponseMessage responseMessage = await httpClient.PostAsync($"{smsurl}/service/sandsms/pin", content);
|
|
|
if (responseMessage.StatusCode == HttpStatusCode.OK)
|
|
|
{
|
|
|
- //string responseBody = responseMessage.Content.ReadAsStringAsync().Result;
|
|
|
- JObject temp_job = (JObject)JsonConvert.DeserializeObject(responseMessage.Content.ReadAsStringAsync().Result);//转换为json对象
|
|
|
- int temp_error = int.Parse(temp_job["error"].ToString());
|
|
|
- string status = null;
|
|
|
- string message = null;
|
|
|
- switch (temp_error)
|
|
|
+ string str_json = await responseMessage.Content.ReadAsStringAsync();
|
|
|
+ if (string.IsNullOrEmpty($"{str_json}"))
|
|
|
{
|
|
|
- case 1:
|
|
|
- status = $"1";
|
|
|
- message = $"查无账号" ;
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- status = $"2";
|
|
|
- message = $"账号已存在";
|
|
|
- break;
|
|
|
-
|
|
|
- case 3:
|
|
|
- status = $"3";
|
|
|
- message = $"验证PIN码失败" ;
|
|
|
- break;
|
|
|
-
|
|
|
- case 4:
|
|
|
- status = $"4";
|
|
|
- message = $"剩最后一个第三方" ;
|
|
|
- break;
|
|
|
+ return Ok(new { status =200, message="发送成功" });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ JsonElement json = str_json.ToObject<JsonElement>();
|
|
|
+ return Ok( json );
|
|
|
}
|
|
|
- return Ok(new { status, message });
|
|
|
-
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- return Ok(new { status = $"0" , message=$"发送失败!" });
|
|
|
+ return Ok(new { status = 0 , message="发送失败!" });
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -333,52 +307,32 @@ namespace TEAMModeBI.Controllers
|
|
|
{
|
|
|
if (!jsonElement.TryGetProperty("mobile", out JsonElement mobile)) return BadRequest();
|
|
|
if (!jsonElement.TryGetProperty("Authorization_Pin", out JsonElement sms)) return BadRequest();
|
|
|
- if (!jsonElement.TryGetProperty("param", out JsonElement param)) return BadRequest();
|
|
|
|
|
|
string smsurl = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
|
|
|
HttpClient httpClient = new HttpClient();
|
|
|
- string str_json = "{'Authorization_Pin':'"+ sms + "'}"; //
|
|
|
- JObject temp_job = (JObject)JsonConvert.DeserializeObject(str_json);
|
|
|
- var content = new StringContent(JsonConvert.SerializeObject(temp_job), Encoding.UTF8, "application/json");
|
|
|
+ var temp_job = new { Authorization_Pin = sms };
|
|
|
+ var content = new StringContent(temp_job.ToJsonString(), Encoding.UTF8, "application/json");
|
|
|
HttpResponseMessage responseMessage = await httpClient.PostAsync($"{smsurl}/service/verifiy/pin", content);
|
|
|
|
|
|
- Teacher teacher = new Teacher();
|
|
|
if (responseMessage.StatusCode == HttpStatusCode.OK)
|
|
|
{
|
|
|
- //string responseBody = responseMessage.Content.ReadAsStringAsync().Result;
|
|
|
- JObject tempok_job = (JObject)JsonConvert.DeserializeObject(responseMessage.Content.ReadAsStringAsync().Result);
|
|
|
- string tempmobile= tempok_job["resule"].ToString();
|
|
|
- string[] mobules = tempmobile.Split("-");
|
|
|
- string temp_mobile =mobules[1];
|
|
|
+ string responseBody = await responseMessage.Content.ReadAsStringAsync();
|
|
|
+ var json = responseBody.ToObject<JsonElement>().GetProperty("resule").ToString();
|
|
|
+
|
|
|
+ string[] mobules = json.Split("-");
|
|
|
+ string temp_mobile = mobules.Length >= 2 ? mobules[1] : mobules[0];
|
|
|
if (mobile.ToString().Equals(temp_mobile))
|
|
|
{
|
|
|
- ddbinds ddbind_list = param.ToObject<ddbinds>();
|
|
|
- string sql = $"select distinct value(c) from c join A1 in c.ddbinds where A1.userid='{ddbind_list.userid}' AND A1.unionid ='{ddbind_list.unionid}'";
|
|
|
- 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 Ok(new { status = $"3", message = "通过钉钉信息没有查到该教师" });
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return Ok(new { status = $"3", message = "通过钉钉信息没有查到该教师" });
|
|
|
- }
|
|
|
+ return Ok(new { status = 200, message = "手机号和验证码验证都过了" });
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- return Ok(new { status = $"1", message = "手机号码不正确" });
|
|
|
+ return Ok(new { status = 1, message = "手机号码不正确" });
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- return Ok(new { status = $"0" , responseMessage = responseMessage});
|
|
|
+ return Ok(new { status = 0 , message = "发送状态错误"});
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -388,115 +342,227 @@ namespace TEAMModeBI.Controllers
|
|
|
/// <param name="ddbindparam"></param>
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
- [HttpGet("bind")]
|
|
|
+ [HttpPost("bind")]
|
|
|
[AllowAnonymous]
|
|
|
- public async Task<IActionResult> Bind(ddbindparam ddbindparam)
|
|
|
+ public async Task<IActionResult> Bind(JsonElement jsonElement)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- Teacher teacher = null;
|
|
|
- var jwt = new JwtSecurityToken(ddbindparam.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"));
|
|
|
- ddbinds ddbinds = ddbindparam.param.ToObject<ddbinds>(); //将json数据转换为实体类
|
|
|
- string sql = $"select distinct value(c) from c join A1 in c.ddbinds where A1.userid='{ddbinds.userid}' AND A1.unionid ='{ddbinds.unionid}'";
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(queryText: sql,
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
|
|
|
+ jsonElement.TryGetProperty("mobile", out JsonElement mobile);
|
|
|
+ jsonElement.TryGetProperty("idToken", out JsonElement idToken);
|
|
|
+ if (!jsonElement.TryGetProperty("param", out JsonElement param)) return BadRequest();
|
|
|
+
|
|
|
+ HttpClient httpClient = new HttpClient();
|
|
|
+ Teacher teacher = new Teacher();
|
|
|
+ ddbinds ddbinds = param.ToObject<ddbinds>(); //将json数据转换为实体类
|
|
|
+ TmdidImplicit implicit_token = new TmdidImplicit();
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty($"{mobile}"))
|
|
|
{
|
|
|
- teacher = item;
|
|
|
- break;
|
|
|
+
|
|
|
+ List<JsonElement> mbs = new List<JsonElement>() { mobile };
|
|
|
+ string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
|
|
|
+ var content = new StringContent(mbs.ToJsonString(), Encoding.UTF8, "application/json");
|
|
|
+ HttpResponseMessage responseMessage = await httpClient.PostAsync(url, content);
|
|
|
+ if (responseMessage.StatusCode == HttpStatusCode.OK)
|
|
|
+ {
|
|
|
+ string responseBody = await responseMessage.Content.ReadAsStringAsync();
|
|
|
+ List<JsonElement> json_id = responseBody.ToObject<List<JsonElement>>();
|
|
|
+ string temp_id = null;
|
|
|
+ if (json_id.IsNotEmpty())
|
|
|
+ {
|
|
|
+ temp_id = json_id[0].GetProperty("id").ToString();
|
|
|
+ }
|
|
|
+
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ teacher = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>(temp_id, new PartitionKey("Base"));
|
|
|
+
|
|
|
+ string sql = $"SELECT distinct value(c) FROM c join A1 in c.ddbinds where A1.userid='{ddbinds.userid}' and A1.unionid='{ddbinds.unionid}'";
|
|
|
+ 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(temp_id))
|
|
|
+ {
|
|
|
+ var infourl = _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 temp_content) = await _aoreAPIHttpService.Implicit(clientID, clientSecret, location, $"{infourl}/oauth2/implicit", new Dictionary<string, string>()
|
|
|
+ {
|
|
|
+ { "grant_type", "implicit" },
|
|
|
+ { "client_id",clientID },
|
|
|
+ { "account",teacher.id },
|
|
|
+ { "nonce",Guid.NewGuid().ToString()}
|
|
|
+ });
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty(temp_content) && code == 200)
|
|
|
+ {
|
|
|
+ implicit_token = temp_content.ToObject<TmdidImplicit>();
|
|
|
+ var ddbind = teacher.ddbinds.Find(x => x.userid.Equals($"{ddbinds.userid}") && x.unionid.Equals($"{ddbinds.unionid}"));
|
|
|
+ if (ddbind == null)
|
|
|
+ {
|
|
|
+ teacher.ddbinds = new List<DingDingBind> { new DingDingBind { type = $"{type}", unionid = $"{ddbinds.unionid}", userid = $"{ddbinds.userid}", name = $"{ddbinds.name}", mobile = $"{ddbinds.mobile}", title = $"{ddbinds.title}", DeptIdList = ddbinds.DeptIdList, jobNumber = $"{ddbinds.jobNumber}" } };
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (teacher.ddbinds.IsNotEmpty())
|
|
|
+ {
|
|
|
+ teacher.ddbinds.RemoveAll(x => x.userid.Equals(ddbinds.userid) && x.unionid.Equals(ddbinds.unionid));
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
|
|
|
+ }
|
|
|
+ return Ok(new { status = 1, message = "绑定失败" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new
|
|
|
+ {
|
|
|
+ location = _option.Location,
|
|
|
+ //账号已被别的醍摩豆id绑定
|
|
|
+ status = 2,
|
|
|
+ tmdid = teacher.id,
|
|
|
+ name = teacher.name,
|
|
|
+ ddid = ddbinds.userid,
|
|
|
+ ddname = ddbinds.name
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ teacher = new Teacher
|
|
|
+ {
|
|
|
+ id = temp_id,
|
|
|
+ pk = "Base",
|
|
|
+ code = "Base",
|
|
|
+ name = temp_id,
|
|
|
+ //创建账号并第一次登录IES5则默认赠送1G
|
|
|
+ size = 1,
|
|
|
+ defaultSchool = null,
|
|
|
+ schools = new List<Teacher.TeacherSchool>(),
|
|
|
+ ddbinds = new List<DingDingBind> { new DingDingBind { type = $"{type}", unionid = $"{ddbinds.unionid}", userid = $"{ddbinds.userid}", name = $"{ddbinds.name}", mobile = $"{ddbinds.mobile}", title = $"{ddbinds.title}", DeptIdList = ddbinds.DeptIdList, jobNumber = $"{ddbinds.jobNumber}" } }
|
|
|
+ };
|
|
|
+ var container = _azureStorage.GetBlobContainerClient(temp_id);
|
|
|
+ await container.CreateIfNotExistsAsync(PublicAccessType.None); //尝试创建Teacher私有容器,如存在则不做任何事,保障容器一定存在
|
|
|
+ teacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { status = 3, message = "通过手机号查询用户信息异常" });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if (teacher != null)
|
|
|
+ if (!string.IsNullOrEmpty($"{idToken}"))
|
|
|
{
|
|
|
- if (teacher.id.Equals(id))
|
|
|
+ var jwt = new JwtSecurityToken($"{idToken}");
|
|
|
+ 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"));
|
|
|
+ string sql = $"select distinct value(c) from c join A1 in c.ddbinds where A1.userid='{ddbinds.userid}' AND A1.unionid ='{ddbinds.unionid}'";
|
|
|
+ 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)
|
|
|
{
|
|
|
- var ddbind = teacher.ddbinds.Find(x => x.userid.Equals($"{ddbinds.userid}") && x.unionid.Equals($"{ddbinds.unionid}"));
|
|
|
- if (ddbind == null)
|
|
|
+ if (teacher.id.Equals(id))
|
|
|
{
|
|
|
- teacher.ddbinds = new List<DingDingBind> { new DingDingBind { type = $"{type}", unionid = $"{ddbind.unionid}", userid = $"{ddbind.userid}", name = $"{ddbind.name}", mobile = $"{ddbind.mobile}", title = $"{ddbind.title}", DeptIdList = ddbind.DeptIdList, jobNumber = $"{ddbind.jobNumber}" } };
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
|
|
|
+ var ddbind = teacher.ddbinds.Find(x => x.userid.Equals($"{ddbinds.userid}") && x.unionid.Equals($"{ddbinds.unionid}"));
|
|
|
+ if (ddbind == null)
|
|
|
+ {
|
|
|
+ teacher.ddbinds = new List<DingDingBind> { new DingDingBind { type = $"{type}", unionid = $"{ddbind.unionid}", userid = $"{ddbind.userid}", name = $"{ddbind.name}", mobile = $"{ddbind.mobile}", title = $"{ddbind.title}", DeptIdList = ddbind.DeptIdList, jobNumber = $"{ddbind.jobNumber}" } };
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
|
|
|
+ }
|
|
|
+
|
|
|
+ return Ok(new
|
|
|
+ {
|
|
|
+ status = 200,
|
|
|
+ idToken = idToken,
|
|
|
+ teacher = teacher,
|
|
|
+ location = _option.Location,
|
|
|
+ });
|
|
|
}
|
|
|
- else
|
|
|
+ else
|
|
|
{
|
|
|
- return Ok(new { binds = $"status=1$location={_option.Location}" });
|
|
|
+ return Ok(new
|
|
|
+ {
|
|
|
+ location = _option.Location,
|
|
|
+ //账号已被别的醍摩豆id绑定
|
|
|
+ status = 2,
|
|
|
+ tmdid = teacher.id,
|
|
|
+ name = teacher.name,
|
|
|
+ userid = ddbinds.userid,
|
|
|
+ ddname = ddbinds.name
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
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>(),
|
|
|
+ ddbinds = new List<DingDingBind> { new DingDingBind { type = $"{type}", unionid = $"{ddbinds.unionid}", userid = $"{ddbinds.userid}", name = $"{ddbinds.name}", mobile = $"{ddbinds.mobile}", title = $"{ddbinds.title}", DeptIdList = ddbinds.DeptIdList, jobNumber = $"{ddbinds.jobNumber}" } },
|
|
|
+ };
|
|
|
+
|
|
|
+ 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
|
|
|
{
|
|
|
+ status = 200,
|
|
|
+ idToken = id,
|
|
|
+ teacher = teacher,
|
|
|
location = _option.Location,
|
|
|
- //账号已被别的醍摩豆id绑定
|
|
|
- status = 3,
|
|
|
- tmdid = teacher.id,
|
|
|
- name = teacher.name,
|
|
|
- userid = ddbinds.userid,
|
|
|
- ddname = ddbinds.name
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
- 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>(),
|
|
|
- ddbinds = new List<DingDingBind> { new DingDingBind { type = $"{type}", unionid = $"{ddbinds.unionid}", userid = $"{ddbinds.userid}", name = $"{ddbinds.name}", mobile = $"{ddbinds.mobile}", title = $"{ddbinds.title}", DeptIdList = ddbinds.DeptIdList, jobNumber = $"{ddbinds.jobNumber}" } },
|
|
|
- };
|
|
|
-
|
|
|
- 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"));
|
|
|
- }
|
|
|
+
|
|
|
+ string temp_idToken = string.IsNullOrEmpty($"{idToken}") ? implicit_token.id_token : idToken.ToString();
|
|
|
+
|
|
|
return Ok(new
|
|
|
{
|
|
|
- location = _option.Location,
|
|
|
status = 200,
|
|
|
+ idToken = temp_idToken,
|
|
|
+ teacher = teacher,
|
|
|
+ location = _option.Location,
|
|
|
});
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
return Ok(new
|
|
|
{
|
|
|
- location = _option.Location,
|
|
|
- status = 2
|
|
|
+ status = 4,
|
|
|
+ location = _option.Location
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public record ddbindparam
|
|
|
- {
|
|
|
- /// <summary>
|
|
|
- /// 绑定类型 ddteammodel
|
|
|
- /// </summary>
|
|
|
- public string type { get; set; }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 钉钉参数
|
|
|
- /// </summary>
|
|
|
- public string param { get; set; }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 醍摩豆参数
|
|
|
- /// </summary>
|
|
|
- public string id_token { get; set; }
|
|
|
- }
|
|
|
-
|
|
|
public record ddbinds
|
|
|
{
|
|
|
+ public string type { get; set; }
|
|
|
/// <summary>
|
|
|
/// 钉钉unionid
|
|
|
/// </summary>
|