public Data CreateSite(string siteName) { if (User.Identity.IsAuthenticated) { string root = Server.MapPath(".") + "/Sites/"; var entities = new WebPageEntities(); var user = entities.AspNetUsers.Where(i => i.UserName == User.Identity.Name).FirstOrDefault(); var site = entities.Sites.Where(i => i.SiteName == siteName && i.UserId == user.Id).FirstOrDefault(); if (site != null) { return(new Data { Error = "Site Name already exists.<br>Choose another Name." }); } if (user != null) { var userFolder = Path.Combine(root, user.Id); if (Directory.Exists(userFolder)) { var siteFolder = Path.Combine(userFolder, siteName); if (!Directory.Exists(siteFolder)) { try { Directory.CreateDirectory(siteFolder); var siteToCreate = new WAG_Login_Page.Site(); siteToCreate.UserId = user.Id; siteToCreate.SiteName = siteName; entities.Sites.Add(siteToCreate); entities.SaveChanges(); return(new Data { Success = true }); } catch (Exception ex) { return(new Data { Success = false, Error = "", ExceptionError = ex.Message }); } } } } } return(new Data { Success = false }); }
public List <Data> GetSites() { List <Data> siteData = new List <Data>(); if (User.Identity.IsAuthenticated) { var entities = new WebPageEntities(); var user = entities.AspNetUsers.Where(i => i.UserName == User.Identity.Name).FirstOrDefault(); if (user != null) { var sites = entities.Sites.Where(i => i.UserId == user.Id); if (sites != null && sites.Count() > 0) { foreach (var site in sites) { siteData.Add(new Data { Name = site.SiteName }); } } } } return(siteData); }
public Data Download(string siteName) { if (User.Identity.IsAuthenticated && siteName != null && siteName != "" && siteName.Trim() != "") { try { siteName = siteName.Replace(".", "").Replace("\\", "").Replace("/", ""); var entities = new WebPageEntities(); var user = entities.AspNetUsers.Where(i => i.UserName == User.Identity.Name).FirstOrDefault(); string random = GetRandomString(3); string random2 = GetRandomString(6); string startPath = Path.Combine(Server.MapPath(".") + "/sites/", user.Id + "/" + siteName); string zipFileDir = Path.Combine(Server.MapPath("."), "../public_downloads/"); string zipPath = Path.Combine(Server.MapPath("."), "../public_downloads/" + random + "1n1" + user.Id.Replace("-", "") + "k4" + random2 + "-" + siteName + ".zip"); string internetZipPath = "/public_downloads/" + random + "1n1" + user.Id.Replace("-", "") + "k4" + random2 + "-" + siteName + ".zip"; if (!Directory.Exists(zipFileDir)) { Directory.CreateDirectory(zipFileDir); } Directory.GetFiles(zipFileDir) .Select(f => new FileInfo(f)) .Where(f => f.LastAccessTime < DateTime.Now.AddHours(-1)) .ToList() .ForEach(f => f.Delete()); if (File.Exists(zipPath)) { File.Delete(zipPath); } ZipFile.CreateFromDirectory(startPath, zipPath); return(new Data { Success = true, Link = internetZipPath }); } catch (Exception ex) { return(new Data { Success = false, Error = ex.Message }); } } return(new Data { Success = false, Error = "" }); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { var entities = new WebPageEntities(); var user = entities.AspNetUsers.Where(i => i.UserName == User.Identity.Name).FirstOrDefault(); if (user != null) { ViewState["UD"] = user.Id; } } }
protected void Page_Load(object sender, EventArgs e) { SiteName = Request.QueryString["SiteName"]; PageName = Request.QueryString["PageName"]; HttpCookie authCookie = Request.Cookies[".AspNet.ApplicationCookie"]; CookieValue = authCookie.Value; HttpCookie myCookie = new HttpCookie("jQuery"); HttpCookie myCookie2 = new HttpCookie("hatway"); DateTime now = DateTime.Now; myCookie.Value = CookieValue; string key = EDC2.EDC.Key; myCookie2.Value = "Ae343efDDgA/dDFEFAadA4dD/AeD=ADDED/D===="; // Add the cookie. myCookie.Expires = authCookie.Expires; myCookie2.Expires = authCookie.Expires; Response.Cookies.Add(myCookie); Response.Cookies.Add(myCookie2); var entities = new WebPageEntities(); var user = entities.AspNetUsers.Where(i => i.UserName == User.Identity.Name).FirstOrDefault(); if (user != null) { SiteId = user.Id; } Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.AppendCacheExtension("no-store, must-revalidate"); Response.ExpiresAbsolute = DateTime.Now.AddDays(-1); Response.AppendHeader("Pragma", "no-cache"); Response.AppendHeader("Expires", "0"); Response.Cache.SetNoServerCaching(); Response.Buffer = true; }
public List <ImageJQ> GetImages(int start, int pageSize) { List <ImageJQ> imagesList = new List <ImageJQ>(); if (User.Identity.IsAuthenticated) { try { var entities = new WebPageEntities(); var user = entities.AspNetUsers.Where(i => i.UserName == User.Identity.Name).FirstOrDefault(); int count = entities.Images.OrderByDescending(k => k.id).Count(i => i.UserId == user.Id); if (count > 0 && count > start) { var images = entities.Images.Where(i => i.UserId == user.Id).OrderByDescending(k => k.id).Skip(start).Take(pageSize); foreach (WAG_Login_Page.Image img in images) { ImageJQ image = new ImageJQ(); image.Path = "iimages/" + Convert.ToString(img.FileName).ToLower(); imagesList.Add(image); } if (imagesList.Count > 0) { imagesList = imagesList.Where(i => i.Path.Contains(".jpeg") || i.Path.Contains(".jpg") || i.Path.Contains(".gif") || i.Path.Contains(".png")).ToList(); } } } catch (Exception ex) { } } return(imagesList); }
public List <Data> GetPages(string siteName) { List <Data> pageData = new List <Data>(); try { if (User.Identity.IsAuthenticated) { var entities = new WebPageEntities(); var user = entities.AspNetUsers.Where(i => i.UserName == User.Identity.Name).FirstOrDefault(); var site = entities.Sites.Where(i => i.SiteName == siteName && i.UserId == user.Id).FirstOrDefault(); if (user != null) { var pages = entities.Pages.Where(i => i.SiteId == site.Id); if (pages != null && pages.Count() > 0) { foreach (var page in pages) { string isFirstTime = page.IsFirstTime == "true" ? "?f=new" : ""; pageData.Add(new Data { Id = page.Id, Name = page.PageName, Link = page.PageName + isFirstTime, Extra = Convert.ToString(page.ParentPageId) }); } } } } } catch (Exception ex) { } return(pageData); }
public Data CreatePage(string siteName, string pageName) { if (User.Identity.IsAuthenticated) { string root = Server.MapPath(".") + "/Sites/"; var entities = new WebPageEntities(); var user = entities.AspNetUsers.Where(i => i.UserName == User.Identity.Name).FirstOrDefault(); var site = entities.Sites.Where(i => i.SiteName == siteName && i.UserId == user.Id).FirstOrDefault(); var pageE = entities.Pages.Where(i => i.SiteId == site.Id && i.PageName == pageName); if (site == null) { return(new Data { Error = "Please create [Site] first." }); } if (pageE.Count() > 0) { return(new Data { Error = "Page Name already exists.<br>Choose another Name." }); } if (user != null) { var userFolder = Path.Combine(root, user.Id); if (Directory.Exists(userFolder)) { var siteFolder = Path.Combine(userFolder, siteName); if (Directory.Exists(siteFolder)) { try { pageName += ".html"; var page = Path.Combine(siteFolder, pageName); if (!File.Exists(page)) { FileStream str = File.Create(page); var pageToCreate = new WAG_Login_Page.Page(); pageToCreate.SiteId = site.Id; pageToCreate.PageName = pageName; pageToCreate.IsFirstTime = "true"; entities.Pages.Add(pageToCreate); entities.SaveChanges(); str.Close(); str.Dispose(); return(new Data { Success = true }); } } catch (Exception ex) { return(new Data { Success = false, Error = "", ExceptionError = ex.Message }); } } } } } return(new Data { Success = false }); }
public string UploadImages() { string resultError = ""; if (User.Identity.IsAuthenticated) { if (HttpContext.Current.Request.Files.AllKeys.Any()) { try { var entities = new WebPageEntities(); var user = entities.AspNetUsers.Where(i => i.UserName == User.Identity.Name).FirstOrDefault(); Image image = new Image(); var postedFiles = HttpContext.Current.Request.Files; for (int f = 0; f < HttpContext.Current.Request.Files.Count; f++) { string fileName = ""; try { string ext = System.IO.Path.GetExtension(postedFiles[f].FileName).ToLower(); fileName = Path.GetFileName(postedFiles[f].FileName); int maxFileSize = 5000; int fileSize = postedFiles[f].ContentLength; if (fileSize > (maxFileSize * 1024)) { if (ext != ".jpg" && ext != ".png" && ext != ".gif" && ext != ".jpeg") { resultError += fileName + " is Not a valid image.<br>"; } else { resultError += fileName + " image file size is greater than 5Mb.<br>"; } continue; } if (ext != ".jpg" && ext != ".png" && ext != ".gif" && ext != ".jpeg") { resultError += fileName + " is Not a valid image.<br>"; continue; } fileName = GetRandomString(8) + fileName; int i = 0; while (File.Exists(GetUserImagesPath() + fileName)) { i++; fileName = GetRandomString(5) + GetRandomString(5) + fileName; if (i == 4) { break; } } string savePath = GetUserImagesPath() + fileName; postedFiles[f].SaveAs(savePath); image = new Image(); image.UserId = user.Id; image.FileName = fileName; image.Path = "iimages"; entities.Images.Add(image); } catch (Exception ex) { resultError += fileName + " upload failed : server error.<br>"; } } entities.SaveChanges(); } catch (Exception ex) { resultError = "Server error!.<br>Try again later."; } } } return(resultError); }