private void AdminSetup() { var acc0 = new AdminAccount(0, "admin-pete-w", "password", "Pete Wilkinson", false); AccountList accList = new AccountList(true); accList.AddAdminAccount(acc0); accList.SaveAdminData(); }
/// <summary> /// This function logs out a user from the system. /// </summary> /// <param name="accountId">The user ID to log out.</param> /// <returns>returns -1 to show the user has been logged out. </returns> public int LogoutAdmin(int accountId) { var accs = Persister.ReadFromBinaryFile <List <AdminAccount> >(@"AdminAccounts.txt"); foreach (var account in accs) { if (account._accountId == accountId) { account._loginStatus = false; var temp = new AccountList(accs); temp.SaveAdminData(); return(-1); } } return(-1); }
/// <summary> /// This function takes the username and password entered by the user. /// It then calls the function to read the Accounts file; this then verifies the entered details /// against the stored details. If both match, it returns the accountId. /// </summary> /// <param name="username">A string containing the username the user entered when attempting to log in.</param> /// <param name="password">A string containing the password the user entered when attempting to log in.</param> /// <returns>If successful, the accountId, else -1 to signal a failure.</returns> public int VerifyLogin(string username, string password) { if (username.StartsWith("admin")) { var accs = Persister.ReadFromBinaryFile <List <AdminAccount> >(@"AdminAccounts.txt"); foreach (var account in accs) { if (account._username == username && account._password == password) { if (account._loginStatus) { return(-2); } account._loginStatus = true; var temp = new AccountList(accs); temp.SaveAdminData(); return(account._accountId); } } return(-1); } else { var accs = Persister.ReadFromBinaryFile <List <CustomerAccount> >(@"Accounts.txt"); foreach (var account in accs) { if (account._username == username && account._password == password) { if (account._loginStatus) { return(-2); } account._loginStatus = true; var temp = new AccountList(accs); temp.SaveCustomerData(); return(account._accountId); } } return(-1); } }