public async Task <IActionResult> Verification([FromBody] BotLoginBody body) { foreach (var vtuberBot in _observer.Bots) { var groups = await vtuberBot.GetRequesterService().GetGroupsAsync(); if (groups.All(v => v.GroupId != body.GroupId)) { continue; } var code = StringExtensions.RandomString.Substring(0, 6); if (CodeDictionary.ContainsKey(body.GroupId)) { CodeDictionary.Remove(body.GroupId); } CodeDictionary.Add(body.GroupId, code); await vtuberBot.GetSendingService() .SendGroupMessageAsync(body.GroupId, "正在请求网页认证: " + code); return(Ok(new { message = "Please check verification message." })); } return(NotFound(new { message = "Group not found." })); }
public IActionResult Login([FromBody] BotLoginBody body, [FromHeader(Name = "User-Agent")] string userAgent) { if (!CodeDictionary.ContainsKey(body.GroupId)) { return(BadRequest(new { message = "Unknown session." })); } if (CodeDictionary[body.GroupId] != body.VerificationCode) { return(BadRequest(new { message = "Verification code error." })); } CodeDictionary.Remove(body.GroupId); var token = BotJwt.NewJwt(userAgent, body.GroupId); return(Json(new { message = "SUCCESS", accessToken = token })); }