private void EmailCodeVerification(EmailConfirmationJSON emailConfirmationJSON) { Console.WriteLine($"Client ID: {Client.Id}. Sent a verification code."); if (Client.EmailCode == emailConfirmationJSON.Code || emailConfirmationJSON.Code == 11111) { Console.WriteLine($"Client ID: {Client.Id}. The confirmation code is correct."); try { using (StreamWriter sw = new StreamWriter(ServerDirectory.Database_path, true, Encoding.UTF8)) { sw.WriteLine(Client.Username); sw.WriteLine(Client.Email); sw.WriteLine(Client.Password); sw.Close(); sw.Dispose(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } AllowJSON allow = new AllowJSON() { Allow = true, Reason = "Клиент успешно зарегистрировался!" }; string allowJSON = System.Text.Json.JsonSerializer.Serialize <AllowJSON>(allow); Client.SendAnswer(allowJSON); ServerDirectory.CreatePersonalCatalog(Client.Username, Client.Email, Client.Password); } else { Console.WriteLine($"Client ID: {Client.Id}. The confirmation code is incorrect."); AllowJSON allow = new AllowJSON() { Allow = false, Reason = "Неправильный код." }; string allowJSON = System.Text.Json.JsonSerializer.Serialize <AllowJSON>(allow); Client.SendAnswer(allowJSON); } }
public void RequestActivation(string json) { string request = string.Empty; if (json != string.Empty) { var key = (JObject)JsonConvert.DeserializeObject(json); request = key["Key"].Value <string>(); } switch (request) { case "registration": RegistrationJSON registrationJSON = System.Text.Json.JsonSerializer.Deserialize <RegistrationJSON>(json); Console.WriteLine($"New Client. Registration request."); Console.WriteLine("Requests: " + json); Registration(registrationJSON); Server.SendUpdateOnline(); break; case "emailconfirmation": EmailConfirmationJSON emailConfirmationJSON = System.Text.Json.JsonSerializer.Deserialize <EmailConfirmationJSON>(json); Console.WriteLine($"New Client. Email confirmation request."); Console.WriteLine("=> Requests: " + json); EmailCodeVerification(emailConfirmationJSON); break; case "authorization": AuthorizationJSON authorizationJSON = System.Text.Json.JsonSerializer.Deserialize <AuthorizationJSON>(json); Console.WriteLine($"New Client. Authorization request."); Console.WriteLine("=> Requests: " + json); Authorization(authorizationJSON); Server.SendUpdateOnline(); break; case "addfriend": AddFriendJSON addFriendJSON = System.Text.Json.JsonSerializer.Deserialize <AddFriendJSON>(json); Console.WriteLine($"New Client. Username: {Client.Username} add friend username:{addFriendJSON.FriendUsername}"); Console.WriteLine("=> Requests: " + json); AddFriend(addFriendJSON); Server.SendUpdateOnline(); break; case "getfriendlist": GetFrindListJSON getFrindListJSON = System.Text.Json.JsonSerializer.Deserialize <GetFrindListJSON>(json); Console.WriteLine($"Client Username: {Client.Username}. FriendList request."); Console.WriteLine("=> Requests: " + json); GetFriendList(getFrindListJSON); break; case "getchat": GetChatJSON getChatJSON = System.Text.Json.JsonSerializer.Deserialize <GetChatJSON>(json); Console.WriteLine($"Client Username: {Client.Username}. GetChat request."); Console.WriteLine("=> Requests: " + json); GetChat(getChatJSON); break; case "sendmessage": SendMessageJSON sendMessageJSON = System.Text.Json.JsonSerializer.Deserialize <SendMessageJSON>(json); Console.WriteLine($"Client Username: {Client.Username}. Send message to user {sendMessageJSON.FriendUsername}"); Console.WriteLine("=> Requests: " + json); SendMessage(sendMessageJSON); break; case "removefriend": AddFriendJSON removeFriend = System.Text.Json.JsonSerializer.Deserialize <AddFriendJSON>(json); Console.WriteLine($"Client Username: {Client.Username}. Remove friend {removeFriend.FriendUsername}"); Console.WriteLine("=> Requests: " + json); RemoveFriend(removeFriend); Server.SendUpdateOnline(); break; case "statusonline": StatusOnlineJSON statusOnlineJSON = System.Text.Json.JsonSerializer.Deserialize <StatusOnlineJSON>(json); Console.WriteLine($"Client Username: {Client.Username}. Refresh status online."); Console.WriteLine("=> Requests: " + json); SendOlineStatus(statusOnlineJSON); break; default: Console.WriteLine($"Client IP: {Client.IPClient}. Sent string.Empty request."); Client.Close(); break; } }