Beispiel #1
0
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            string profile = this.ProfileName;

            if (!string.IsNullOrWhiteSpace(profile))
            {
                this.CacheProfile = string.Empty;

                string tenant = DbConvention.GetTenant();

                var config = CacheConfig.Get(tenant, profile);

                if (config != null)
                {
                    this.Duration              = config.Duration;
                    this.Location              = config.Location;
                    this.NoStore               = config.NoStore;
                    this.SqlDependency         = config.SqlDependency;
                    this.VaryByContentEncoding = config.VaryByContentEncoding;
                    this.VaryByCustom          = config.VaryByCustom;
                    this.VaryByHeader          = config.VaryByHeader;
                    this.VaryByParam           = config.VaryByParam;
                }
            }

            base.OnActionExecuting(context);
        }
Beispiel #2
0
        public void Remove()
        {
            if (string.IsNullOrWhiteSpace(this.ThemeName))
            {
                Thread.Sleep(10000);
                throw new ThemeRemoveException("Access is denied.");
            }

            string defaultTheme = Configuration.GetDefaultTheme();

            if (this.ThemeName.ToLower().Equals(defaultTheme.ToLower()))
            {
                throw new ThemeRemoveException("Access is denied. You cannot remove this theme because it is in use.");
            }

            string tenant = DbConvention.GetTenant();
            string path   = $"~/Tenants/{tenant}/Areas/Frapid.WebsiteBuilder/Themes/{this.ThemeName}";

            path = HostingEnvironment.MapPath(path);

            if (path == null || !Directory.Exists(path))
            {
                throw new ThemeRemoveException("Invalid theme.");
            }

            Directory.Delete(path, true);
        }
Beispiel #3
0
        public void Create()
        {
            string tenant = DbConvention.GetTenant();
            string path   = $"~/Tenants/{tenant}";

            path = HostingEnvironment.MapPath(path);

            if (path == null || !Directory.Exists(path))
            {
                throw new ResourceCreateException("Could not create the file or directory because the tenant directory was not found.");
            }

            path = Path.Combine(path, this.Container);

            if (!Directory.Exists(path))
            {
                throw new ResourceCreateException("Could not create the file or directory is an invalid directory path.");
            }

            path = Path.Combine(path, this.File);

            if (this.Rewrite.Equals(false) && System.IO.File.Exists(path))
            {
                return;
            }

            if (this.IsDirectory)
            {
                Directory.CreateDirectory(path);
                return;
            }

            System.IO.File.WriteAllText(path, this.Contents, Encoding.UTF8);
        }
Beispiel #4
0
        public ActionResult GetResources(string themeName)
        {
            if (string.IsNullOrWhiteSpace(themeName))
            {
                return(this.Failed("Invalid theme name", HttpStatusCode.BadRequest));
            }

            string tenant = DbConvention.GetTenant();
            string path   = $"~/Tenants/{tenant}/Areas/Frapid.WebsiteBuilder/Themes/{themeName}/";

            path = HostingEnvironment.MapPath(path);

            if (path == null || !Directory.Exists(path))
            {
                return(this.Failed("Path not found", HttpStatusCode.NotFound));
            }

            var resource = ThemeResource.Get(path);

            resource = ThemeResource.NormalizePath(path, resource);

            string json = JsonConvert.SerializeObject(resource, Formatting.None,
                                                      new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });

            return(this.Content(json, "application/json"));
        }
Beispiel #5
0
        public bool IsWellKnownDb()
        {
            var serializer = new DomainSerializer("DomainsApproved.json");
            var domains    = serializer.Get();

            return(domains.Any(domain => DbConvention.GetTenant(domain.DomainName) == this.Database));
        }
Beispiel #6
0
        public void Execute(IJobExecutionContext context)
        {
            string url = context.JobDetail.Key.Name;

            try
            {
                Log.Verbose($"Installing frapid on domain {url}.");
                string database = DbConvention.GetTenant(url);

                Log.Verbose($"Creating database {database}.");
                var db = new DbInstaller(database);
                db.Install();

                Log.Verbose("Getting installables.");
                var installables = GetInstallables(database);
                Log.Information($"The following apps will be installed:\n\n {installables}.");

                foreach (var installable in installables)
                {
                    Log.Verbose($"Installing module {installable.ApplicationName}.");
                    new AppInstaller(database, installable).Install();
                }

                var tenant =
                    new DomainSerializer("DomainsApproved.json").Get().FirstOrDefault(x => x.DomainName.Equals(url));
                DbInstalledDomains.Add(tenant);
            }
            catch (Exception ex)
            {
                Log.Error("Could not install frapid on {url} due to errors. Exception: {Exception}", url, ex);
                throw;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Returns path to the static content on the tenant directory.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static string GetFile(HttpContext context)
        {
            string tenant          = DbConvention.GetTenant();
            var    staticResources = GetConfig(tenant, "StaticResources").Or("").Split(',').Select(x => x.Trim()).ToList();

            if (!staticResources.Any())
            {
                return(string.Empty);
            }

            string rootDirectory = $"/Tenants/{tenant}/wwwroot/";

            string requestedFile = context.Request.Url.AbsolutePath;
            string query         = context.Request.Url.Query;
            string extension     = Path.GetExtension(requestedFile);

            if (staticResources.Contains(extension))
            {
                //This is a well-known file type
                string path = rootDirectory + requestedFile;
                if (File.Exists(HostingEnvironment.MapPath(path)))
                {
                    return(path + query);
                }
            }


            return(string.Empty);
        }
Beispiel #8
0
        public ActionResult SetAsDefault(string themeName)
        {
            if (string.IsNullOrEmpty(themeName))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            string tenant = DbConvention.GetTenant();
            string path   = $"~/Tenants/{tenant}/Areas/Frapid.Dashboard/Themes/{themeName}";

            path = HostingEnvironment.MapPath(path);

            if (path == null || !Directory.Exists(path))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            path = $"~/Tenants/{tenant}/Areas/Frapid.Dashboard/Dashboard.config";
            path = HostingEnvironment.MapPath(path);

            if (path == null || !System.IO.File.Exists(path))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }


            ConfigurationManager.SetConfigurationValue(path, "DefaultTheme", themeName);
            return(this.Ok());
        }
        protected string GetRazorView(string areaName, string path)
        {
            string tenant = DbConvention.GetTenant();
            string theme  = Configuration.GetDefaultTheme();


            string overridePath = "~/Tenants/{0}/Areas/Frapid.Dashboard/Themes/{1}/Areas/{2}/Views/" + path;

            overridePath = string.Format(CultureInfo.InvariantCulture, overridePath, tenant, theme, areaName);

            if (System.IO.File.Exists(HostingEnvironment.MapPath(overridePath)))
            {
                return(overridePath);
            }


            overridePath = "~/Tenants/{0}/Areas/{1}/Themes/{2}/Views/" + path;
            overridePath = string.Format(CultureInfo.InvariantCulture, overridePath, tenant, areaName, theme);

            if (System.IO.File.Exists(HostingEnvironment.MapPath(overridePath)))
            {
                return(overridePath);
            }

            string defaultPath = "~/Areas/{0}/Views/{1}";

            defaultPath = string.Format(CultureInfo.InvariantCulture, defaultPath, areaName, path);

            return(defaultPath);
        }
Beispiel #10
0
        public void Delete()
        {
            string tenant = DbConvention.GetTenant();
            string path   = $"~/Tenants/{tenant}/Areas/Frapid.WebsiteBuilder/Themes/{this.ThemeName}";

            path = HostingEnvironment.MapPath(path);

            if (path == null)
            {
                throw new ResourceRemoveException("Path to the file or directory is invalid.");
            }

            path = Path.Combine(path, this.Resource);

            if (Directory.Exists(path))
            {
                Directory.Delete(path);
                return;
            }

            if (File.Exists(path))
            {
                File.Delete(path);
                return;
            }

            throw new ResourceRemoveException("File or directory could not be found.");
        }
Beispiel #11
0
        public void Upload()
        {
            if (string.IsNullOrWhiteSpace(this.ThemeName))
            {
                throw new ArgumentNullException(nameof(this.ThemeName));
            }

            string tenant = DbConvention.GetTenant();
            string path   = $"~/Tenants/{tenant}/Areas/Frapid.WebsiteBuilder/Themes/{this.ThemeName}";

            path = HostingEnvironment.MapPath(path);

            if (path == null || !Directory.Exists(path))
            {
                Log.Warning("Could not upload resource because the directory {directory} does not exist.", path);
                throw new ResourceUploadException("Invalid path. Check the log for more details.");
            }

            path = Path.Combine(path, this.Container);

            if (!Directory.Exists(path))
            {
                Log.Warning("Could not upload resource because the directory {directory} does not exist.", path);
                throw new ResourceUploadException("Invalid path. Check application logs for more information.");
            }


            string fileName = Path.GetFileName(this.PostedFile.FileName);

            if (fileName == null)
            {
                Log.Warning("Could not upload resource because the posted file name is null or invalid.");
                throw new ResourceUploadException(
                          "Could not upload resource because the posted file name is null or invalid.");
            }

            var    allowed   = FrapidConfig.GetAllowedUploadExtensions(DbConvention.GetTenant());
            string extension = Path.GetExtension(fileName);

            if (!allowed.Contains(extension))
            {
                Log.Warning("Could not upload resource because the uploaded file {file} has invalid extension.",
                            fileName);
                throw new ResourceUploadException(
                          "Could not upload resource because the uploaded file has invalid extension.");
            }

            var stream = this.PostedFile.InputStream;

            path = Path.Combine(Path.Combine(path, fileName));

            using (var fileStream = File.Create(path))
            {
                stream.CopyTo(fileStream);
            }
        }
Beispiel #12
0
        public string Locate()
        {
            string tenant = DbConvention.GetTenant();
            string path   = $"~/Tenants/{tenant}/Areas/Frapid.WebsiteBuilder/Themes/{this.ThemeName}/{this.File}";

            path = HostingEnvironment.MapPath(path);

            if (!System.IO.File.Exists(path))
            {
                throw new ThemeFileLocationException("Could not locate the requested file.");
            }

            return(path);
        }
Beispiel #13
0
        public ActionResult Get(string resource = "")
        {
            string configFile =
                HostingEnvironment.MapPath($"~/Tenants/{DbConvention.GetTenant()}/Configs/Frapid.config");

            if (!System.IO.File.Exists(configFile))
            {
                return(this.HttpNotFound());
            }

            var allowed = ConfigurationManager.ReadConfigurationValue(configFile, "MyAllowedResources").Split(',');

            if (string.IsNullOrWhiteSpace(resource) || allowed.Length.Equals(0))
            {
                return(this.HttpNotFound());
            }

            string directory = HostingEnvironment.MapPath(Configuration.GetCurrentThemePath());

            if (directory == null)
            {
                return(this.HttpNotFound());
            }

            string path = Path.Combine(directory, resource);

            if (!System.IO.File.Exists(path))
            {
                return(this.HttpNotFound());
            }

            string extension = Path.GetExtension(path);

            if (!allowed.Contains(extension))
            {
                return(this.HttpNotFound());
            }

            if (this._exceptions.Contains(extension))
            {
                return(this.HttpNotFound());
            }

            string mimeType = this.GetMimeType(path);

            return(this.File(path, mimeType));
        }
Beispiel #14
0
        protected override void Initialize(RequestContext context)
        {
            string clientToken = context.HttpContext.Request.GetClientToken();
            var    provider    = new Provider(DbConvention.GetTenant());
            var    token       = provider.GetToken(clientToken);
            string tenant      = DbConvention.GetTenant();

            if (token != null)
            {
                bool isValid = AccessTokens.IsValid(token.ClientToken, context.HttpContext.GetClientIpAddress(),
                                                    context.HttpContext.GetUserAgent());

                if (isValid)
                {
                    AppUsers.SetCurrentLogin(tenant, token.LoginId);
                    var loginView = AppUsers.GetCurrent(tenant, token.LoginId);

                    this.MetaUser = new MetaUser
                    {
                        Tenant      = tenant,
                        ClientToken = token.ClientToken,
                        LoginId     = token.LoginId,
                        UserId      = token.UserId,
                        OfficeId    = token.OfficeId
                    };

                    var identity = new ClaimsIdentity(token.Claims, DefaultAuthenticationTypes.ApplicationCookie,
                                                      ClaimTypes.NameIdentifier, ClaimTypes.Role);
                    identity.AddClaim(new Claim(ClaimTypes.NameIdentifier,
                                                token.LoginId.ToString(CultureInfo.InvariantCulture)));

                    if (loginView.RoleName != null)
                    {
                        identity.AddClaim(new Claim(ClaimTypes.Role, loginView.RoleName));
                    }

                    if (loginView.Email != null)
                    {
                        identity.AddClaim(new Claim(ClaimTypes.Email, loginView.Email));
                    }

                    context.HttpContext.User = new ClaimsPrincipal(identity);
                }
            }

            base.Initialize(context);
        }
Beispiel #15
0
        public ActionResult GetThemes()
        {
            string tenant = DbConvention.GetTenant();
            string path   = $"~/Tenants/{tenant}/Areas/Frapid.Dashboard/Themes";

            path = HostingEnvironment.MapPath(path);

            if (path == null || !Directory.Exists(path))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            var directories = Directory.GetDirectories(path);
            var templates   = directories.Select(directory => new DirectoryInfo(directory).Name).ToList();

            return(this.Ok(templates));
        }
Beispiel #16
0
        private string GetUploadDirectory()
        {
            string tenant          = DbConvention.GetTenant();
            string uploadDirectory = HostingEnvironment.MapPath($"~/Tenants/{tenant}/Temp/");

            if (uploadDirectory == null || !Directory.Exists(uploadDirectory))
            {
                Log.Warning("Could not upload theme because the temporary directory {uploadDirectory} does not exist.",
                            uploadDirectory);
                throw new ThemeUploadException(
                          "Could not upload your theme. Check application logs for more information.");
            }

            return(uploadDirectory);

            ;
        }
Beispiel #17
0
        public List <string> Discover()
        {
            string tenant = DbConvention.GetTenant();
            string path   = $"~/Tenants/{tenant}/Areas/Frapid.WebsiteBuilder/Themes";

            path = HostingEnvironment.MapPath(path);

            if (path == null || !Directory.Exists(path))
            {
                Log.Warning("Could not discover theme(s) on path {path}.", path);
                throw new ThemeDiscoveryException(
                          "Cannot find the theme directory. Check application logs for more information.");
            }

            var directories = Directory.GetDirectories(path);

            return(directories.Select(directory => new DirectoryInfo(directory).Name).ToList());
        }
        private static Token GetToken(HubCallerContext context)
        {
            string clientToken = context.Request.GetClientToken();
            var    provider    = new Provider(DbConvention.GetTenant());
            var    token       = provider.GetToken(clientToken);

            if (token != null)
            {
                bool isValid = AccessTokens.IsValid(token.ClientToken, context.Request.GetClientIpAddress(),
                                                    context.Headers["User-Agent"]);

                if (isValid)
                {
                    return(token);
                }
            }

            return(null);
        }
Beispiel #19
0
        public ActionResult GetBinary(string file)
        {
            if (string.IsNullOrWhiteSpace(file))
            {
                return(this.HttpNotFound());
            }

            string tenant = DbConvention.GetTenant();
            string path   = HostingEnvironment.MapPath($"/Tenants/{tenant}/{file}");

            if (!System.IO.File.Exists(path))
            {
                return(this.HttpNotFound());
            }

            string mimeType = this.GetMimeType(path);

            return(this.File(path, mimeType));
        }
Beispiel #20
0
        protected override void Initialize(HttpControllerContext context)
        {
            string database = DbConvention.GetTenant();

            string clientToken = context.Request.GetBearerToken();
            var    provider    = new Provider(database);
            var    token       = provider.GetToken(clientToken);


            if (token != null)
            {
                AppUsers.SetCurrentLogin(database, token.LoginId);
                var loginView = AppUsers.GetCurrent(database, token.LoginId);

                this.MetaUser = new MetaUser
                {
                    Tenant      = database,
                    ClientToken = token.ClientToken,
                    LoginId     = token.LoginId,
                    UserId      = loginView.UserId.To <int>(),
                    OfficeId    = loginView.OfficeId.To <int>()
                };

                var identity = new ClaimsIdentity(token.Claims);

                identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, token.LoginId.ToString(CultureInfo.InvariantCulture)));

                if (loginView.RoleName != null)
                {
                    identity.AddClaim(new Claim(ClaimTypes.Role, loginView.RoleName));
                }

                if (loginView.Email != null)
                {
                    identity.AddClaim(new Claim(ClaimTypes.Email, loginView.Email));
                }

                context.RequestContext.Principal = new ClaimsPrincipal(identity);
            }

            base.Initialize(context);
        }
Beispiel #21
0
        private Content GetContents(string categoryAlias, string alias, bool isPost = false, FormCollection form = null)
        {
            string tenant = DbConvention.GetTenant(this.CurrentDomain);
            var    model  = ContentModel.GetContent(tenant, categoryAlias, alias);

            if (model == null)
            {
                return(null);
            }

            bool isHomepage = string.IsNullOrWhiteSpace(categoryAlias) && string.IsNullOrWhiteSpace(alias);

            string path   = GetLayoutPath();
            string layout = isHomepage ? this.GetHomepageLayout() : this.GetLayout();


            model.LayoutPath = path;
            model.Layout     = layout;
            return(model);
        }
Beispiel #22
0
        public ActionResult Get(string resource = "")
        {
            if (string.IsNullOrWhiteSpace(resource))
            {
                return(this.HttpNotFound());
            }

            string tenant = DbConvention.GetTenant();

            var allowed = FrapidConfig.GetMyAllowedResources(tenant);

            if (string.IsNullOrWhiteSpace(resource) || allowed.Count().Equals(0))
            {
                return(this.HttpNotFound());
            }

            string directory = HostingEnvironment.MapPath($"/Tenants/{tenant}");

            if (directory == null)
            {
                return(this.HttpNotFound());
            }

            string path = Path.Combine(directory, resource);

            if (!System.IO.File.Exists(path))
            {
                return(this.HttpNotFound());
            }

            string extension = Path.GetExtension(path);

            if (!allowed.Contains(extension))
            {
                return(this.HttpNotFound());
            }

            string mimeType = this.GetMimeType(path);

            return(this.File(path, mimeType));
        }
        protected override void OnActionExecuting(ActionExecutingContext context)
        {
            if (this.Request?.Url != null)
            {
                this.CurrentDomain  = this.Request.Url.DnsSafeHost;
                this.CurrentPageUrl = this.Request.Url.AbsoluteUri;
                this.Tenant         = DbConvention.GetTenant(this.CurrentDomain);
            }

            bool isStatic = DbConvention.IsStaticDomain(this.CurrentDomain);

            if (isStatic)
            {
                //Static domains are strictly used for content caching only.
                context.Result = new HttpNotFoundResult("The requested page does not exist.");
            }
            else
            {
                base.OnActionExecuting(context);
            }
        }
Beispiel #24
0
        public void CopyTheme()
        {
            string source      = this.ExtractedDirectory;
            string tenant      = DbConvention.GetTenant();
            string destination =
                HostingEnvironment.MapPath(
                    $"~/Tenants/{tenant}/Areas/Frapid.WebsiteBuilder/Themes/{this.ThemeInfo.ThemeName}");

            if (destination == null)
            {
                Log.Warning("Could not copy theme because the destination directory could not be located.");
                throw new ThemeInstallException("Could not install theme. Check application logs for more information.");
            }

            if (Directory.Exists(destination))
            {
                throw new ThemeInstallException("Could not install theme because it already exists.");
            }

            FileHelper.CopyDirectory(source, destination);
        }
        protected string GetRazorView(string areaName, string path)
        {
            Log.Verbose($"Prepping Razor view for area \"{areaName}\" and view \"{path}\".");

            string tenant = DbConvention.GetTenant();
            string theme  = Configuration.GetDefaultTheme();

            Log.Verbose($"Resolved tenant \"{tenant}\" and theme \"{theme}\".");

            string overridePath = "~/Tenants/{0}/Areas/Frapid.WebsiteBuilder/Themes/{1}/Areas/{2}/Views/" + path;

            overridePath = string.Format(CultureInfo.InvariantCulture, overridePath, tenant, theme, areaName);

            Log.Verbose($"Checking if there is an overridden view present on the theme path \"{overridePath}\".");

            if (System.IO.File.Exists(HostingEnvironment.MapPath(overridePath)))
            {
                Log.Verbose($"The view \"{path}\" was overridden by the theme \"{theme}\".");
                return(overridePath);
            }

            overridePath = "~/Tenants/{0}/Areas/{1}/Themes/{2}/Views/" + path;
            overridePath = string.Format(CultureInfo.InvariantCulture, overridePath, tenant, areaName, theme);

            Log.Verbose($"Checking if there is an overridden view present on the tenant path \"{overridePath}\".");

            if (System.IO.File.Exists(HostingEnvironment.MapPath(overridePath)))
            {
                Log.Verbose($"The view \"{path}\" was overridden by the tenant \"{tenant}\".");
                return(overridePath);
            }

            string defaultPath = "~/Areas/{0}/Views/{1}";

            defaultPath = string.Format(CultureInfo.InvariantCulture, defaultPath, areaName, path);

            Log.Verbose($"The view \"{path}\" was located on area \"{areaName}\" on path \"{defaultPath}\".");

            return(defaultPath);
        }
Beispiel #26
0
        public void Create()
        {
            if (string.IsNullOrWhiteSpace(this.ThemeName) || string.IsNullOrWhiteSpace(this.File))
            {
                throw new ResourceCreateException("Invalid theme or file name.");
            }

            string tenant = DbConvention.GetTenant();
            string path   = $"~/Tenants/{tenant}/Areas/Frapid.WebsiteBuilder/Themes/{this.ThemeName}";

            path = HostingEnvironment.MapPath(path);

            if (path == null || !Directory.Exists(path))
            {
                throw new ResourceCreateException(
                          "Could not create the file or directory because the theme directory was not found.");
            }

            path = Path.Combine(path, this.Container);

            if (!Directory.Exists(path))
            {
                throw new ResourceCreateException("Could not create the file or directory is an invalid directory path.");
            }

            path = Path.Combine(path, this.File);

            if (this.Rewrite.Equals(false) && System.IO.File.Exists(path))
            {
                return;
            }

            if (this.IsDirectory)
            {
                Directory.CreateDirectory(path);
                return;
            }

            System.IO.File.WriteAllText(path, this.Contents, Encoding.UTF8);
        }
        public override bool AuthorizeHubConnection(HubDescriptor descriptor, IRequest request)
        {
            string clientToken = request.GetClientToken();
            var    provider    = new Provider(DbConvention.GetTenant());
            var    token       = provider.GetToken(clientToken);
            string tenant      = DbConvention.GetTenant();

            if (token != null)
            {
                bool isValid = AccessTokens.IsValid(token.ClientToken, request.GetClientIpAddress(),
                                                    request.Headers["user-agent"]);

                if (isValid)
                {
                    AppUsers.SetCurrentLogin(tenant, token.LoginId);
                    var loginView = AppUsers.GetCurrent(tenant, token.LoginId);

                    var identity = new ClaimsIdentity(token.Claims, DefaultAuthenticationTypes.ApplicationCookie,
                                                      ClaimTypes.NameIdentifier, ClaimTypes.Role);

                    identity.AddClaim(new Claim(ClaimTypes.NameIdentifier,
                                                token.LoginId.ToString(CultureInfo.InvariantCulture)));

                    if (loginView.RoleName != null)
                    {
                        identity.AddClaim(new Claim(ClaimTypes.Role, loginView.RoleName));
                    }

                    if (loginView.Email != null)
                    {
                        identity.AddClaim(new Claim(ClaimTypes.Email, loginView.Email));
                    }

                    request.Environment["server.User"] = new ClaimsPrincipal(identity);
                    return(true);
                }
            }

            return(false);
        }
Beispiel #28
0
        public ActionResult GetResources()
        {
            string tenant = DbConvention.GetTenant();
            string path   = $"~/Tenants/{tenant}/";

            path = HostingEnvironment.MapPath(path);

            if (path == null || !Directory.Exists(path))
            {
                return(this.Failed("Path not found", HttpStatusCode.NotFound));
            }

            var resource = FileManagerResource.Get(path);

            resource = FileManagerResource.NormalizePath(path, resource);

            string json = JsonConvert.SerializeObject(resource, Formatting.None,
                                                      new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });

            return(this.Content(json, "application/json"));
        }
        public static MetaUser GetUser(HubCallerContext context)
        {
            var token = GetToken(context);

            if (token != null)
            {
                string tenant = DbConvention.GetTenant();

                AppUsers.SetCurrentLogin(tenant, token.LoginId);
                var loginView = AppUsers.GetCurrent(tenant, token.LoginId);

                return(new MetaUser
                {
                    Tenant = tenant,
                    ClientToken = token.ClientToken,
                    LoginId = token.LoginId,
                    UserId = loginView.UserId,
                    OfficeId = loginView.OfficeId
                });
            }

            return(null);
        }
Beispiel #30
0
        private void CreateDirectory()
        {
            string tenant    = DbConvention.GetTenant();
            string directory = $"~/Tenants/{tenant}/Areas/Frapid.WebsiteBuilder/Themes/{this.Info.ThemeName}";

            directory = HostingEnvironment.MapPath(directory);

            this.ThemeDirectory = directory;

            if (directory == null)
            {
                throw new ThemeCreateException(
                          "Could not create the theme because the destination directory could not be located.");
            }

            if (Directory.Exists(directory))
            {
                throw new ThemeCreateException(
                          "Could not create the theme because the destination directory already exists.");
            }

            Directory.CreateDirectory(directory);
        }