public Site Post([FromBody] Site Site) { if (ModelState.IsValid) { bool authorized; if (!Sites.GetSites().Any()) { // provision initial site during installation authorized = true; Tenant tenant = Tenants.GetTenant(); Site.TenantId = tenant.TenantId; } else { authorized = User.IsInRole(Constants.HostRole); } if (authorized) { Site = Sites.AddSite(Site); string folder = environment.WebRootPath + "\\Tenants\\" + Tenants.GetTenant().TenantId.ToString() + "\\Sites\\" + Site.SiteId.ToString(); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } logger.Log(LogLevel.Information, this, LogFunction.Create, "Site Added {Site}", Site); } } return(Site); }
public UserRole Post([FromBody] UserRole userRole) { if (ModelState.IsValid) { userRole = _userRoles.AddUserRole(userRole); _syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.User, userRole.UserId); _logger.Log(LogLevel.Information, this, LogFunction.Create, "User Role Added {UserRole}", userRole); } return(userRole); }
public Site Post([FromBody] Site Site) { if (ModelState.IsValid) { bool authorized; if (!Sites.GetSites().Any()) { authorized = true; // provision initial site during installation } else { authorized = User.IsInRole(Constants.HostRole); } if (authorized) { Site = Sites.AddSite(Site); string folder = environment.WebRootPath + "\\Tenants\\" + Tenants.GetTenant().TenantId.ToString() + "\\Sites\\" + Site.SiteId.ToString(); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } } } return(Site); }
public PageModule Post([FromBody] PageModule pageModule) { if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Page, pageModule.PageId, PermissionNames.Edit)) { pageModule = _pageModules.AddPageModule(pageModule); _syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.Page, pageModule.PageId); _logger.Log(LogLevel.Information, this, LogFunction.Create, "Page Module Added {PageModule}", pageModule); } else { _logger.Log(LogLevel.Error, this, LogFunction.Create, "User Not Authorized To Add PageModule {PageModule}", pageModule); HttpContext.Response.StatusCode = 401; pageModule = null; } return(pageModule); }
public async Task <User> Put(int id, [FromBody] User user) { if (ModelState.IsValid) { if (User.IsInRole(RoleNames.Admin) || User.Identity.Name == user.Username) { if (user.Password != "") { IdentityUser identityuser = await _identityUserManager.FindByNameAsync(user.Username); if (identityuser != null) { identityuser.PasswordHash = _identityUserManager.PasswordHasher.HashPassword(identityuser, user.Password); await _identityUserManager.UpdateAsync(identityuser); } } user = _users.UpdateUser(user); _syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.User, user.UserId); user.Password = ""; // remove sensitive information _logger.Log(LogLevel.Information, this, LogFunction.Update, "User Updated {User}", user); } else { _logger.Log(LogLevel.Error, this, LogFunction.Update, "User Not Authorized To Update User {User}", user); HttpContext.Response.StatusCode = 401; user = null; } } return(user); }
public Setting Post([FromBody] Setting setting) { if (ModelState.IsValid && IsAuthorized(setting.EntityName, setting.EntityId, PermissionNames.Edit)) { setting = _settings.AddSetting(setting); if (setting.EntityName == EntityNames.Module) { _syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.Site, _tenants.GetAlias().SiteId); } _logger.Log(LogLevel.Information, this, LogFunction.Create, "Setting Added {Setting}", setting); } else { _logger.Log(LogLevel.Error, this, LogFunction.Create, "User Not Authorized To Add Setting {Setting}", setting); HttpContext.Response.StatusCode = 401; setting = null; } return(setting); }
public Page Post([FromBody] Page page) { if (ModelState.IsValid) { string permissions; if (page.ParentId != null) { permissions = _pages.GetPage(page.ParentId.Value).Permissions; } else { permissions = new List <Permission> { new Permission(PermissionNames.Edit, Constants.AdminRole, true) }.EncodePermissions(); } if (_userPermissions.IsAuthorized(User, PermissionNames.Edit, permissions)) { page = _pages.AddPage(page); _syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.Site, page.SiteId); _logger.Log(LogLevel.Information, this, LogFunction.Create, "Page Added {Page}", page); if (!page.EditMode) { var modules = _modules.GetModules(page.SiteId).Where(item => item.AllPages).ToList(); foreach (Module module in modules) { var pageModule = _pageModules.GetPageModules(page.SiteId).FirstOrDefault(item => item.ModuleId == module.ModuleId); _pageModules.AddPageModule(new PageModule { PageId = page.PageId, ModuleId = pageModule.ModuleId, Title = pageModule.Title, Pane = pageModule.Pane, Order = pageModule.Order, ContainerType = pageModule.ContainerType }); } } } else { _logger.Log(LogLevel.Error, this, LogFunction.Create, "User Not Authorized To Add Page {Page}", page); HttpContext.Response.StatusCode = 401; page = null; } } return(page); }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { var tenant = _tenantResolver.GetTenant(); if (tenant != null) { optionsBuilder.UseSqlServer(tenant.DBConnectionString .Replace("|DataDirectory|", AppDomain.CurrentDomain.GetData("DataDirectory")?.ToString()) ); } base.OnConfiguring(optionsBuilder); }
private void ProcessTemplatesRecursively(DirectoryInfo current, string rootPath, string templatePath, ModuleDefinition moduleDefinition) { // process folder string folderPath = rootPath + current.FullName.Replace(templatePath, ""); folderPath = folderPath.Replace("[Owner]", moduleDefinition.Owner); folderPath = folderPath.Replace("[Module]", moduleDefinition.Name); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } FileInfo[] files = current.GetFiles("*.*"); if (files != null) { foreach (FileInfo file in files) { // process file string filePath = Path.Combine(folderPath, file.Name); filePath = filePath.Replace("[Owner]", moduleDefinition.Owner); filePath = filePath.Replace("[Module]", moduleDefinition.Name); string text = System.IO.File.ReadAllText(file.FullName); text = text.Replace("[Owner]", moduleDefinition.Owner); text = text.Replace("[Module]", moduleDefinition.Name); text = text.Replace("[Description]", moduleDefinition.Description); text = text.Replace("[RootPath]", rootPath); text = text.Replace("[ServerAssemblyName]", moduleDefinition.ServerAssemblyName); text = text.Replace("[Folder]", folderPath); text = text.Replace("[File]", Path.GetFileName(filePath)); System.IO.File.WriteAllText(filePath, text); if (Path.GetExtension(filePath) == ".sql") { // execute script in curent tenant foreach (string query in text.Split("GO", StringSplitOptions.RemoveEmptyEntries)) { _sql.ExecuteNonQuery(_resolver.GetTenant(), query); } } } DirectoryInfo[] folders = current.GetDirectories(); foreach (DirectoryInfo folder in folders.Reverse()) { ProcessTemplatesRecursively(folder, rootPath, templatePath, moduleDefinition); } } }
private void ProcessTemplatesRecursively(DirectoryInfo current, string rootPath, string rootFolder, string templatePath, ModuleDefinition moduleDefinition) { // process folder string folderPath = rootPath + current.FullName.Replace(templatePath, ""); folderPath = folderPath.Replace("[Owner]", moduleDefinition.Owner); folderPath = folderPath.Replace("[Module]", moduleDefinition.Name); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } FileInfo[] files = current.GetFiles("*.*"); if (files != null) { foreach (FileInfo file in files) { // process file string filePath = Path.Combine(folderPath, file.Name); filePath = filePath.Replace("[Owner]", moduleDefinition.Owner); filePath = filePath.Replace("[Module]", moduleDefinition.Name); string text = System.IO.File.ReadAllText(file.FullName); text = text.Replace("[Owner]", moduleDefinition.Owner); text = text.Replace("[Module]", moduleDefinition.Name); text = text.Replace("[Description]", moduleDefinition.Description); text = text.Replace("[RootPath]", rootPath); text = text.Replace("[RootFolder]", rootFolder); text = text.Replace("[ServerManagerType]", moduleDefinition.ServerManagerType); text = text.Replace("[Folder]", folderPath); text = text.Replace("[File]", Path.GetFileName(filePath)); text = text.Replace("[FrameworkVersion]", Constants.Version); System.IO.File.WriteAllText(filePath, text); if (Path.GetExtension(filePath).ToLower() == ".sql" && !filePath.ToLower().Contains("uninstall")) { // execute installation script in curent tenant _sql.ExecuteScript(_resolver.GetTenant(), text); } } DirectoryInfo[] folders = current.GetDirectories(); foreach (DirectoryInfo folder in folders.Reverse()) { ProcessTemplatesRecursively(folder, rootPath, rootFolder, templatePath, moduleDefinition); } } }
public Site Post([FromBody] Site site) { if (ModelState.IsValid) { bool authorized; if (!_sites.GetSites().Any()) { // provision initial site during installation authorized = true; Tenant tenant = _tenants.GetTenant(); site.TenantId = tenant.TenantId; } else { authorized = User.IsInRole(RoleNames.Host); } if (authorized) { site = _sites.AddSite(site); _logger.Log(site.SiteId, LogLevel.Information, this, LogFunction.Create, "Site Added {Site}", site); } } return(site); }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.ReplaceService <IMigrationsAssembly, MultiDatabaseMigrationsAssembly>(); if (string.IsNullOrEmpty(_connectionString)) { Tenant tenant; if (_tenantResolver != null) { tenant = _tenantResolver.GetTenant(); } else { tenant = _tenantManager.GetTenant(); } if (tenant != null) { _connectionString = tenant.DBConnectionString .Replace("|DataDirectory|", AppDomain.CurrentDomain.GetData("DataDirectory")?.ToString()); _databaseType = tenant.DBType; } } if (!String.IsNullOrEmpty(_databaseType)) { var type = Type.GetType(_databaseType); ActiveDatabase = Activator.CreateInstance(type) as IDatabase; } if (!string.IsNullOrEmpty(_connectionString) && ActiveDatabase != null) { optionsBuilder.UseOqtaneDatabase(ActiveDatabase, _connectionString); } base.OnConfiguring(optionsBuilder); }
public Site Post([FromBody] Site Site) { if (ModelState.IsValid) { bool authorized; if (!Sites.GetSites().Any()) { // provision initial site during installation authorized = true; Tenant tenant = Tenants.GetTenant(); Site.TenantId = tenant.TenantId; } else { authorized = User.IsInRole(Constants.HostRole); } if (authorized) { Site = Sites.AddSite(Site); logger.Log(LogLevel.Information, this, LogFunction.Create, "Site Added {Site}", Site); } } return(Site); }
public ContextBase(ITenantResolver TenantResolver) { tenant = TenantResolver.GetTenant(); }
private string GetFolderPath(Folder folder) { return(Utilities.PathCombine(_environment.ContentRootPath, "Content", "Tenants", _tenants.GetTenant().TenantId.ToString(), "Sites", folder.SiteId.ToString(), folder.Path)); }
public TenantContext(ITenantResolver TenantResolver) { tenant = TenantResolver.GetTenant(); }
public DBContextBase(ITenantResolver tenantResolver, IHttpContextAccessor accessor) { _tenant = tenantResolver.GetTenant(); _accessor = accessor; }
public DBContextBase(ITenantResolver TenantResolver, IHttpContextAccessor accessor) { tenant = TenantResolver.GetTenant(); this.accessor = accessor; }
private string GetFolderPath(Folder folder) { return(environment.ContentRootPath + "\\Content\\Tenants\\" + Tenants.GetTenant().TenantId.ToString() + "\\Sites\\" + folder.SiteId.ToString() + "\\" + folder.Path); }
public DBLoggerProvider(ITenantResolver TenantResolver) { tenant = TenantResolver.GetTenant(); }