From 32f2d5771f78f8d0c2cce5b00a341800031326d4 Mon Sep 17 00:00:00 2001 From: Daria Date: Thu, 28 Oct 2021 13:08:13 +0300 Subject: [PATCH] =?UTF-8?q?upd=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B0=20=D1=81=D0=BA=D0=B2=D0=BE=D0=B7=D0=BD=D0=BE=D0=B9?= =?UTF-8?q?=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/Registration/GetLoginCommand.cs | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/SvetoforVKBot/Models/Commands/Registration/GetLoginCommand.cs b/SvetoforVKBot/Models/Commands/Registration/GetLoginCommand.cs index 6bc228f..c560df4 100644 --- a/SvetoforVKBot/Models/Commands/Registration/GetLoginCommand.cs +++ b/SvetoforVKBot/Models/Commands/Registration/GetLoginCommand.cs @@ -11,6 +11,7 @@ using VkNet.Model.Keyboard; using VkNet.Model.RequestParams; using System.Linq; using SvetoforVKBot.Services; +using SvetoforVKBot.Models.Commands.LK; namespace SvetoforVKBot.Models.Commands.Registration { @@ -30,6 +31,35 @@ namespace SvetoforVKBot.Models.Commands.Registration string login = update.@object.message.text.Trim(); string message = ""; var user = db.Users.Single(usr => usr.chatId == chatId); + if (checkAuthStatus(login)) + { + user.isAuthorized = 1; + user.tag = "Подписчик - Регистрация - Пол"; + db.SaveChanges(); + + if (user.reg == 1) + { + ShowLKCommand showLK = new ShowLKCommand(); + showLK.Execute(update, client, db); + } + else + { + keyboardBuilder + .AddButton("М", "selectGender-1", KeyboardButtonColor.Primary) + .AddButton("Ж", "selectGender-2", KeyboardButtonColor.Primary) + .AddLine() + .AddButton("Отменить", "startPL", KeyboardButtonColor.Default); + + @params.Keyboard = keyboardBuilder.Build(); + @params.UserId = chatId; + @params.Message = //1 шаг из 4. + "✅ Авторизация прошла успешно.\n" + + "Выберите на клавиатуре внизу или напишите пол в формате \"М\" или \"Ж\""; + @params.RandomId = GetRandomId(); + client.Messages.SendAsync(@params); + } + return; + } string pincode = PasswordService.GeneratePassword(); string hash = PasswordService.CreateMD5(pincode + chatId.ToString()); message = $"Ваш код подтверждения: {pincode}"; @@ -81,5 +111,37 @@ namespace SvetoforVKBot.Models.Commands.Registration return BitConverter.ToInt32(intBytes, 0); } + + public static string StringSha256Hash(string text) => + string.IsNullOrEmpty(text) ? string.Empty : BitConverter.ToString(new System.Security.Cryptography.SHA256Managed().ComputeHash(System.Text.Encoding.UTF8.GetBytes(text))). + Replace("-", string.Empty); + + private bool checkAuthStatus(string login) + { + HttpClient client = new HttpClient(); + string sault = @"{ YDB * mhB * *0SuQ([WU.TSuJt.j47}UW{"; + string uri = String.Format("https://new.vyatsu.ru/api/user_tmp_id/get/?user={0}&hash={1}", login, StringSha256Hash(login + sault)); + var result = client.GetAsync(uri); + result.Wait(); + HttpResponseMessage resp = result.Result; + if (resp.StatusCode == System.Net.HttpStatusCode.OK) + { + var bodyreader = resp.Content.ReadAsStringAsync(); + bodyreader.Wait(); + string body = bodyreader.Result; + if (body.Contains(login)) + return true; + } + return false; + } + + private void getAuthStatus(string login) + { + HttpClient client = new HttpClient(); + string sault = @"{ YDB * mhB * *0SuQ([WU.TSuJt.j47}UW{"; + string uri = String.Format("https://new.vyatsu.ru/api/user_tmp_id/get/?user={0}&hash={1}", login, StringSha256Hash(login + sault)); + var result = client.GetAsync(uri); + } + } } \ No newline at end of file