public void EditUserForm(UserInfo userInfo) { UserError error; error = AdministrationClient.Instance.LockUser(userInfo); if ((error & UserError.NoError) == error) { try { using (UserForm frm = new UserForm(userInfo)) frm.ShowDialog(); } finally { error = AdministrationClient.Instance.UnlockUser(userInfo); if ((error & UserError.NoError) != error) // Если возникла ошибка при разблокировке { MessageBoxAdv.Show(GetErrorMessage(error, userInfo), "Ошибка"); } } } else // Если возникла ошибка при блокировке { MessageBoxAdv.Show(GetErrorMessage(error, userInfo), "Ошибка"); } }
public UserError DeleteUser(UserInfo userInfo) { UserError error = new UserError(); UserError whatCheck = UserError.LockedAlready | UserError.DeletedAlready | UserError.NoMoreAdminAfterDelete; error = CheckUserInfo(userInfo, whatCheck); if (error == 0) { int index = _userStorage.FindIndex(x => x.Name == userInfo.Name); //bool removeResult = try { _userStorage.RemoveAt(index); } catch { return UserError.NoDeleted; } _userStorage.SaveStorage(_filePath); return UserError.NoError; } return error; }
public UserError UpdateUser(UserInfo userInfo) { if(IsUserLogin(userInfo)) { return UserError.WorkInSystem; } return _serviceConfiguration.UserStorageAdapter.UpdateUser(userInfo); }
public UserForm(UserInfo userInfoEditor) { _userInfoEditor = userInfoEditor; InitializeComponent(); InitializeControls(); NewUser = false; Text = "Пользователь " + _userInfoEditor.FullName; btnSave.Enabled = false; }
private UserInfo GetUserInfo() { if (!NewUser) { return _userInfoEditor; } UserInfo userInfo = new UserInfo(); userInfo.Enable = true; userInfo.Date = DateTime.Today; userInfo.Priority = 0; return userInfo; }
public UserError DeleteUser(UserInfo userInfo) { if (IsUserLogin(userInfo)) { return UserError.WorkInSystem; } /*if (userInfo == null) { return UserError.DeletedAlready; }*/ return _serviceConfiguration.UserStorageAdapter.DeleteUser(userInfo); }
private void FillUserInfo(ref UserInfo userInfo) { userInfo.FullName = txtUserName.Text.Trim(); userInfo.Name = txtLogin.Text.Trim(); userInfo.Comment = txtComment.Text; userInfo.IsAdmin = chbAdministrator.Checked; userInfo.IsOperator = chbOperator.Checked; if (txtPassword.Modified) { byte[] hash = SecurityUtils.PasswordToHash(txtPassword.Text); userInfo.Hash = hash; } }
public UserError CRUD(Func<UserInfo, UserError> proc, UserInfo userInfo) { try { return proc(userInfo); } catch (NoConnectionException /*ex*/) { MessageBoxAdv.Show("Связь с сервером потеряна.\r\nПриложение будет закрыто.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning); Process.GetCurrentProcess().Kill(); } return UserError.NoError; }
public UserError AddUser(UserInfo userInfo) { UserError error = new UserError(); UserError whatCheck = UserError.NoLogin | UserError.NoPassword | UserError.NoFIO | UserError.LoginAlreadyExist| UserError.FIOAlreadyExist | UserError.NoRole; error = CheckUserInfo(userInfo, whatCheck); if (error== 0) { userInfo.Id = NextUserInfoId; _userStorage.Add(userInfo); _userStorage.SaveStorage(_filePath); return UserError.NoError; } return error; }
public UserError CheckUserInfo(UserInfo userInfo,UserError forCheck) { UserError error = new UserError(); //Проверка на залнение логина if((forCheck&UserError.NoLogin)==UserError.NoLogin) { if (userInfo== null || userInfo.Name.Trim().Length == 0) { error |= UserError.NoLogin; } } //В системе останется после удаления хотя бы одни пользователь с ролью Администратор if ((forCheck & UserError.NoMoreAdminAfterDelete) == UserError.NoMoreAdminAfterDelete) { UserInfo systemUserInfo = FindSystemUser(); if (userInfo != null) { if (!_userStorage.Exists(x => x.Id != userInfo.Id && x.IsAdmin && x.Id!= systemUserInfo.Id)) { error |= UserError.NoMoreAdminAfterDelete; } } } if ((forCheck & UserError.LastUserWithAdminRole) == UserError.LastUserWithAdminRole) { UserInfo systemUserInfo = FindSystemUser(); if (userInfo != null) { if (!_userStorage.Exists(x => x.Id != userInfo.Id && x.IsAdmin && x.Id != systemUserInfo.Id) && !userInfo.IsAdmin) { error |= UserError.LastUserWithAdminRole; } } } //Проверка на залнение FIO if ((forCheck & UserError.NoFIO) == UserError.NoFIO) { if (userInfo == null || userInfo.FullName.Trim().Length == 0) { error |= UserError.NoFIO; } } //Проверка на заполнение пароля if ((forCheck & UserError.NoPassword) == UserError.NoPassword) { if (userInfo == null || userInfo.Hash.Length == 0) { error |= UserError.NoPassword; } } //Проверка на залнение хотя бы одной роли if ((forCheck & UserError.NoRole) == UserError.NoRole) { if ((userInfo == null) ||(!userInfo.IsAdmin && !userInfo.IsOperator)) { error |= UserError.NoRole; } } //Проверка на то, что пользователь уже удален if ((forCheck & UserError.DeletedAlready) == UserError.DeletedAlready) { int userInfoIndex = -1; if(userInfo!= null) userInfoIndex = _userStorage.FindIndex(x => x.Id == userInfo.Id); if (userInfoIndex == -1) { error |= UserError.DeletedAlready; } } //Проверка на, то что такой Login уже есть в системе if ((forCheck & UserError.LoginAlreadyExist) == UserError.LoginAlreadyExist) { //_userStorage.Find(value => value.Name.Equals(userInfo.Name, StringComparison.InvariantCultureIgnoreCase)&& value.Id!=userInfo.Id); if (userInfo != null && _userStorage.Exists(x => x.Id != userInfo.Id && x.Name != null && x.Name.ToLower().Trim() == userInfo.Name.ToLower().Trim() )) { error |= UserError.LoginAlreadyExist; } } //Проверка на, то что такое FIO уже есть в системе if ((forCheck & UserError.FIOAlreadyExist) == UserError.FIOAlreadyExist) { if (userInfo != null && _userStorage.Exists(x => x.FullName!=null && x.FullName.ToLower().Trim() == userInfo.FullName.ToLower().Trim() && x.Id != userInfo.Id)) { error |= UserError.FIOAlreadyExist; } } //Проверка на, то что пользователь с таким Id заблокрован if ((forCheck & UserError.LockedAlready) == UserError.LockedAlready) { if (userInfo != null && lockedUsers.Exists(x => x.Id == userInfo.Id)) { error |= UserError.LockedAlready; } } //Проверка на, то что пользователь с таким Id уже не заблоктрована if ((forCheck & UserError.UnlockedAlready) == UserError.UnlockedAlready) { if (userInfo != null && !lockedUsers.Exists(x => x.Id == userInfo.Id)) { error |= UserError.UnlockedAlready; } } return error; }
public UserError UnlockUser(UserInfo userInfo) { UserError error = new UserError(); UserError whatCheck = UserError.DeletedAlready | UserError.UnlockedAlready; error = CheckUserInfo(userInfo, whatCheck); if (error == 0) { LockUserListDelete(userInfo); return UserError.NoError; } return error; }
private void LockUserListDelete(UserInfo userInfo) { lock (_syncObject) { int index = lockedUsers.FindIndex(x => x.Id == userInfo.Id); if (index>-1) lockedUsers.RemoveAt(index); } }
private void LockUserListAdd(UserInfo userInfo) { lock (_syncObject) { lockedUsers.Add(userInfo); } }
public UserError UpdateUser(UserInfo userInfo) { UserError error = new UserError(); UserError whatCheck = UserError.NoLogin | UserError.NoPassword | UserError.NoFIO | UserError.LastUserWithAdminRole| UserError.LoginAlreadyExist | UserError.FIOAlreadyExist | UserError.DeletedAlready | UserError.NoRole | UserError.UnlockedAlready; //TODO проверять если логин или FIO поменялись error = CheckUserInfo(userInfo, whatCheck); if (error == 0) { UserInfo userInfoPrev = _userStorage.Find(x => x.Id == userInfo.Id); userInfoPrev.Name = userInfo.Name; userInfoPrev.Hash = userInfo.Hash; userInfoPrev.IsAdmin = userInfo.IsAdmin; userInfoPrev.IsOperator = userInfo.IsOperator; userInfoPrev.Comment = userInfo.Comment; userInfoPrev.FullName = userInfo.FullName; _userStorage.SaveStorage(_filePath); return UserError.NoError; } return error; }
public UserError UnlockUser(UserInfo userInfo) { return _serviceConfiguration.UserStorageAdapter.UnlockUser(userInfo); }
public UserError DeleteUser(UserInfo userInfo) { return UserHandler("DeleteUser", userInfo); }
public UserError AddUser(UserInfo userInfo) { return AdministrationClient.Instance.AddUser(userInfo); }
public string GetErrorMessage(UserError error, UserInfo userInfo) { string errorMessage = ""; if ((error & UserError.LockedAlready) == UserError.LockedAlready) errorMessage += "- Пользователь с логином \"" + userInfo.Name + "\" заблокирован\n"; if ((error & UserError.NoLogin) == UserError.NoLogin) errorMessage += "- У пользователя отсутствует логин\n"; if ((error & UserError.NoPassword) == UserError.NoPassword) errorMessage += "- Не заполнено поле Пароль\n"; if ((error & UserError.DeletedAlready) == UserError.DeletedAlready) errorMessage += "- Пользователь " + (userInfo == null ? "" : "\"" + userInfo.Name + "\" ") + "уже удален\n"; if ((error & UserError.LoginAlreadyExist) == UserError.LoginAlreadyExist) errorMessage += "- Пользователь с логином " + (userInfo == null ? "" : "\"" + userInfo.Name + "\" ") + "уже учтен в Системе\n"; if ((error & UserError.FIOAlreadyExist) == UserError.FIOAlreadyExist) errorMessage += "- Пользователь с таким ФИО " + (userInfo == null ? "" : "\"" + userInfo.FullName + "\" ") + "уже учтен в Системе\n"; if ((error & UserError.NoRole) == UserError.NoRole) errorMessage += "- Пользователю не назначена ни одна роль\n"; if ((error & UserError.NoFIO) == UserError.NoFIO) errorMessage += "- У пользователя отсутствует ФИО\n"; if ((error & UserError.NoDeleted) == UserError.NoDeleted) errorMessage += "- Пользователь не удален\n"; if ((error & UserError.UnlockedAlready) == UserError.UnlockedAlready) errorMessage += "- Пользователь уже разблокирован\n"; if ((error & UserError.NoMoreAdminAfterDelete) == UserError.NoMoreAdminAfterDelete) errorMessage += "- В Системе должен остаться хотя бы один пользователь с ролью Администратор\n"; if ((error & UserError.WorkInSystem) == UserError.WorkInSystem) errorMessage += "- Запись недоступна для изменения: пользователь работает в Системе\n"; if ((error & UserError.LastUserWithAdminRole) == UserError.LastUserWithAdminRole) errorMessage += "- В Системе должен остаться хотя бы один пользователь с ролью Администратор\n"; return errorMessage; }
private bool IsUserLogin(UserInfo userInfo) { IList<UserIdentity> userIdentities = _loginService.GetUserLoginCollection(); if (userInfo!=null && userIdentities.Any(x => x.User.Id == userInfo.Id)) { return true; } return false; }
public UserError LockUser(UserInfo userInfo) { return UserHandler("LockUser", userInfo); }
private UserError UserHandler(string proc, UserInfo userInfo) { using (_svc = new SimpleClient<IAdministrationService>()) { try { _svc.Open(); } catch (Exception /*ex*/) { NoConnectionException error = new NoConnectionException(); throw error; } Type channel = typeof(IUserService); MethodInfo method = channel.GetMethod(proc, new Type[] { typeof(UserInfo)}); object[] parameters ={userInfo}; return (UserError)method.Invoke(_svc.Channel, parameters); } }
public UserError UpdateUser(UserInfo userInfo) { return UserHandler("UpdateUser", userInfo); }
public UserError UpdateUser(UserInfo userInfo) { return AdministrationClient.Instance.UpdateUser(userInfo); }
public UserError AddUser(UserInfo userInfo) { return UserHandler("AddUser", userInfo); }