private void LogIn() { List <Person> persons; if (!File.Exists(usersFile)) { MessageBox.Show("Oooops...Something was wrong!"); return; } using (CustomJsonSerializer <List <Person> > serializer = new CustomJsonSerializer <List <Person> >()) { persons = serializer.DeserializeFromFile(usersFile); } if (!persons.Any(p => p.AccountNumber == loginBox.Text && p.Password == passwordBox.Text)) { MessageBox.Show("Incorrect login or password!"); return; } currentPerson = persons.Find(p => p.AccountNumber == loginBox.Text); loginBox.Enabled = false; passwordBox.Enabled = false; signInButton.Enabled = false; signUpButton.Enabled = false; InitializeChainFromStore(); }
private void InitializeChainFromStore() { var path = Path.Combine(folderUsersData, ChainFilePattern()); using (CustomJsonSerializer <Chain> serializer = new CustomJsonSerializer <Chain>()) { Chain = serializer.DeserializeFromFile(path) ?? new Chain(); while (Chain.Blocks.Count(b => b.Index == 0) > 1) { Chain.Blocks.Remove(Chain.Blocks.First(b => b.Index == 0)); } } }
private void Registration() { if (loginBox.Text == "" || passwordBox.Text == "") { MessageBox.Show("Input login and password"); return; } if (!File.Exists(usersFile)) { File.Create(usersFile).Close(); } List <Person> persons; using (CustomJsonSerializer <List <Person> > serializer = new CustomJsonSerializer <List <Person> >()) { persons = serializer.DeserializeFromFile(usersFile) ?? new List <Person>(); if (persons.Any(p => p.AccountNumber == loginBox.Text)) { MessageBox.Show("This login currently exist!"); return; } persons.Add(new Person() { AccountNumber = loginBox.Text, Password = passwordBox.Text, Name = "", Surname = "" }); serializer.SerializeToFile(persons, usersFile); } var dataPath = Path.Combine(folderUsersData, $"{loginBox.Text}_chain.json"); if (!Directory.Exists(folderUsersData)) { Directory.CreateDirectory(folderUsersData); } var files = Directory.GetFiles(folderUsersData); File.Create(dataPath).Close(); if (files.Length > 0) { string chainInfo; using (StreamReader sr = new StreamReader(files.First())) { chainInfo = sr.ReadToEnd(); } using (StreamWriter sw = new StreamWriter(dataPath, false)) { sw.Write(chainInfo); } } LogIn(); }