Exemple #1
0
        public async Task Handle(RecipientsAddedToFolderNotification value, CancellationToken cancellationToken)
        {
            WorkerLog.Instance.Information("Handling notification that recipients are added");
            WorkerLog.Instance.Debug($"Getting files of folder '{value.FolderId}' for following recipients: '{string.Join(", ", value.Recipients)}'");
            var filesResult = await _fileRepository.GetFilesForFolder(value.FolderId);

            var folderResult = await _folderRepository.GetFolder(value.FolderId);

            if (filesResult.WasSuccessful && folderResult.WasSuccessful)
            {
                var neededRecipients = folderResult.Data.Recipients?.Where(x => value.Recipients.Any(y => y == x.Id)).ToList();
                foreach (var file in filesResult.Data)
                {
                    var requestFile = new RequestFile
                                      (
                        file.Id,
                        file.FolderId,
                        file.Name,
                        file.Path,
                        file.LastModifiedDate,
                        file.Size,
                        file.Source,
                        file.Version,
                        neededRecipients
                                      );

                    await _workerQueueContainer.ToSendFiles.Writer.WriteAsync(requestFile, cancellationToken);
                }
            }
        }
        public IEnumerable <Models.File> Get(string folder)
        {
            List <Models.File> files = new List <Models.File>();
            int folderid;

            if (int.TryParse(folder, out folderid))
            {
                Folder f = _folders.GetFolder(folderid);
                if (f != null && _userPermissions.IsAuthorized(User, PermissionNames.Browse, f.Permissions))
                {
                    files = _files.GetFiles(folderid).ToList();
                }
            }
            else
            {
                if (User.IsInRole(Constants.HostRole))
                {
                    folder = GetFolderPath(folder);
                    if (Directory.Exists(folder))
                    {
                        foreach (string file in Directory.GetFiles(folder))
                        {
                            files.Add(new Models.File {
                                Name = Path.GetFileName(file), Extension = Path.GetExtension(file)?.Replace(".", "")
                            });
                        }
                    }
                }
            }

            return(files);
        }
Exemple #3
0
 public File AddFile(File file)
 {
     _db.File.Add(file);
     _db.SaveChanges();
     file.Folder = _folderRepository.GetFolder(file.FolderId);
     file.Url    = GetFileUrl(file, _tenants.GetAlias());
     return(file);
 }
        public Folder Get(int id)
        {
            Folder folder = _folders.GetFolder(id);

            if (_userPermissions.IsAuthorized(User, PermissionNames.Browse, folder.Permissions))
            {
                return(folder);
            }
            else
            {
                _logger.Log(LogLevel.Error, this, LogFunction.Read, "User Not Authorized To Access Folder {Folder}", folder);
                HttpContext.Response.StatusCode = 401;
                return(null);
            }
        }
        // GET: TreeView
        public ActionResult Index(string path)
        {
            var rootFolderViewModel = new FolderViewModel();
            var rootFolder          = repo.GetFolder(path);
            var subFolders          = repo.GetSubFolders(rootFolder.Id).ToList();

            rootFolderViewModel = rootFolder.MapToViewModel(subFolders);
            return(View(rootFolderViewModel));
        }
        public IEnumerable <Models.File> Get(string folder)
        {
            List <Models.File> files = new List <Models.File>();
            int folderid;

            if (int.TryParse(folder, out folderid))
            {
                Folder Folder = _folders.GetFolder(folderid);
                if (Folder != null && Folder.SiteId == _alias.SiteId && _userPermissions.IsAuthorized(User, PermissionNames.Browse, Folder.Permissions))
                {
                    files = _files.GetFiles(folderid).ToList();
                }
                else
                {
                    _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized File Get Attempt {FolderId}", folder);
                    HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
                    files = null;
                }
            }
            else
            {
                if (User.IsInRole(RoleNames.Host))
                {
                    folder = GetFolderPath(folder);
                    if (Directory.Exists(folder))
                    {
                        foreach (string file in Directory.GetFiles(folder))
                        {
                            files.Add(new Models.File {
                                Name = Path.GetFileName(file), Extension = Path.GetExtension(file)?.Replace(".", "")
                            });
                        }
                    }
                }
                else
                {
                    _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized File Get Attempt {Folder}", folder);
                    HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
                    files = null;
                }
            }

            return(files);
        }
Exemple #7
0
        public Folder Get(int id)
        {
            Folder folder = _folders.GetFolder(id);

            if (folder != null && folder.SiteId == _alias.SiteId && _userPermissions.IsAuthorized(User, PermissionNames.Browse, folder.Permissions))
            {
                return(folder);
            }
            else
            {
                _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Folder Get Attempt {FolderId}", id);
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
                return(null);
            }
        }
        public IActionResult UploadPicture()
        {
            IFormFile uploadedImage = HttpContext.Request.Form.Files[0];
            Folder    folder        = folderRepository.GetFolder(userGet.GetUser(HttpContext), HttpContext.Request.Form["FolderName"].ToString());

            if (folder == null)
            {
                return(BadRequest("Not existing folder!"));
            }
            UploadPhoto photoData = new UploadPhoto(
                HttpContext.Request.Form["Description"].ToString(),
                HttpContext.Request.Form["Access"].ToString(),
                folder);

            if (userGet.HaveUser(HttpContext) && ModelState.IsValid && uploadedImage != null && ImageTypeIsValid(uploadedImage) && ImageDataIsValid(photoData))
            {
                UploadImage(HttpContext, photoData, uploadedImage);
                return(Ok());
            }
            return(Unauthorized());
        }
        public List <PageTemplate> CreateSite(Site site)
        {
            List <PageTemplate> _pageTemplates = new List <PageTemplate>();

            _pageTemplates.Add(new PageTemplate
            {
                Name             = "Home",
                Parent           = "",
                Path             = "",
                Icon             = "home",
                IsNavigation     = true,
                IsPersonalizable = false,
                EditMode         = false,
                PagePermissions  = new List <Permission> {
                    new Permission(PermissionNames.View, Constants.AllUsersRole, true),
                    new Permission(PermissionNames.View, Constants.AdminRole, true),
                    new Permission(PermissionNames.Edit, Constants.AdminRole, true)
                }.EncodePermissions(),
                PageTemplateModules = new List <PageTemplateModule> {
                    new PageTemplateModule {
                        ModuleDefinitionName = "Oqtane.Modules.HtmlText, Oqtane.Client", Title = "Welcome To Oqtane...", Pane = "Content",
                        ModulePermissions    = new List <Permission> {
                            new Permission(PermissionNames.View, Constants.AllUsersRole, true),
                            new Permission(PermissionNames.View, Constants.AdminRole, true),
                            new Permission(PermissionNames.Edit, Constants.AdminRole, true)
                        }.EncodePermissions(),
                        Content = "<p><a href=\"https://www.oqtane.org\" target=\"_new\">Oqtane</a> is an open source <b>modular application framework</b> built from the ground up using modern .NET Core technology. It leverages the revolutionary new Blazor component model to create a <b>fully dynamic</b> web development experience which can be executed on a client or server. Whether you are looking for a platform to <b>accelerate your web development</b> efforts, or simply interested in exploring the anatomy of a large-scale Blazor application, Oqtane provides a solid foundation based on proven enterprise architectural principles.</p>" +
                                  "<p align=\"center\"><a href=\"https://www.oqtane.org\" target=\"_new\"><img class=\"img-fluid\" src=\"oqtane.png\"></a></p><p align=\"center\"><a class=\"btn btn-primary\" href=\"https://www.oqtane.org/Community\" target=\"_new\">Join Our Community</a>&nbsp;&nbsp;<a class=\"btn btn-primary\" href=\"https://github.com/oqtane/oqtane.framework\" target=\"_new\">Clone Our Repo</a></p>" +
                                  "<p><a href=\"https://dotnet.microsoft.com/apps/aspnet/web-apps/blazor\" target=\"_new\">Blazor</a> is a single-page app framework that lets you build interactive web applications using C# instead of JavaScript. Client-side Blazor relies on WebAssembly, an open web standard that does not require plugins or code transpilation in order to run natively in a web browser. Server-side Blazor uses SignalR to host your application on a web server and provide a responsive and robust debugging experience. Blazor applications works in all modern web browsers, including mobile browsers.</p>" +
                                  "<p>Blazor is a feature of <a href=\"https://dotnet.microsoft.com/apps/aspnet\" target=\"_new\">ASP.NET Core 3</a>, the popular cross platform web development framework from Microsoft that extends the <a href=\"https://dotnet.microsoft.com/learn/dotnet/what-is-dotnet\" target=\"_new\" >.NET developer platform</a> with tools and libraries for building web apps.</p>"
                    },
                    new PageTemplateModule {
                        ModuleDefinitionName = "Oqtane.Modules.HtmlText, Oqtane.Client", Title = "MIT License", Pane = "Content",
                        ModulePermissions    = new List <Permission> {
                            new Permission(PermissionNames.View, Constants.AllUsersRole, true),
                            new Permission(PermissionNames.View, Constants.AdminRole, true),
                            new Permission(PermissionNames.Edit, Constants.AdminRole, true)
                        }.EncodePermissions(),
                        Content = "<p>Copyright (c) 2019-2020 .NET Foundation</p>" +
                                  "<p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:</p>" +
                                  "<p>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</p>" +
                                  "<p>THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>"
                    },
                    new PageTemplateModule {
                        ModuleDefinitionName = "Oqtane.Modules.HtmlText, Oqtane.Client", Title = "Secure Content", Pane = "Content",
                        ModulePermissions    = new List <Permission> {
                            new Permission(PermissionNames.View, Constants.RegisteredRole, true),
                            new Permission(PermissionNames.View, Constants.AdminRole, true),
                            new Permission(PermissionNames.Edit, Constants.AdminRole, true)
                        }.EncodePermissions(),
                        Content = "<p>Oqtane allows you to control access to your content using security roles. This module is only visible to Registered Users of the site.</p>"
                    }
                }
            });
            _pageTemplates.Add(new PageTemplate
            {
                Name             = "Private",
                Parent           = "",
                Path             = "private",
                Icon             = "lock-locked",
                IsNavigation     = true,
                IsPersonalizable = false,
                EditMode         = false,
                PagePermissions  = new List <Permission> {
                    new Permission(PermissionNames.View, Constants.RegisteredRole, true),
                    new Permission(PermissionNames.View, Constants.AdminRole, true),
                    new Permission(PermissionNames.Edit, Constants.AdminRole, true)
                }.EncodePermissions(),
                PageTemplateModules = new List <PageTemplateModule> {
                    new PageTemplateModule {
                        ModuleDefinitionName = "Oqtane.Modules.HtmlText, Oqtane.Client", Title = "Secure Content", Pane = "Content",
                        ModulePermissions    = new List <Permission> {
                            new Permission(PermissionNames.View, Constants.RegisteredRole, true),
                            new Permission(PermissionNames.View, Constants.AdminRole, true),
                            new Permission(PermissionNames.Edit, Constants.AdminRole, true)
                        }.EncodePermissions(),
                        Content = "<p>Oqtane allows you to control access to your content using security roles. This page is only visible to Registered Users of the site.</p>"
                    }
                }
            });
            _pageTemplates.Add(new PageTemplate
            {
                Name             = "My Page",
                Parent           = "",
                Path             = "mypage",
                Icon             = "target",
                IsNavigation     = true,
                IsPersonalizable = true,
                EditMode         = false,
                PagePermissions  = new List <Permission> {
                    new Permission(PermissionNames.View, Constants.AllUsersRole, true),
                    new Permission(PermissionNames.View, Constants.AdminRole, true),
                    new Permission(PermissionNames.Edit, Constants.AdminRole, true)
                }.EncodePermissions(),
                PageTemplateModules = new List <PageTemplateModule> {
                    new PageTemplateModule {
                        ModuleDefinitionName = "Oqtane.Modules.HtmlText, Oqtane.Client", Title = "My Page", Pane = "Content",
                        ModulePermissions    = new List <Permission> {
                            new Permission(PermissionNames.View, Constants.AllUsersRole, true),
                            new Permission(PermissionNames.View, Constants.AdminRole, true),
                            new Permission(PermissionNames.Edit, Constants.AdminRole, true)
                        }.EncodePermissions(),
                        Content = "<p>Oqtane offers native support for user personalized pages. If a page is identified as personalizable by the site administrator in the page settings, when an authenticated user visits the page they will see an edit button at the top right corner of the page next to their username. When they click this button the sytem will create a new version of the page and allow them to edit the page content.</p>"
                    }
                }
            });

            if (System.IO.File.Exists(Path.Combine(_environment.WebRootPath, "images", "logo.png")))
            {
                string folderpath = Utilities.PathCombine(_environment.ContentRootPath, "Content", "Tenants", site.TenantId.ToString(), "Sites", site.SiteId.ToString(), "\\");
                System.IO.Directory.CreateDirectory(folderpath);
                if (!System.IO.File.Exists(Path.Combine(folderpath, "logo.png")))
                {
                    System.IO.File.Copy(Path.Combine(_environment.WebRootPath, "images", "logo.png"), Path.Combine(folderpath, "logo.png"));
                }
                Folder             folder = _folderRepository.GetFolder(site.SiteId, "");
                Oqtane.Models.File file   = _fileRepository.AddFile(new Oqtane.Models.File {
                    FolderId = folder.FolderId, Name = "logo.png", Extension = "png", Size = 8192, ImageHeight = 80, ImageWidth = 250
                });
                site.LogoFileId = file.FileId;
                _siteRepository.UpdateSite(site);
            }

            return(_pageTemplates);
        }
Exemple #10
0
        //TODO shoud be moved to another layer
        private async Task <User> CreateUser(User user)
        {
            User newUser = null;

            bool verified;
            bool allowregistration;

            if (user.Username == UserNames.Host || User.IsInRole(RoleNames.Admin))
            {
                verified          = true;
                allowregistration = true;
            }
            else
            {
                verified          = false;
                allowregistration = _sites.GetSite(user.SiteId).AllowRegistration;
            }

            if (allowregistration)
            {
                IdentityUser identityuser = await _identityUserManager.FindByNameAsync(user.Username);

                if (identityuser == null)
                {
                    identityuser                = new IdentityUser();
                    identityuser.UserName       = user.Username;
                    identityuser.Email          = user.Email;
                    identityuser.EmailConfirmed = verified;
                    var result = await _identityUserManager.CreateAsync(identityuser, user.Password);

                    if (result.Succeeded)
                    {
                        user.LastLoginOn   = null;
                        user.LastIPAddress = "";
                        newUser            = _users.AddUser(user);
                        if (!verified)
                        {
                            string token = await _identityUserManager.GenerateEmailConfirmationTokenAsync(identityuser);

                            string url          = HttpContext.Request.Scheme + "://" + _tenants.GetAlias().Name + "/login?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token);
                            string body         = "Dear " + user.DisplayName + ",\n\nIn Order To Complete The Registration Of Your User Account Please Click The Link Displayed Below:\n\n" + url + "\n\nThank You!";
                            var    notification = new Notification(user.SiteId, null, newUser, "User Account Verification", body, null);
                            _notifications.AddNotification(notification);
                        }

                        // assign to host role if this is the host user ( initial installation )
                        if (user.Username == UserNames.Host)
                        {
                            int      hostroleid = _roles.GetRoles(user.SiteId, true).Where(item => item.Name == RoleNames.Host).FirstOrDefault().RoleId;
                            UserRole userrole   = new UserRole();
                            userrole.UserId        = newUser.UserId;
                            userrole.RoleId        = hostroleid;
                            userrole.EffectiveDate = null;
                            userrole.ExpiryDate    = null;
                            _userRoles.AddUserRole(userrole);
                        }

                        // add folder for user
                        Folder folder = _folders.GetFolder(user.SiteId, Utilities.PathCombine("Users", Path.DirectorySeparatorChar.ToString()));
                        if (folder != null)
                        {
                            _folders.AddFolder(new Folder
                            {
                                SiteId      = folder.SiteId,
                                ParentId    = folder.FolderId,
                                Name        = "My Folder",
                                Path        = Utilities.PathCombine(folder.Path, newUser.UserId.ToString(), Path.DirectorySeparatorChar.ToString()),
                                Order       = 1,
                                IsSystem    = true,
                                Permissions = new List <Permission>
                                {
                                    new Permission(PermissionNames.Browse, newUser.UserId, true),
                                    new Permission(PermissionNames.View, RoleNames.Everyone, true),
                                    new Permission(PermissionNames.Edit, newUser.UserId, true)
                                }.EncodePermissions()
                            });
                        }
                    }
                }
                else
                {
                    var result = await _identitySignInManager.CheckPasswordSignInAsync(identityuser, user.Password, false);

                    if (result.Succeeded)
                    {
                        newUser = _users.GetUser(user.Username);
                    }
                }

                if (newUser != null && user.Username != UserNames.Host)
                {
                    // add auto assigned roles to user for site
                    List <Role> roles = _roles.GetRoles(user.SiteId).Where(item => item.IsAutoAssigned).ToList();
                    foreach (Role role in roles)
                    {
                        UserRole userrole = new UserRole();
                        userrole.UserId        = newUser.UserId;
                        userrole.RoleId        = role.RoleId;
                        userrole.EffectiveDate = null;
                        userrole.ExpiryDate    = null;
                        _userRoles.AddUserRole(userrole);
                    }
                }

                if (newUser != null)
                {
                    newUser.Password = ""; // remove sensitive information
                    _logger.Log(user.SiteId, LogLevel.Information, this, LogFunction.Create, "User Added {User}", newUser);
                }
            }
            else
            {
                _logger.Log(user.SiteId, LogLevel.Error, this, LogFunction.Create, "User Registration Is Not Enabled For Site. User Was Not Added {User}", user);
            }

            return(newUser);
        }
        //TODO shoud be moved to another layer
        private async Task <User> CreateUser(User user)
        {
            User newUser = null;

            bool verified;
            bool allowregistration;

            if (user.Username == Constants.HostUser || User.IsInRole(Constants.AdminRole))
            {
                verified          = true;
                allowregistration = true;
            }
            else
            {
                verified          = false;
                allowregistration = _sites.GetSite(user.SiteId).AllowRegistration;
            }

            if (allowregistration)
            {
                IdentityUser identityuser = await _identityUserManager.FindByNameAsync(user.Username);

                if (identityuser == null)
                {
                    identityuser                = new IdentityUser();
                    identityuser.UserName       = user.Username;
                    identityuser.Email          = user.Email;
                    identityuser.EmailConfirmed = verified;
                    var result = await _identityUserManager.CreateAsync(identityuser, user.Password);

                    if (result.Succeeded)
                    {
                        user.LastLoginOn   = null;
                        user.LastIPAddress = "";
                        newUser            = _users.AddUser(user);
                        if (!verified)
                        {
                            Notification notification = new Notification();
                            notification.SiteId     = user.SiteId;
                            notification.FromUserId = null;
                            notification.ToUserId   = newUser.UserId;
                            notification.ToEmail    = "";
                            notification.Subject    = "User Account Verification";
                            string token = await _identityUserManager.GenerateEmailConfirmationTokenAsync(identityuser);

                            string url = HttpContext.Request.Scheme + "://" + _tenants.GetAlias().Name + "/login?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token);
                            notification.Body        = "Dear " + user.DisplayName + ",\n\nIn Order To Complete The Registration Of Your User Account Please Click The Link Displayed Below:\n\n" + url + "\n\nThank You!";
                            notification.ParentId    = null;
                            notification.CreatedOn   = DateTime.UtcNow;
                            notification.IsDelivered = false;
                            notification.DeliveredOn = null;
                            _notifications.AddNotification(notification);
                        }

                        // assign to host role if this is the host user ( initial installation )
                        if (user.Username == Constants.HostUser)
                        {
                            int      hostroleid = _roles.GetRoles(user.SiteId, true).Where(item => item.Name == Constants.HostRole).FirstOrDefault().RoleId;
                            UserRole userrole   = new UserRole();
                            userrole.UserId        = newUser.UserId;
                            userrole.RoleId        = hostroleid;
                            userrole.EffectiveDate = null;
                            userrole.ExpiryDate    = null;
                            _userRoles.AddUserRole(userrole);
                        }

                        // add folder for user
                        Folder folder = _folders.GetFolder(user.SiteId, "Users\\");
                        if (folder != null)
                        {
                            _folders.AddFolder(new Folder
                            {
                                SiteId      = folder.SiteId,
                                ParentId    = folder.FolderId,
                                Name        = "My Folder",
                                Path        = folder.Path + newUser.UserId.ToString() + "\\",
                                Order       = 1,
                                IsSystem    = true,
                                Permissions = "[{\"PermissionName\":\"Browse\",\"Permissions\":\"[" + newUser.UserId.ToString() + "]\"},{\"PermissionName\":\"View\",\"Permissions\":\"All Users\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"[" +
                                              newUser.UserId.ToString() + "]\"}]"
                            });
                        }
                    }
                }
                else
                {
                    var result = await _identitySignInManager.CheckPasswordSignInAsync(identityuser, user.Password, false);

                    if (result.Succeeded)
                    {
                        newUser = _users.GetUser(user.Username);
                    }
                }

                if (newUser != null && user.Username != Constants.HostUser)
                {
                    // add auto assigned roles to user for site
                    List <Role> roles = _roles.GetRoles(user.SiteId).Where(item => item.IsAutoAssigned).ToList();
                    foreach (Role role in roles)
                    {
                        UserRole userrole = new UserRole();
                        userrole.UserId        = newUser.UserId;
                        userrole.RoleId        = role.RoleId;
                        userrole.EffectiveDate = null;
                        userrole.ExpiryDate    = null;
                        _userRoles.AddUserRole(userrole);
                    }
                }

                if (newUser != null)
                {
                    newUser.Password = ""; // remove sensitive information
                    _logger.Log(user.SiteId, LogLevel.Information, this, LogFunction.Create, "User Added {User}", newUser);
                }
            }
            else
            {
                _logger.Log(user.SiteId, LogLevel.Error, this, LogFunction.Create, "User Registration Is Not Enabled For Site. User Was Not Added {User}", user);
            }

            return(newUser);
        }
 public Folder Get(int id)
 {
     return(Folders.GetFolder(id));
 }