/// <summary> /// Method for creating abbility list for user /// </summary> /// <param name="user">Logged user</param> /// <returns>list of UserAbbilities</returns> static private List <UserAbbilities> BuildAbbilityList(User user) { List <UserAbbilities> abbilities = new List <UserAbbilities>(); foreach (int i in user.RolesId) { AbbilitiesAdd(abbilities, UserControls.GetRoleById(i)); } return(abbilities); }
/// <summary> /// describes button that creates new user /// </summary> /// <param name="sender">sender of event</param> /// <param name="e">event data</param> private void NewUser_Click(object sender, EventArgs e) { if ((login.Text.Length < 5) || UserControls.WrongSymbols(login.Text) || (password.Text.Length < 5) || UserControls.WrongSymbols(password.Text)) { MessageBox.Show("Wrong login or password. Not enought or wrong symbols"); } else { UserControls.AddNewUser(login.Text, password.Text); MessageBox.Show("User Created"); } }
/// <summary> /// Prints list of users. /// </summary> private static void ShowAllUsers() { List <User> AllUsers = new List <User>(); if (UserControls.LoadBaseUsers(out AllUsers)) { foreach (User user in AllUsers) { Console.WriteLine(user.ToString()); } } }
/// <summary> /// Deleting user from base. /// </summary> private static void DeleteUser() { Console.WriteLine("Input ID user to delete."); int idDel = new int(); idDel = Convert.ToInt32(Console.ReadLine()); if (UserControls.DeleteUser(idDel)) { Console.WriteLine("Success!"); } else { Console.WriteLine("Wrong ID!"); } }
/// <summary> /// Adding of new user /// </summary> private static void AddNewUser() { string login; string password; Console.WriteLine("Write login for new user:"******"Password: "******"Enter 0 to stop adding 1 to add new role to user any other symbol to show available roles"); int c = Console.Read(); switch (c) { case 0: { adding = false; break; } case 1: { Console.WriteLine("Enter roles id:"); int roleid = Convert.ToInt32(Console.ReadLine()); if (UserControls.AddUsersRole(user.Id, roleid)) { Console.WriteLine("Role added successfully"); } else { Console.WriteLine("Something went wrong maybe id is incorrect"); } break; } default: { break; } } } }
/// <summary> /// describes button that shows users list /// </summary> /// <param name="sender">sender of event</param> /// <param name="e">event data</param> private void ShowUsers_Click(object sender, EventArgs e) { this.login.Hide(); this.password.Hide(); this.newUser.Hide(); this.showUsers.Hide(); this.usersList.Show(); this.label1.Hide(); this.label2.Hide(); this.visible.Hide(); this.back.Show(); List <User> list; UserControls.LoadBaseUsers(out list); foreach (User user in list) { this.usersList.Text = usersList.Text + user.ToString() + "\r\n"; } this.usersList.ReadOnly = true; list.Clear(); }
/// <summary> /// Login interface /// </summary> /// <param name="count">Counter of tries</param> /// <returns>User if logged null if not</returns> static private User Login(int count) { try { Console.WriteLine("login:"******"password:"******"*"); } else { if (key.Key == ConsoleKey.Backspace && password.Length > 0) { password = password.Substring(0, (password.Length - 1)); Console.Write("\b \b"); } } } // Stops Receving Keys Once Enter is Pressed while (key.Key != ConsoleKey.Enter); Console.WriteLine(); if (UserControls.Identify(login, password) == null) { if (count < 3) { Console.WriteLine("Wrong login or password"); Console.WriteLine("Press 0 to exit"); string message = "You have only " + (3 - count).ToString() + " more attempts"; Console.WriteLine(message); char choice = Convert.ToChar(Console.ReadLine()); switch (choice) { case '0': { Environment.Exit(0); return(new User()); } default: { return(Login(count + 1)); } } } else { Environment.Exit(0); return(new User()); } } return(UserControls.Identify(login, password)); } catch (FormatException) { return(Login(count + 1)); } }