Exemplo n.º 1
0
        protected override void OnException(ExceptionContext filterContext)
        {
            var request = filterContext.HttpContext.Request;

            NTGLogger.LogError(request, filterContext.Exception);

            var contentType = request.Headers["Content-Type"];
            var acceptsJson = request.AcceptTypes.Contains("application/json");

            contentType = contentType != null?contentType.ToLower() : string.Empty;

            if (acceptsJson || contentType.Contains("application/json") || contentType.Contains("multipart/form-data"))
            {
                var errorModel = new BaseAjaxModel();
                errorModel.AddMessage(Message.GLOBAL, new Message(ExceptionMessage, MessageTypes.Error));
                filterContext.HttpContext.Response.StatusCode             = (int)HttpStatusCode.InternalServerError;
                filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
                filterContext.Result = new JsonResult
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = JsonConvert.SerializeObject(errorModel)
                };
                filterContext.ExceptionHandled = true;
            }
            else
            {
                base.OnException(filterContext);
            }
        }
Exemplo n.º 2
0
        protected void Application_Error(object sender, EventArgs e)
        {
            try
            {
                var ex = Server.GetLastError();
                Server.ClearError();
                NTGLogger.LogError(Context.Request, ex);

                var httpException = ex as HttpException;
                Response.StatusCode = httpException != null?httpException.GetHttpCode() : (int)HttpStatusCode.InternalServerError;

                if (IsMaxRequestExceededException(ex))
                {
                    this.Server.ClearError();
                    Context.ClearError();
                    var errorModel = new BaseAjaxModel();
                    errorModel.AddMessage(Message.GLOBAL, new Message("Unable to upload. Max file size exceeded", MessageTypes.Error));
                    Context.Response.ContentType = "application/json";
                    Context.Response.StatusCode  = 500;
                    Context.Response.Write(JsonConvert.SerializeObject(errorModel));
                }
            }
            catch (Exception) {
                return;
            }
        }
Exemplo n.º 3
0
        protected override void OnSubmit()
        {
            var fileName = Path.GetRandomFileName() + Path.GetExtension(Image.FileName).ToLower();
            var tempPath = Path.Combine(HttpContext.Current.Server.MapPath("~/App_Data/temp"), fileName);

            Image.SaveAs(tempPath);
            var result = CloudinaryService.UploadImage(Folder, fileName, Tags, tempPath);

            File.Delete(tempPath);

            if (string.IsNullOrEmpty(result.error))
            {
                Url      = result.uri.ToString();
                PublicId = result.publicId;

                var page = Page.Query.SingleOrDefault(p => p.UploadFolder == Folder);
                NTGLogger.LogSiteAction(HttpContext.Current.Request, Session.SessionVariables.User, "Uploaded image " + Url + " in folder: " + Folder, page?.Id, page?.Name, null, null);
                AddMessage(Message.GLOBAL, new Message("File successfully uploaded", MessageTypes.Success));
            }
            else
            {
                AddMessage(Message.GLOBAL, new Message("An error occurred while uploading the file. Please try again later", MessageTypes.Error));
                NTGLogger.LogError(HttpContext.Current.Request, "Cloudinary Error", result.error, nameof(UploadImageFormModel), nameof(CloudinaryService.UploadImage));
            }
        }
Exemplo n.º 4
0
        protected override bool OnValidate()
        {
            _pages = new List <Page>();
            foreach (var pageAction in PageActions)
            {
                var page = Page.Query.SingleOrDefault(p => p.Id == pageAction.Id);
                if (page == null)
                {
                    AddMessage("PageList", new Message("Page in collection with Id " + pageAction.Id + " does not exist", MessageTypes.Error));
                    return(false);
                }

                if (pageAction.Delete)
                {
                    if (pageAction.Position == 1 && pageAction.Delete)
                    {
                        AddMessage(Message.GLOBAL, new Message("Page with position 1 cannot be deleted", MessageTypes.Error));
                        NTGLogger.LogSecurityAction(HttpContext.Current.Request, SessionVariables.User, "Attempted to delete current home page " + page.Id + " '" + page.Name + "'");
                        return(false);
                    }

                    if (pageAction.Delete && page.AdminLocked && !SessionVariables.User.IsInRole("Admin"))
                    {
                        AddMessage("PageList", new Message("You are not permitted to delete admin locked page " + pageAction.Id, MessageTypes.Error));
                        NTGLogger.LogSecurityAction(HttpContext.Current.Request, SessionVariables.User, "Attempted to delete admin locked page " + page.Id + " '" + page.Name + "'");
                        return(false);
                    }
                }

                _pages.Add(page);
            }

            return(true);
        }
Exemplo n.º 5
0
 protected override bool OnValidate()
 {
     if (!Url.Contains(PublicId))
     {
         AddMessage(Message.GLOBAL, new Message("Cannot delete image: Url and Public Id differ", MessageTypes.Error));
         NTGLogger.LogSecurityAction(HttpContext.Current.Request, Session.SessionVariables.User, "Attempted to delete Cloudinary image with difference between Url and Public Id");
     }
     return(true);
 }
Exemplo n.º 6
0
        protected override bool OnValidate()
        {
            if (Name.ToLower().Equals("create"))
            {
                AddMessage(Message.GLOBAL, new Message("Non-valid page name: Create", MessageTypes.Error));
                return(false);
            }

            _page = Page.Query.Include(nameof(Page.PageModules)).SingleOrDefault(p => p.Name == PageName || p.Id == Id);
            if (_page != null && _page.Id != Id)
            {
                AddMessage(Message.GLOBAL, new Message("Page with name " + Name + " already exists", MessageTypes.Error));
                return(false);
            }

            if (AdminLocked.HasValue && !SessionVariables.User.IsInRole("Admin"))
            {
                AddMessage(Message.GLOBAL, new Message("You are not permitted to edit the admin lock on pages", MessageTypes.Error));
                NTGLogger.LogSecurityAction(HttpContext.Current.Request, SessionVariables.User, "Attempted to edit admin lock on " + _page.Id + " '" + _page.Name + "'");
                return(false);
            }

            if (Id != 0)
            {
                if (_page == null)
                {
                    AddMessage(Message.GLOBAL, new Message("Page does not exist", MessageTypes.Error));
                    return(false);
                }

                if (_page.AdminLocked && !SessionVariables.User.IsInRole("Admin"))
                {
                    AddMessage(Message.GLOBAL, new Message("You are not permitted to edit an admin locked page", MessageTypes.Error));
                    NTGLogger.LogSecurityAction(HttpContext.Current.Request, SessionVariables.User, "Attempted to edit admin locked page " + _page.Id + " '" + _page.Name + "'");
                    return(false);
                }

                if (ModuleActions != null)
                {
                    if (ModuleActions.GroupBy(mp => mp.Position).Any(mp => mp.Count() > 1))
                    {
                        AddMessage(Message.GLOBAL, new Message("Duplicate module positions are not allowed", MessageTypes.Error));
                        return(false);
                    }

                    if (ModuleActions.Any(mp => mp.Position < 1 || mp.Position > _page.PageModules.Count()))
                    {
                        AddMessage(Message.GLOBAL, new Message("A module has a non-valid position", MessageTypes.Error));
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 7
0
        protected void Application_PostAuthenticateRequest(object sender, EventArgs e)
        {
            if (FormsAuthentication.CookiesSupported)
            {
                try
                {
                    var authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
                    if (authCookie == null || string.IsNullOrEmpty(authCookie.Value))
                    {
                        return;
                    }

                    var authTicket = FormsAuthentication.Decrypt(authCookie.Value);
                    if (authTicket.UserData.Contains("Hazmat"))
                    {
                        var user = Admin.Query.Include(nameof(Admin.Role)).SingleOrDefault(a => a.Email == authTicket.Name && a.Active);

                        if (user == null)
                        {
                            NTGLogger.LogSecurityAction(Context.Request, "Attempted cookied forgery or use of non-active admin '" + (authTicket.Name ?? "Unknown") + "'", null, authTicket.Name, "Hazmat");
                            return;
                        }

                        HttpContext.Current.User = new NTGPrincipal(new GenericIdentity(authTicket.Name, "Forms"), new string[] { "Hazmat", user.Role.Name }, user.Id, user.Email, true);
                    }
                    else
                    {
                        //TODO: Change from Admin to User should a user base be established
                        var user = Admin.Query.SingleOrDefault(a => a.Email == authTicket.Name && a.Active);

                        if (user == null)
                        {
                            NTGLogger.LogSecurityAction(Context.Request, "Attempted cookied forgery or use of non-active member '" + (authTicket.Name ?? "Unknown") + "'", null, authTicket.Name, "Member");
                            return;
                        }

                        HttpContext.Current.User = new NTGPrincipal(new GenericIdentity(authTicket.Name, "Forms"), new string[] { "Member" }, user.Id, user.Email, false);
                    }

                    if (authTicket.IsPersistent)
                    {
                        authCookie.Expires = DateTime.Now.AddDays(30);
                        Response.Cookies.Set(authCookie);
                    }
                }
                catch (Exception ex)
                {
                    var request = Context.Request;
                    NTGLogger.LogError(Context.Request, ex);
                }
            }
        }
Exemplo n.º 8
0
        protected override void OnSubmit()
        {
            var isNew = _module == null;

            if (isNew)
            {
                _module     = new ModulePromo();
                _pageModule = new PageModule();
                _pageModule.ModuleTypeId = ModuleService.ModuleTypes[ModuleService.MODULE_PROMO];
                _pageModule.PageId       = _page.Id;
                _pageModule.Position     = _page.PageModules.Count + 1;
                Position = _pageModule.Position;
            }

            _module.Image                     = Image;
            _module.Text                      = Text;
            _module.ButtonText                = ButtonText;
            _module.ButtonLink                = !string.IsNullOrEmpty(ButtonText) ? ButtonLink : string.Empty;
            _module.ImageRight                = ImageRight;
            _module.TitleTop                  = TitleTop;
            _pageModule.Title                 = Title;
            _pageModule.BlueTitle             = BlueTitle;
            _pageModule.Theme                 = Theme;
            _pageModule.TransparentBackground = TransparentBackground;
            _pageModule.LootBox               = LootBox;
            _pageModule.LootBoxTop            = LootBoxTop;
            _pageModule.LootBoxLeft           = LootBoxLeft;
            _pageModule.State                 = State;

            using (var conn = new NTGDBTransactional())
            {
                _module.Save(conn);
                _pageModule.ModuleId = _module.Id;
                _pageModule.Save(conn);

                NTGLogger.LogSiteAction(HttpContext.Current.Request,
                                        SessionVariables.User,
                                        (isNew ? "Created" : "Editted") + " Module",
                                        _page.Id,
                                        _page.Name,
                                        _module.Id,
                                        ModuleService.MODULE_PROMO,
                                        conn);

                conn.Commit();
                Id           = _module.Id;
                PageModuleId = _pageModule.Id;
                ModuleService.RefreshCacheModule(_pageModule.Id);
                AddMessage(Message.GLOBAL, new Message("Module saved", MessageTypes.Success));
            }
        }
Exemplo n.º 9
0
        protected override void OnSubmit()
        {
            var result = CloudinaryService.DeleteImage(PublicId);

            if (string.IsNullOrEmpty(result.error))
            {
                NTGLogger.LogSiteAction(HttpContext.Current.Request, Session.SessionVariables.User, "Deleted image " + Url, null, null, null, null);
                AddMessage(Message.GLOBAL, new Message("File successfully deleted", MessageTypes.Success));
            }
            else
            {
                AddMessage(Message.GLOBAL, new Message("An error occurred while deleting the image. Please try again later", MessageTypes.Error));
                NTGLogger.LogError(HttpContext.Current.Request, "Cloudinary Error", result.error, nameof(DeleteImageFormModel), nameof(CloudinaryService.DeleteImage));
            }
        }
Exemplo n.º 10
0
        protected override bool OnValidate()
        {
            var password = EncryptionService.Encrypt(Password);

            Password = string.Empty;

            _admin = Admin.Query.Include(nameof(Admin.Role)).SingleOrDefault(a => a.Email == Email && a.Password == password && a.Active);
            if (_admin == null)
            {
                AddMessage(Message.GLOBAL, new Message("Invalid email or password", MessageTypes.Warning));
                NTGLogger.LogSecurityAction(HttpContext.Current.Request, "Failed login attempt", null, Email, "Hazmat");
                return(false);
            }

            _roles = _admin.Role.Name + ",Hazmat";
            return(true);
        }
        protected override bool OnValidate()
        {
            _page = Page.Query.Include(nameof(Page.PageModules)).SingleOrDefault(p => p.Name.Equals(PageName, StringComparison.OrdinalIgnoreCase));
            if (_page == null)
            {
                AddMessage(Message.GLOBAL, new Message("Attempted to save module to non-existing page", MessageTypes.Error));
                return(false);
            }

            if (_page.AdminLocked && !SessionVariables.User.IsInRole("Admin"))
            {
                AddMessage(Message.GLOBAL, new Message("You are not permitted to edit an admin locked page", MessageTypes.Error));
                NTGLogger.LogSecurityAction(HttpContext.Current.Request, SessionVariables.User, "Attempted to edit/create module in admin locked page" + _page.Id + " '" + _page.Name + "'");
                return(false);
            }

            if (Id != 0)
            {
                _module = ModuleGallery.Query.SingleOrDefault(mg => mg.Id == Id);
                if (_module == null)
                {
                    AddMessage(Message.GLOBAL, new Message("Module not found", MessageTypes.Error));
                    return(false);
                }

                var moduleTypeId = ModuleService.ModuleTypes[ModuleService.MODULE_GALLERY];
                _pageModule = PageModule.Query.SingleOrDefault(mg => mg.ModuleId == _module.Id && mg.ModuleTypeId == moduleTypeId && mg.PageId == _page.Id);
                if (_pageModule == null)
                {
                    AddMessage(Message.GLOBAL, new Message("Module does not belong to current page", MessageTypes.Error));
                    return(false);
                }

                if (Images == null || !Images.Any(b => !b.IsDelete))
                {
                    AddMessage(nameof(State) + GetErrorMessageSufix(), new Message("Module Gallery requires at least one card", MessageTypes.Warning));
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 12
0
        protected override bool OnValidate()
        {
            if (Image == null)
            {
                AddMessage(Message.GLOBAL, new Message("No file chosen", MessageTypes.Warning));
                return(false);
            }

            if (Image != null)
            {
                var isImageError = Image.IsImage();
                if (!string.IsNullOrEmpty(isImageError))
                {
                    AddMessage(Message.GLOBAL, new Message("Chosen file is not an image", MessageTypes.Warning));
                    NTGLogger.LogSecurityAction(HttpContext.Current.Request, Session.SessionVariables.User, "Attempted to upload Cloudinary non-image file of type" + Image.ContentType.ToLower() + ": " + isImageError);
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 13
0
        protected override void OnSubmit()
        {
            var admin = new Admin()
            {
                Email     = Email,
                FirstName = FirstName,
                LastName  = LastName,
                Password  = EncryptionService.Encrypt(Password),
                RoleId    = _role.Id,
                Active    = true
            };

            using (var conn = new NTGDBTransactional())
            {
                admin.Save(conn);
                NTGLogger.LogSecurityAction(HttpContext.Current.Request, _sessionUser, "Created user " + admin.Id + " '" + admin.Email + "' with role " + _role.Name, conn);
                conn.Commit();
            }

            AddMessage(Message.GLOBAL, new Message("User successfully created", MessageTypes.Success));
        }
Exemplo n.º 14
0
        protected override void OnSubmit()
        {
            var now        = DateTime.UtcNow;
            var authTicket = new FormsAuthenticationTicket(
                1,
                Email,
                now,
                now.AddYears(100),
                Persist,
                "Hazmat",
                FormsAuthentication.FormsCookiePath
                );

            var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket));

            if (authTicket.IsPersistent)
            {
                cookie.Expires = now.AddDays(30);
            }

            HttpContext.Current.Response.Cookies.Add(cookie);
            NTGLogger.LogSecurityAction(HttpContext.Current.Request, "Successful login", _admin.Id, _admin.Email, _roles);
        }
Exemplo n.º 15
0
        protected override bool OnValidate()
        {
            _page = Page.Query.Include(nameof(Page.PageModules)).SingleOrDefault(p => p.Name.Equals(PageName, StringComparison.OrdinalIgnoreCase));
            if (_page == null)
            {
                AddMessage(Message.GLOBAL, new Message("Attempted to save module to non-existing page", MessageTypes.Error));
                return(false);
            }

            if (_page.AdminLocked && !SessionVariables.User.IsInRole("Admin"))
            {
                AddMessage(Message.GLOBAL, new Message("You are not permitted to edit an admin locked page", MessageTypes.Error));
                NTGLogger.LogSecurityAction(HttpContext.Current.Request, SessionVariables.User, "Attempted to edit/create module in admin locked page" + _page.Id + " '" + _page.Name + "'");
                return(false);
            }

            if (Id != 0)
            {
                _module = ModulePromo.Query.SingleOrDefault(mc => mc.Id == Id);
                if (_module == null)
                {
                    AddMessage(Message.GLOBAL, new Message("Module not found", MessageTypes.Error));
                    return(false);
                }

                var moduleTypeId = ModuleService.ModuleTypes[ModuleService.MODULE_PROMO];
                _pageModule = PageModule.Query.SingleOrDefault(mp => mp.ModuleId == _module.Id && mp.ModuleTypeId == moduleTypeId && mp.PageId == _page.Id);
                if (_pageModule == null)
                {
                    AddMessage(Message.GLOBAL, new Message("Module does not belong to current page", MessageTypes.Error));
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 16
0
        protected override bool OnValidate()
        {
            _sessionUser = SessionVariables.User;
            var valid = true;

            _admin = Admin.Query.Include(nameof(Admin.Role)).SingleOrDefault(a => a.Email == User);
            if (_admin == null)
            {
                AddMessage(Message.GLOBAL, new Message("User " + User + " does not exist", MessageTypes.Error));
                NTGLogger.LogSecurityAction(HttpContext.Current.Request, _sessionUser, "Attempted to edit non-existing admin '" + User + "'");
                return(false);
            }

            if (_sessionUser.IsInRole("Admin"))
            {
                if (!_admin.Email.Equals(_sessionUser.Email) && _admin.Role.Name.Equals("Admin"))
                {
                    AddMessage(Message.GLOBAL, new Message("You are not permitted to modify other users with the Admin role", MessageTypes.Error));
                    NTGLogger.LogSecurityAction(HttpContext.Current.Request, _sessionUser, "Attempted to edit admin " + _admin.Id + " '" + _admin.Email + "'");
                    return(false);
                }

                if (RoleId.HasValue && _admin.RoleId != RoleId)
                {
                    _role = Role.Query.SingleOrDefault(r => r.Id == RoleId.Value);
                    if (_role == null)
                    {
                        AddMessage(nameof(RoleId), new Message("Attempted to assign non-existing role", MessageTypes.Error));
                        NTGLogger.LogSecurityAction(HttpContext.Current.Request, _sessionUser, "Attempted to assign non-existing role to admin " + _admin.Id + " '" + _admin.Email + "'");
                        return(false);
                    }
                }
            }
            else
            {
                if (!_admin.Active)
                {
                    AddMessage(Message.GLOBAL, new Message("Unable to save changes: user is no longer active", MessageTypes.Error));
                    NTGLogger.LogSecurityAction(HttpContext.Current.Request, _sessionUser, "Attempted to save changes to inactive admin " + _admin.Id + " '" + _admin.Email + "'");
                    return(false);
                }

                if (!_admin.Email.Equals(_sessionUser.Email))
                {
                    AddMessage(Message.GLOBAL, new Message("You are not permitted to modify other users", MessageTypes.Error));
                    NTGLogger.LogSecurityAction(HttpContext.Current.Request, _sessionUser, "Attempted to modify admin " + _admin.Id + " '" + _admin.Email + "'");
                    return(false);
                }

                if (Active.HasValue)
                {
                    AddMessage(Message.GLOBAL, new Message("You are not permitted to change activation of users", MessageTypes.Error));
                    NTGLogger.LogSecurityAction(HttpContext.Current.Request, _sessionUser, "Attempted to reactivate/deactivate admin " + _admin.Id + " '" + _admin.Email + "'");
                    return(false);
                }

                if (RoleId.HasValue)
                {
                    AddMessage(Message.GLOBAL, new Message("You are not permitted to change the role of users", MessageTypes.Error));
                    NTGLogger.LogSecurityAction(HttpContext.Current.Request, _sessionUser, "Attempted to change role of admin " + _admin.Id + " '" + _admin.Email + "'");
                    return(false);
                }
            }

            if (Admin.Query.Any(a => a.Email == Email && a.Id != _admin.Id))
            {
                AddMessage(nameof(Email), new Message("Email is already in use", MessageTypes.Warning));
                valid = false;
            }

            if (!string.IsNullOrEmpty(Password) && !Password.Equals(VerifyPassword))
            {
                AddMessage(nameof(Password), new Message("Passwords do not match", MessageTypes.Warning));
                valid = false;
            }

            return(valid);
        }
Exemplo n.º 17
0
        protected override void OnSubmit()
        {
            var isNew = _page == null;

            if (isNew)
            {
                _page = new Page();
                _page.UploadFolder = Path.GetRandomFileName();
                _page.Position     = Page.Query.Count() + 1;
            }

            using (var conn = new NTGDBTransactional())
            {
                if (_page.Id == 0 || !_page.Name.Equals(Name))
                {
                    RedirectTo = Name.Replace(" ", "-").ToLower();
                }

                _page.Name            = Name;
                _page.HeroImage       = HeroImage;
                _page.MobileHeroImage = !string.IsNullOrEmpty(HeroImage) ? MobileHeroImage : null;

                /*The page with position 1 is the equivalent of home and should always have
                 * InMenu and as false because it has its own logic to appear in the top menu as the home link*/
                _page.InMenu       = _page.Position == 1 ? false : InMenu;
                _page.InBottomMenu = _page.Position == 1 ? false : InBottomMenu;
                //The home page cannot be inactive
                _page.Visible = _page.Position == 1 ? true : Visible;

                if (AdminLocked.HasValue)
                {
                    _page.AdminLocked = AdminLocked.Value;
                    if (!isNew)
                    {
                        NTGLogger.LogSiteAction(HttpContext.Current.Request,
                                                SessionVariables.User,
                                                "Changed admin lock on page",
                                                _page.Id,
                                                _page.Name,
                                                null,
                                                null,
                                                conn);
                    }
                }

                _page.Save(conn);

                foreach (var module in _page.PageModules.OrderBy(pm => ModuleActions.OrderBy(ma => ma.Position).Select(ma => ma.Id).ToList().IndexOf(pm.Id)))
                {
                    var action = ModuleActions.SingleOrDefault(ma => ma.Id == module.Id);
                    if (action != null)
                    {
                        if (action.Delete)
                        {
                            ModuleService.DeleteModule(module, conn);
                            foreach (var nextAction in ModuleActions.Where(ma => ma.Position > action.Position))
                            {
                                nextAction.Position -= 1;
                            }
                            NTGLogger.LogSiteAction(HttpContext.Current.Request,
                                                    SessionVariables.User,
                                                    "Deleted Module",
                                                    _page.Id,
                                                    _page.Name,
                                                    module.ModuleId,
                                                    ModuleType.Query.FirstOrDefault(mt => mt.Id == module.ModuleTypeId)?.Name,
                                                    conn);
                        }
                        else if (module.Position != action.Position)
                        {
                            module.Position = action.Position;
                            module.Save(conn);
                        }
                    }
                }

                NTGLogger.LogSiteAction(HttpContext.Current.Request,
                                        SessionVariables.User,
                                        (isNew ? "Created" : "Editted") + " Page",
                                        _page.Id,
                                        _page.Name,
                                        null,
                                        null,
                                        conn);

                conn.Commit();
                ModuleService.RefreshModulesCache(_page.Id);
                AddMessage(Message.GLOBAL, new Message("Page " + Name + " successfully saved", MessageTypes.Success));
            }
        }
Exemplo n.º 18
0
        protected override void OnSubmit()
        {
            _siteSettings = Global.GlobalVariables.SiteSettings;

            #region Layout

            _siteSettings.HeaderHomeImageUrl      = HeaderHomeImageUrl;
            _siteSettings.FooterHomeImageUrlLight = FooterHomeImageUrlLight;
            _siteSettings.FooterHomeImageUrlDark  = FooterHomeImageUrlDark;
            _siteSettings.LoadingImageUrl         = LoadingImageUrl;
            _siteSettings.BlogUrl     = BlogUrl;
            _siteSettings.ForumUrl    = ForumUrl;
            _siteSettings.ShopUrl     = ShopUrl;
            _siteSettings.FacebookUrl = FacebookUrl;
            _siteSettings.TwitterUrl  = TwitterUrl;
            _siteSettings.RedditUrl   = RedditUrl;
            _siteSettings.YouTubeUrl  = YouTubeUrl;
            _siteSettings.TwitchUrl   = TwitchUrl;

            #endregion

            #region Loot Box

            _siteSettings.LootBoxImageUrl   = LootBoxImageUrl;
            _siteSettings.LootBoxPopupTitle = LootBoxPopupTitle;
            _siteSettings.LootBoxPopupText  = LootBoxPopupText;

            #endregion

            #region Meta Tags

            _siteSettings.MetaFaviconImageUrl = MetaFaviconImageUrl;
            _siteSettings.MetaSiteTitle       = MetaSiteTitle;
            _siteSettings.MetaSiteDescription = MetaSiteDescription;

            #endregion

            #region Open Graph Tags

            _siteSettings.MetaOgImageUrl    = MetaOgImageUrl;
            _siteSettings.MetaOgImageType   = MetaOgImageType;
            _siteSettings.MetaOgImageWidth  = MetaOgImageWidth;
            _siteSettings.MetaOgImageHeight = MetaOgImageHeight;
            _siteSettings.MetaOgUrl         = MetaOgUrl;
            _siteSettings.MetaOgSiteName    = MetaOgSiteName;
            _siteSettings.MetaOgTitle       = MetaOgTitle;
            _siteSettings.MetaOgDescription = MetaOgDescription;
            _siteSettings.MetaOgType        = MetaOgType;
            _siteSettings.MetaOgLocale      = MetaOgLocale;

            #endregion

            #region Twitter Tags

            _siteSettings.MetaTwitterImageUrl    = MetaTwitterImageUrl;
            _siteSettings.MetaTwitterCard        = MetaTwitterCard;
            _siteSettings.MetaTwitterSite        = MetaTwitterSite;
            _siteSettings.MetaTwitterTitle       = MetaTwitterTitle;
            _siteSettings.MetaTwitterDescription = MetaTwitterDescription;

            #endregion

            #region Error Pages

            _siteSettings.ErrorImageIconTopUrl = ErrorImageIconTopUrl;
            _siteSettings.ErrorImage401Url     = ErrorImage401Url;
            _siteSettings.ErrorImage403Url     = ErrorImage403Url;
            _siteSettings.ErrorImage404Url     = ErrorImage404Url;
            _siteSettings.ErrorImage500Url     = ErrorImage500Url;
            _siteSettings.ErrorImage503Url     = ErrorImage503Url;

            #endregion

            using (var conn = new NTGDBTransactional())
            {
                NTGLogger.LogSiteAction(HttpContext.Current.Request, SessionVariables.User, "Editted Site Settings", null, null, null, null, conn);

                _siteSettings.Save(conn);
                conn.Commit();
            }

            AddMessage(Message.GLOBAL, new Message("Changes successfully saved", MessageTypes.Success));
        }
Exemplo n.º 19
0
        protected override void OnSubmit()
        {
            var deleteLog = string.Empty;
            var orderLog  = string.Empty;

            using (var conn = new NTGDBTransactional())
            {
                foreach (var page in _pages.OrderBy(p => PageActions.OrderBy(pa => pa.Position).Select(pa => pa.Id).ToList().IndexOf(p.Id)))
                {
                    var action = PageActions.SingleOrDefault(pa => pa.Id == page.Id);
                    if (action != null)
                    {
                        if (action.Delete)
                        {
                            var pageModules = PageModule.Query.Where(pm => pm.PageId == page.Id);
                            foreach (var pageModule in pageModules)
                            {
                                ModuleService.DeleteModule(pageModule, conn);
                            }

                            var cloudinaryResult = CloudinaryService.DeleteFolder(page.UploadFolder);
                            if (!string.IsNullOrEmpty(cloudinaryResult.error))
                            {
                                NTGLogger.LogError(HttpContext.Current.Request, "Cloudinary Error", cloudinaryResult.error, nameof(PageListFormModel), nameof(CloudinaryService.DeleteFolder), conn);
                            }
                            page.Delete(conn);
                            deleteLog += " - " + action.Id;
                            foreach (var nextAction in PageActions.Where(pa => pa.Position > action.Position))
                            {
                                nextAction.Position -= 1;
                            }
                        }
                        else if (page.Position != action.Position)
                        {
                            page.Position = action.Position;
                            page.Save(conn);
                            orderLog += " - " + action.Id;
                        }
                    }
                }

                if (!string.IsNullOrEmpty(orderLog))
                {
                    NTGLogger.LogSiteAction(HttpContext.Current.Request,
                                            SessionVariables.User,
                                            "Changed pages order " + orderLog,
                                            null,
                                            null,
                                            null,
                                            null,
                                            conn);
                }

                if (!string.IsNullOrEmpty(deleteLog))
                {
                    NTGLogger.LogSiteAction(HttpContext.Current.Request,
                                            SessionVariables.User,
                                            "Deleted pages " + deleteLog,
                                            null,
                                            null,
                                            null,
                                            null,
                                            conn);
                }

                conn.Commit();
                AddMessage(Message.GLOBAL, new Message("Pages successfully saved", MessageTypes.Success));
            }
        }
        protected override void OnSubmit()
        {
            var isNew = _module == null;

            if (isNew)
            {
                _module     = new ModuleGallery();
                _pageModule = new PageModule();
                _pageModule.ModuleTypeId = ModuleService.ModuleTypes[ModuleService.MODULE_GALLERY];
                _pageModule.PageId       = _page.Id;
                _pageModule.Position     = _page.PageModules.Count + 1;
                Position = _pageModule.Position;
            }

            _pageModule.Title                 = Title;
            _pageModule.BlueTitle             = BlueTitle;
            _pageModule.Theme                 = Theme;
            _pageModule.TransparentBackground = TransparentBackground;
            _pageModule.LootBox               = LootBox;
            _pageModule.LootBoxTop            = LootBoxTop;
            _pageModule.LootBoxLeft           = LootBoxLeft;
            _pageModule.State                 = State;

            using (var conn = new NTGDBTransactional())
            {
                _module.Save(conn);
                var subFormSuccess    = true;
                var subForm           = new CreateEditModuleGalleryImageSubFormModel();
                var positionReduction = 0;
                foreach (var image in Images.OrderBy(i => i.Position))
                {
                    if (image.IsDelete)
                    {
                        positionReduction++;
                    }
                    else if (positionReduction > 0)
                    {
                        image.IsModified = true;
                        image.Position  -= positionReduction;
                    }

                    if (image.IsModified || image.IsDelete)
                    {
                        subForm.Id            = image.Id;
                        subForm.Image         = image.Image;
                        subForm.Position      = image.Position;
                        subForm.ModuleGallery = _module;
                        subForm.IsDelete      = image.IsDelete;
                        subForm.IsNewModule   = Id == 0;
                        subForm.Links         = image.ModuleGalleryImageLinks.ToList();
                        subForm.Submit(conn, Messages);

                        subFormSuccess                = subFormSuccess && subForm.Success;
                        image.Id                      = subForm.Id;
                        image.ModuleGalleryId         = subForm.ModuleGallery.Id;
                        image.ModuleGalleryImageLinks = subForm.Links;
                        image.IsModified              = false;
                    }
                }

                if (subFormSuccess)
                {
                    _pageModule.ModuleId = _module.Id;
                    _pageModule.Save(conn);

                    NTGLogger.LogSiteAction(HttpContext.Current.Request,
                                            SessionVariables.User,
                                            (isNew ? "Created" : "Editted") + " Module",
                                            _page.Id,
                                            _page.Name,
                                            _module.Id,
                                            ModuleService.MODULE_GALLERY,
                                            conn);

                    conn.Commit();
                    Id           = _module.Id;
                    PageModuleId = _pageModule.Id;
                    Images.RemoveAll(c => c.IsDelete);
                    ModuleService.RefreshCacheModule(_pageModule.Id);
                    AddMessage(Message.GLOBAL, new Message("Module saved", MessageTypes.Success));
                }
            }
        }
        protected override void OnSubmit()
        {
            var isNew = _module == null;

            if (isNew)
            {
                _module     = new ModuleProfileCards();
                _pageModule = new PageModule();
                _pageModule.ModuleTypeId = ModuleService.ModuleTypes[ModuleService.MODULE_PROFILE_CARDS];
                _pageModule.PageId       = _page.Id;
                _pageModule.Position     = _page.PageModules.Count + 1;
                Position = _pageModule.Position;
            }

            _pageModule.Title                 = Title;
            _pageModule.BlueTitle             = BlueTitle;
            _pageModule.Theme                 = Theme;
            _pageModule.TransparentBackground = TransparentBackground;
            _pageModule.LootBox               = LootBox;
            _pageModule.LootBoxTop            = LootBoxTop;
            _pageModule.LootBoxLeft           = LootBoxLeft;
            _pageModule.State                 = State;

            using (var conn = new NTGDBTransactional())
            {
                _module.Save(conn);
                var subFormSuccess    = true;
                var subForm           = new CreateEditModuleProfileCardsCardSubFormModel();
                var positionReduction = 0;
                foreach (var card in Cards.OrderBy(c => c.Position))
                {
                    if (card.IsDelete)
                    {
                        positionReduction++;
                    }
                    else if (positionReduction > 0)
                    {
                        card.IsModified = true;
                        card.Position  -= positionReduction;
                    }

                    if (card.IsModified || card.IsDelete)
                    {
                        subForm.Id                 = card.Id;
                        subForm.Name               = card.Name;
                        subForm.FacebookUrl        = card.FacebookUrl;
                        subForm.TwitterUrl         = card.TwitterUrl;
                        subForm.TwitchUrl          = card.TwitchUrl;
                        subForm.InstagramUrl       = card.InstagramUrl;
                        subForm.YouTubeUrl         = card.YouTubeUrl;
                        subForm.Image              = card.Image;
                        subForm.Position           = card.Position;
                        subForm.ModuleProfileCards = _module;
                        subForm.IsNewModule        = Id == 0;
                        subForm.IsDelete           = card.IsDelete;
                        subForm.Links              = card.ModuleProfileCardsCardLinks.ToList();
                        subForm.Submit(conn, Messages);

                        subFormSuccess                   = subFormSuccess && subForm.Success;
                        card.Id                          = subForm.Id;
                        card.ModuleProfileCardsId        = subForm.ModuleProfileCards.Id;
                        card.ModuleProfileCardsCardLinks = subForm.Links;
                        card.IsModified                  = false;
                    }
                }

                if (subFormSuccess)
                {
                    _pageModule.ModuleId = _module.Id;
                    _pageModule.Save(conn);

                    NTGLogger.LogSiteAction(HttpContext.Current.Request,
                                            SessionVariables.User,
                                            (isNew ? "Created" : "Editted") + " Module",
                                            _page.Id,
                                            _page.Name,
                                            _module.Id,
                                            ModuleService.MODULE_PROFILE_CARDS,
                                            conn);

                    conn.Commit();
                    Id           = _module.Id;
                    PageModuleId = _pageModule.Id;
                    Cards.RemoveAll(c => c.IsDelete);
                    ModuleService.RefreshCacheModule(_pageModule.Id);
                    AddMessage(Message.GLOBAL, new Message("Module saved", MessageTypes.Success));
                }
            }
        }
        protected override void OnSubmit()
        {
            var isNew = _module == null;

            if (isNew)
            {
                _module     = new ModuleBoxes();
                _pageModule = new PageModule();
                _pageModule.ModuleTypeId = ModuleService.ModuleTypes[ModuleService.MODULE_BOXES];
                _pageModule.PageId       = _page.Id;
                _pageModule.Position     = _page.PageModules.Count + 1;
                Position = _pageModule.Position;
            }

            _module.Text                      = Text;
            _pageModule.Title                 = Title;
            _pageModule.BlueTitle             = BlueTitle;
            _pageModule.Theme                 = Theme;
            _pageModule.TransparentBackground = TransparentBackground;
            _pageModule.LootBox               = LootBox;
            _pageModule.LootBoxLeft           = LootBoxLeft;
            _pageModule.LootBoxTop            = LootBoxTop;
            _pageModule.State                 = State;

            using (var conn = new NTGDBTransactional())
            {
                _module.Save(conn);

                var subFormSuccess    = true;
                var subForm           = new CreateEditModuleBoxesBoxSubFormModel();
                var positionReduction = 0;
                foreach (var box in Boxes.OrderBy(b => b.Position))
                {
                    if (box.IsDelete)
                    {
                        positionReduction++;
                    }
                    else if (positionReduction > 0)
                    {
                        box.IsModified = true;
                        box.Position  -= positionReduction;
                    }

                    if (box.IsModified || box.IsDelete)
                    {
                        subForm.Id          = box.Id;
                        subForm.Title       = box.Title;
                        subForm.Icon        = box.Icon;
                        subForm.Color       = box.Color;
                        subForm.Text        = box.Text;
                        subForm.Url         = box.Url;
                        subForm.Position    = box.Position;
                        subForm.ModuleBoxes = _module;
                        subForm.IsDelete    = box.IsDelete;
                        subForm.IsNewModule = Id == 0;
                        subForm.Submit(conn, Messages);

                        subFormSuccess    = subFormSuccess && subForm.Success;
                        box.Id            = subForm.Id;
                        box.ModuleBoxesId = subForm.ModuleBoxes.Id;
                        box.IsModified    = false;
                    }
                }

                if (subFormSuccess)
                {
                    _pageModule.ModuleId = _module.Id;
                    _pageModule.Save(conn);

                    NTGLogger.LogSiteAction(HttpContext.Current.Request,
                                            SessionVariables.User,
                                            (isNew ? "Created" : "Editted") + " Module",
                                            _page.Id,
                                            _page.Name,
                                            _module.Id,
                                            ModuleService.MODULE_BOXES,
                                            conn);
                    conn.Commit();

                    Id           = _module.Id;
                    PageModuleId = _pageModule.Id;
                    Boxes.RemoveAll(b => b.IsDelete);
                    ModuleService.RefreshCacheModule(_pageModule.Id);
                    AddMessage(Message.GLOBAL, new Message("Module saved", MessageTypes.Success));
                }
            }
        }
Exemplo n.º 23
0
        protected override void OnSubmit()
        {
            string oldRole         = null;
            var    emailChanged    = !_admin.Email.Equals(Email);
            var    passwordChanged = !string.IsNullOrEmpty(Password);
            var    activeChanged   = Active.HasValue && _admin.Active != Active.Value;

            _admin.FirstName = FirstName;
            _admin.LastName  = LastName;

            using (var conn = new NTGDBTransactional())
            {
                NTGLogger.LogSecurityAction(HttpContext.Current.Request, _sessionUser, "Editted user " + _admin.Id + " '" + _admin.Email + "'", conn);

                if (activeChanged)
                {
                    _admin.Active = Active.Value;
                    NTGLogger.LogSecurityAction(HttpContext.Current.Request, _sessionUser, (_admin.Active ? "Reactivated" : "Deactivated") + " admin " + _admin.Id + " '" + _admin.Email + "'", conn);
                }

                if (emailChanged)
                {
                    NTGLogger.LogSecurityAction(HttpContext.Current.Request, _sessionUser, "Changed email of admin " + _admin.Id + " '" + _admin.Email + "': " + _admin.Email + " to " + Email);
                    _admin.Email = Email;
                }

                if (passwordChanged)
                {
                    NTGLogger.LogSecurityAction(HttpContext.Current.Request, _sessionUser, "Changed password of admin " + _admin.Id + " '" + _admin.Email + "'", conn);
                    var encryptedPassword = EncryptionService.Encrypt(Password);
                    _admin.Password = encryptedPassword;
                    Password        = string.Empty;
                    VerifyPassword  = string.Empty;
                }

                if (_role != null)
                {
                    NTGLogger.LogSecurityAction(HttpContext.Current.Request, _sessionUser, "Changed role of admin " + _admin.Id + " '" + _admin.Email + "': " + oldRole + " to " + _role.Name, conn);
                    oldRole       = _admin.Role.Name;
                    _admin.RoleId = _role.Id;
                }

                _admin.Save(conn);
                conn.Commit();
            }


            Relog = User == _sessionUser.Email && (emailChanged || passwordChanged || activeChanged);
            if (Relog)
            {
                FormsAuthentication.SignOut();
                if (activeChanged)
                {
                    AddMessage(Message.GLOBAL, new Message("User has been deactivated. Good Bye!", MessageTypes.Success));
                }
                else
                {
                    AddMessage(Message.GLOBAL, new Message("User access information changed. Please log in again", MessageTypes.Success));
                }
            }

            AddMessage(Message.GLOBAL, new Message("Changes successfully saved", MessageTypes.Success));
        }