//create a new user node public void newUserNode(EvilCarUser user) { string type; string nodeCollection; XmlNode collection; //differ between Admin and Manager if (user.Type == EvilCarUser.UserType.ADMIN) { type = "admin"; nodeCollection = "userDB/adminCollection"; } else if (user.Type == EvilCarUser.UserType.FLEET_MANAGER) { type = "manager"; nodeCollection = "userDB/managerCollection"; } else { type = "customer"; nodeCollection = "customerCollection"; } collection = doc.SelectSingleNode(nodeCollection); //Set attributes from user object XmlNode newNode = doc.CreateNode(XmlNodeType.Element, type, null); XmlAttribute xa = doc.CreateAttribute("firstName"); xa.Value = user.FirstName; XmlAttribute xb = doc.CreateAttribute("lastName"); xb.Value = user.LastName; XmlAttribute xc = doc.CreateAttribute("guid"); xc.Value = user.UserID.ToString(); XmlAttribute xd = doc.CreateAttribute("userName"); xd.Value = user.UserName; //Only Admins and Manager have passwords if (user.Type != EvilCarUser.UserType.CUSTOMER) { XmlAttribute xe = doc.CreateAttribute("password"); xe.Value = user.Password; newNode.Attributes.Append(xe); } newNode.Attributes.Append(xa); newNode.Attributes.Append(xb); newNode.Attributes.Append(xc); newNode.Attributes.Append(xd); collection.AppendChild(newNode); doc.Save(location); }
/* * Includes all functions to do with the administration of fleet Managers * - CreateNewAFleetManager * - ReadfleetManagerInfos * - Delete FleetManager * - UpdateFleetManager */ public void CreateNewFleetManager() { Console.WriteLine("You are creating a new Fleet Manager."); EvilCarUser manager = newUser(EvilCarUser.UserType.FLEET_MANAGER); try { fleetManager.assignFleetManager(manager.UserID); } catch (Exception ex) { Console.WriteLine(ex.Message); deleteUser("manager", manager.UserName); } }
public EvilCarUser deleteUser(string type, string userName) { try { EvilCarUser user = xmlManager.getUserInformation(type, userName); xmlManager.removeNode(type, "guid", user.UserID.ToString()); return(user); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine("Something went wrong. Please check your spelling."); return(null); } }
public EvilCarUser UserLogin() { EvilCarUser user = new EvilCarUser(); string username = ""; string password = null; username = inputService.validInput("Please enter your username: "******"Please enter your password: "******"\n"); if (decodePassword(user.Password) == password) { Console.WriteLine("Logged in!"); return(user); } else { Console.WriteLine("Invalid LogIn. Please try again."); return(null); } }
//find a user based on their userName and their type (customer, manager, admin) //return the found user public EvilCarUser getUserInformation(string type, string searchInput) { EvilCarUser user = new EvilCarUser(); try { user.FirstName = findInformation(type, "userName", searchInput, "firstName").ToString(); user.LastName = findInformation(type, "userName", searchInput, "lastName").ToString(); user.UserID = new Guid(findInformation(type, "userName", searchInput, "guid")); user.UserName = searchInput; //Customers can't auth against system => no need for a password if (type != "customer") { user.Password = findInformation(type, "userName", searchInput, "password").ToString(); } } catch (Exception ex) { } return(user); }
/*User Management Functions * Handle input and communication with user * interface between user communication and xml "database" conversion */ //Create new user based on userType passed as parameter //automatically generate unique username public EvilCarUser newUser(EvilCarUser.UserType type) { EvilCarUser newUser = new EvilCarUser(); newUser.FirstName = inputServices.validInput("Please enter their first name."); newUser.LastName = inputServices.validInput("Enter their last Name."); newUser.UserName = inputServices.generateUsername(newUser.FirstName, newUser.LastName); Console.WriteLine("Automatically generate username is, {0}.", newUser.UserName); newUser.Type = type; newUser.UserID = Guid.NewGuid(); if (type != EvilCarUser.UserType.CUSTOMER) { newUser.Password = loginManager.encodePassword("StartPassword"); } xmlManager.newUserNode(newUser); Console.WriteLine("Succesfully created a new {0} User: {1}, {2} ({3})", type, newUser.LastName, newUser.FirstName, newUser.UserName); return(newUser); }
static void Main(string[] args) { EvilCarUser CurrentUser = null; LoginManager loginManager = new LoginManager(); Console.Write("Welcome to the evil car management portal. Please login to continue.\n"); while (CurrentUser == null) { CurrentUser = loginManager.UserLogin(); } if (CurrentUser.Type == EvilCarUser.UserType.ADMIN) { UserMenuAdminView menu = new UserMenuAdminView(CurrentUser.UserID); while (true) { menu.Start(); } } else if (CurrentUser.Type == EvilCarUser.UserType.FLEET_MANAGER) { UserMenuManagerView menu = new UserMenuManagerView(CurrentUser.UserID); while (true) { menu.Start(); } } else { Console.WriteLine("You don't have access to the admin or manager options. Please contact your system administator."); } Console.Read(); }
public void deleteFleetManager() { string userName; Console.WriteLine("You are abbout to premanently delete a fleet manager."); userName = inputService.validInput("Please enter the userName of the manager."); EvilCarUser user = fetchUserInfo("manager", userName); if (user != null) { try { fleetManager.removeNode("manager", "guid", user.UserID.ToString()); deleteUser("manager", user.UserName); } catch (Exception ex) { Console.WriteLine(ex.Message); return; } Console.WriteLine("Successfully deleted {0} {1}", user.FirstName, user.LastName); } }
//Access User in DB file via their id and change their information //in case of empty id a username is required to find the user //userType is passed as parameter to ensure a user can't find users of types they're not supposed to view public async void changeUserInfo(string type, Guid id) { char selection; Guid userId = id; string newValue = ""; string changeParam = ""; if (id == Guid.Empty) { string userName; userName = inputServices.validInput("Enter the username for the user whose information needs changing."); EvilCarUser user = xmlManager.getUserInformation(type, userName); userId = user.UserID; } if (userId == Guid.Empty) { Console.WriteLine("User doesn't exist"); return; } if (type != "customer") { Console.WriteLine("What info needs changining?\n 1.First Name 2.Last Name 3.User Name 4.Password"); } else { Console.WriteLine("What info needs changining?\n 1.First Name 2.Last Name 3.User Name"); } selection = Console.ReadKey().KeyChar; Console.WriteLine("\nEnter the new value."); if (selection == '1') { newValue = Console.ReadLine(); changeParam = "firstName"; } else if (selection == '2') { newValue = Console.ReadLine(); changeParam = "lastName"; } else if (selection == '3') { newValue = Console.ReadLine(); changeParam = "userName"; } else if (selection == '4' && type != "customer") { newValue = Console.ReadLine(); changeParam = "password"; newValue = loginManager.encodePassword(newValue); } else { Console.WriteLine("Invalid selection"); return; } //Change entry in XML file use id to find user and param to change correct info xmlManager.changeInformationBasedOnGuid(type, userId.ToString(), changeParam, newValue); if (selection == '4') { await emailManager.sendMailToManager(); } }