public void IsSystemAccount_Email_Failure() { Assert.IsFalse(SystemAccountHelper.IsSystemAccount("*****@*****.**")); Assert.IsFalse(SystemAccountHelper.IsSystemAccount("*****@*****.**")); Assert.IsFalse(SystemAccountHelper.IsSystemAccount("*****@*****.**")); Assert.IsFalse(SystemAccountHelper.IsSystemAccount("*****@*****.**")); }
protected void InitMonitoring() { var client = SystemAccountHelper.GetInternalSystemClient(); // Создадим компонент // Если запускаемся в отладке, то компонент будет не в корне, а в папке DEBUG var folder = !DebugHelper.IsDebugMode ? client.GetRootComponentControl() : client.GetRootComponentControl().GetOrCreateChildFolderControl("DEBUG"); var componentType = client.GetOrCreateComponentTypeControl(!DebugHelper.IsDebugMode ? "Agent" : DebugHelper.DebugComponentType); ComponentControl = folder .GetOrCreateChildComponentControl(new GetOrCreateComponentData("Agent", componentType) { DisplayName = "Агент", Version = AgentHelper.GetVersion() }); // Присвоим Id компонента по умолчанию, чтобы адаптер NLog мог его использовать Client.Instance = client; Client.Instance.Config.DefaultComponent.Id = ComponentControl.Info?.Id; Logger = LogManager.GetLogger("Agent"); Logger.Info("Запуск, IsFake={0}", ComponentControl.IsFake()); AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException; }
public async Task UpdatePassword(string contextUserEmail, UserUpdatePasswordDto dto, long userId) { await ThrowIfNotInRole(contextUserEmail, UserRoleEnum.Viewer); if (dto == null) { throw new ArgumentNullException(nameof(UserUpdatePasswordDto)); } if (dto.OldPassword.Equals(dto.NewPassword)) { throw new BadRequestException("Please provide a different password."); } var hashedPassword = _hashProvider.Hash(dto.OldPassword); var entity = await _context.Users.FirstOrDefaultAsync( u => u.Id == userId && u.Password.Equals(hashedPassword) && !SystemAccountHelper.IsSystemAccount(u.Id)); if (entity == null) { throw new EntityNotFoundException(userId); } if (!entity.Email.Equals(contextUserEmail)) { throw new UnauthorizeException(); } entity.Password = _hashProvider.Hash(dto.NewPassword); await _context.SaveChangesAsync(); }
public void IsSystemAccount_ID_Failure() { //Simply test that a few IDs that would be IDENTITY values in the database's User.Id column //are NOT system accounts. for (int counter = 1; counter < 10; counter++) { Assert.IsFalse(SystemAccountHelper.IsSystemAccount(counter)); } }
public void IsSystemAccount_Email_Success() { var systemAccounts = SystemAccountHelper.SystemAccounts; foreach (var systemAccount in systemAccounts) { var isSystemAccount = SystemAccountHelper.IsSystemAccount(systemAccount.Email); Assert.IsTrue(isSystemAccount); } }
public Core.Api.AccessToken GetCoreLocalToken() { return(new Core.Api.AccessToken() { AccountId = Id, IsLocalRequest = true, ProgramName = Token.Program, SecretKey = SystemAccountHelper.GetSystemToken().SecretKey }); }
public async Task <IActionResult> Get() { try { var data = await _userService.Where(x => !SystemAccountHelper.IsSystemAccount(x.Id)); return(Ok(data)); } catch (Exception e) { return(Exception(e)); } }
public async Task <IActionResult> Get(long id) { try { var data = await _userService.Find(x => x.Id == id && !SystemAccountHelper.IsSystemAccount(x.Id)); return(Ok(data)); } catch (Exception e) { return(Exception(e)); } }
protected TRequest GetRequest <TRequest>(Guid?accountId) where TRequest : Request, new() { var token = SystemAccountHelper.GetLocalToken(accountId); var request = new TRequest() { ProgramName = ProgramName, RequestId = Guid.NewGuid(), Token = token }; return(request); }
public async Task Delete(string contextUserEmail, long userId) { await ThrowIfNotInRole(contextUserEmail, UserRoleEnum.Admin); var entity = await _context.Users.FirstOrDefaultAsync(u => u.Id == userId && !SystemAccountHelper.IsSystemAccount(u.Id)); if (entity == null) { throw new EntityNotFoundException(userId); } _context.Users.Remove(entity); await _context.SaveChangesAsync(); }
protected void InitMonitoring() { var client = SystemAccountHelper.GetInternalSystemClient(); client.EventPreparer = new HttpServiceEventPreparer(); // Создадим компонент // Если запускаемся в отладке, то компонент будет не в корне, а в папке DEBUG var folder = !DebugHelper.IsDebugMode ? client.GetRootComponentControl() : client.GetRootComponentControl().GetOrCreateChildFolderControl("DEBUG"); var componentType = client.GetOrCreateComponentTypeControl(!DebugHelper.IsDebugMode ? "ApiWebService" : DebugHelper.DebugComponentType); var componentControl = folder .GetOrCreateChildComponentControl(componentType, "ApiWebService 1.0", ApiHandler.GetVersion()); // Присвоим Id компонента по умолчанию, чтобы адаптер NLog мог его использовать Client.Instance = client; Client.Instance.Config.DefaultComponent.Id = componentControl.Info?.Id; ApiHandler.Init(componentControl); LogManager.GetCurrentClassLogger().Info("Запуск, IsFake={0}", componentControl.IsFake()); }
protected override void PopulateData() { var seeded = _databaseContext.Users.Any(x => SystemAccountHelper.IsSystemAccount(x.Id)); if (seeded) { Console.WriteLine("System accounts have already been seeded. Use the -f command line option, if your intent was to repopulate the system accounts."); return; } foreach (var userAccount in SystemAccountHelper.SystemAccounts) { var query = $@"SET IDENTITY_INSERT {userTableName} ON INSERT INTO {userTableName} (Id, DisplayName, Role, Password, Email) VALUES({userAccount.Id}, '{userAccount.DisplayName}', {(int)userAccount.Role}, '{userAccount.Password}', '{userAccount.Email}') SET IDENTITY_INSERT {userTableName} OFF" ; _databaseContext.Database.ExecuteSqlCommand(query); } }
public async Task Update(string contextUserEmail, UserUpdateDto dto, long userId) { await ThrowIfNotInRole(contextUserEmail, UserRoleEnum.Admin); if (dto == null) { throw new ArgumentNullException(nameof(UserUpdateDto)); } var entity = await _context.Users.FirstOrDefaultAsync(u => u.Id == userId && !SystemAccountHelper.IsSystemAccount(u.Id)); if (entity == null) { throw new EntityNotFoundException(userId); } entity.DisplayName = dto.DisplayName; entity.Role = dto.Role; await _context.SaveChangesAsync(); }
public async Task ThrowIfNotInRole(string email, UserRoleEnum role) { if (SystemAccountHelper.IsSystemAccount(email)) { return; } var entity = await _context.Users.FirstOrDefaultAsync(u => u.Email.Equals(email)); if (entity == null) { throw new EntityNotFoundException(); } if (role == UserRoleEnum.Viewer) { if (entity.Role == UserRoleEnum.Viewer || entity.Role == UserRoleEnum.Editor || entity.Role == UserRoleEnum.Admin) { return; } } if (role == UserRoleEnum.Editor) { if (entity.Role == UserRoleEnum.Editor || entity.Role == UserRoleEnum.Admin) { return; } } if (role == UserRoleEnum.Admin && entity.Role == UserRoleEnum.Admin) { return; } throw new UnauthorizeException(); }
protected void InitMonitoring() { var client = SystemAccountHelper.GetInternalSystemClient(); client.EventPreparer = new WebApplicationEventPreparer(); // Создадим компонент // Если запускаемся в отладке, то компонент будет не в корне, а в папке DEBUG var folder = !DebugHelper.IsDebugMode ? client.GetRootComponentControl() : client.GetRootComponentControl().GetOrCreateChildFolderControl("DEBUG"); var componentType = client.GetOrCreateComponentTypeControl(!DebugHelper.IsDebugMode ? SystemComponentTypes.WebSite.SystemName : DebugHelper.DebugComponentType); ComponentControl = folder .GetOrCreateChildComponentControl(new GetOrCreateComponentData("UserAccountWebSite", componentType) { DisplayName = "Личный кабинет пользователя", Version = Version }); // Присвоим Id компонента по умолчанию, чтобы адаптер NLog мог его использовать Client.Instance = client; Client.Instance.Config.DefaultComponent.Id = ComponentControl.Info?.Id; LogManager.GetCurrentClassLogger().Info("Запуск, IsFake={0}", ComponentControl.IsFake()); }