public void RemoveAllUsers() { UserList ulist = new UserList(); ulist.Add(new User(new TcpClient(), "ЮзерОдин")); ulist.Add(new User(new TcpClient(), "ЮзерДва")); ulist.RemoveAll(); User result = ulist.Find("ЮзерОдин"); Assert.AreEqual(null, result); result = ulist.Find("ЮзерДва"); Assert.AreEqual(null, result); }
public void RemoveUser_UserExists() { UserList ulist = new UserList(); User user = new User(new TcpClient(), "СуперЮзер"); ulist.Add(user); User result = ulist.Find("СуперЮзер"); Assert.AreEqual(user, result, "Юзер не добавился!"); ulist.Remove(user); result = ulist.Find("СуперЮзер"); Assert.AreSame(null, result, "Удаление юзера не сработало!"); }
public bool EditWcsUser(WcsUser user, out string result) { if (!UserList.Exists(c => user.id == c.id)) { result = "不存在该用户信息!"; return(false); } if (UserList.Exists(c => user.id != c.id && user.username.Equals(c.username))) { result = "已经存在该用户名!"; return(false); } result = ""; WcsUser ouser = UserList.Find(c => c.id == user.id); ouser.name = user.name; ouser.username = user.username; ouser.password = user.password; ouser.exitwcs = user.exitwcs; ouser.memo = user.memo; ouser.role_id = user.role_id; return(PubMaster.Mod.RoleSql.EditeWcsUser(ouser)); }
public void FindUserByName_FindNotExistingUser() { UserList ulist = new UserList(); User result = ulist.Find("Не существующий Юзер"); Assert.AreSame(null, result); }
private WcsRole GetUserRole(string username, string password) { if (IsUserMatch(username, password)) { int roleid = UserList.Find(c => c.username.Equals(username))?.role_id ?? 0; return(GetRole(roleid)); } return(null); }
// Sign Up #region Sign up public User SignUp(string breadcrumb = "") { // Username______________________________________ string name = ""; string message1 = "Choose a username:"******""; while (true) { Console.Clear(); Console.WriteLine(LoadHeader()); Console.WriteLine(breadcrumb); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("\t" + message2); Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine("\t" + message1); Console.Write("\t>"); Console.Write(name); var key = Console.ReadKey(); if (key.Key == ConsoleKey.Escape) { return(null); } if (key.Key == ConsoleKey.Backspace) { if (name.Length > 0) { name = name.Remove(name.Length - 1); } continue; } else if (key.Key == ConsoleKey.Enter) { if (!(UserList.Find(i => i.username == name) is null)) { Console.Clear(); message2 = "That username is taken."; message1 = "Try another one:"; name = ""; // Prompt to sign up or try again for username? // How will the user go back to main menu? } else { break; } } if (Tools.IsSymbol(key.KeyChar) > -1 || char.IsNumber(key.KeyChar) || char.IsLetter(key.KeyChar)) { Console.Write(key); name += key.KeyChar; } }
public void AddUsers_FindUser() { User expected = new User(null, "СуперЮзер"); UserList ulist = new UserList(); ulist.Add(expected); ulist.Add(new User(new TcpClient(), "ДругойЮзер")); User result = ulist.Find("СуперЮзер"); Assert.AreSame(expected, result, expected.name + " и " + result.name); }
private void FindPerson(int uid) { string ucl; if (!__uid__ucl__.TryGetValue(uid, out ucl)) { User person; UserList.Find(uid: uid, val: out person); __uid__ucl__.Add(uid, person.name); } }
private void RemoveFriendButton_OnClick(object sender, RoutedEventArgs e) { Button b = sender as Button; User u2 = b.DataContext as User; MainWindow.Service.RemoveFriend(MainWindow.CurrentUser, u2); View.ItemsSource = null; _ul.Remove(_ul.Find(u => u.Id == u2.Id)); View.ItemsSource = _ul; }
private void btnEnter_Click(object sender, EventArgs e) { User currentUser = _userList.Find(txtLogin.Text, txtPassword.Text); if (currentUser != null) { Service.CurrentUser = currentUser; var studentsForm = new Students(); studentsForm.AddOwnedForm(this); Hide(); studentsForm.Show(); } else { MessageBox.Show("Такого пользователя не существует!", "Ошибка!"); } }
private async void StartUp() { if (MainAuth.UserID == null) { LoginNavigate(); } else { await MainAuth.GenerateAccessToken(); await RefreshShifts(); await RefreshUsers(); User user = UserList.Find(x => x._ID == MainAuth.UserID); MainAuth.UserName = $"{user.FirstName} {user.LastName}"; ShiftListNavigate(); } }
private void btnSave_Click(object sender, EventArgs e) { if (Service.CurrentUser.Role != User.UserRole.Admin) { if (txtLogin.Text == "" || txtPassword.Text == "" || txtFio.Text == "") { MessageBox.Show("Не все поля заполнены!", "Ошибка!"); } else { User oldUser = _userList.Find(Service.CurrentUser); oldUser.Login = txtLogin.Text; oldUser.Password = txtPassword.Text; oldUser.Fio = txtFio.Text; oldUser.Role = (User.UserRole)cmbRole.SelectedIndex; _userList.Update(); } } else { var editedUser = new User(); editedUser.Login = txtLogin.Text; editedUser.Password = txtPassword.Text; editedUser.Fio = txtFio.Text; editedUser.Role = (User.UserRole)cmbRole.SelectedIndex; _userList.Replace(_selectedUserId, editedUser); _userList.Update(); } if (_selectedUserId == Service.CurrentUser.UserId) { _userList.SetNewCurrentUser(); } dgvUsers.DataSource = typeof(List <User>); dgvUsers.DataSource = _userList.Value; }
// Log in. #region Log in public User LogIn() { // Username______________________________________ string name = ""; string message = ""; while (true) { Console.Clear(); Console.WriteLine(LoadHeader()); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine(message); Console.ForegroundColor = ConsoleColor.Black; message = ""; Console.Write("\tUsername:\n\t>"); Console.Write(name); var key = Console.ReadKey(); if (key.Key == ConsoleKey.Escape) { return(null); } if (key.Key == ConsoleKey.Backspace) { if (name.Length > 0) { name = name.Remove(name.Length - 1); } continue; } else if (key.Key == ConsoleKey.Enter) { if (UserList.Find(i => i.username == name) is null) { Console.Clear(); message = "\tThat name is not my DB."; name = ""; } else { break; } } if (Tools.IsSymbol(key.KeyChar) > -1 || char.IsNumber(key.KeyChar) || char.IsLetter(key.KeyChar)) { Console.Write(key); name += key.KeyChar; } } //------------------------------------------------------------------- // Password______________________________________ string password = ""; message = ""; while (true) { Console.Clear(); Console.WriteLine(LoadHeader()); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine(message); Console.ForegroundColor = ConsoleColor.Black; message = ""; Console.Write("\tPassword:\n\t>"); Console.Write("*".Times(password.Length)); var key = Console.ReadKey(true); if (key.Key == ConsoleKey.Escape) { return(null); } if (key.Key == ConsoleKey.Backspace) { if (password.Length > 0) { password = password.Remove(password.Length - 1); } continue; } if (key.Key == ConsoleKey.Enter) { if (password.Length != 0) { if (UserList.Find(i => i.username == name).password == password) { break; } message = "\tWrong password!"; password = ""; } continue; } if (Tools.IsSymbol(key.KeyChar) > -1 || char.IsNumber(key.KeyChar) || char.IsLetter(key.KeyChar)) { //Console.Write("*"); password += key.KeyChar; } } //------------------------------------------------------------------- // LoadSpecific UserDB User user = UserList.Find(i => i.username == name); this.Log($"User loged in(userID:{user.UserID})"); return(user); }
public WcsUser GetUser(int id) { return(UserList.Find(c => c.id == id)); }
public int AdjustKhepris(string username, int khepris) { UserList.Find(mentionedUser => mentionedUser.username.Equals(username)).khepris += khepris; AdjustSafeKhepris(UserList.Find(mentionedUser => mentionedUser.username.Equals(username)).safename, khepris); return(UserList.Find(mentionedUser => mentionedUser.username.Equals(username)).khepris); }
public WcsUser GetUser(string username, string password) { return(UserList.Find(c => username.Equals(c.username) && password.Equals(c.password))); }
/// <summary> /// 获取默认的用户账号 /// </summary> /// <returns></returns> public WcsUser GetGuestUser() { return(UserList.Find(c => c.guest)); }