public bool RegisterEmail(string email, out string infoMessage) { NLog.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().Name).Info(Context.Request.UserHostName); try { using (OnlineVideosDataContext dc = new OnlineVideosDataContext()) { if (!dc.DatabaseExists()) { dc.CreateDatabase(); dc.SubmitChanges(); } User user = null; if (dc.User.Any(u => u.Email == email)) { user = dc.User.First(u => u.Email == email); } else { user = new User() { Email = email, IsAdmin = false, Password = RandomString(6) }; dc.User.InsertOnSubmit(user); } if (SendPasswordEmail(user)) { infoMessage = "Password was sent to your Email address."; dc.SubmitChanges(); return(true); } else { infoMessage = "Password could not be sent to your Email address."; return(false); } } } catch (Exception ex) { infoMessage = ex.Message; return(false); } }
public override string GetPassword(string username, string answer) { using (OnlineVideosDataContext dc = new OnlineVideosDataContext()) { if (!dc.DatabaseExists()) { dc.CreateDatabase(); dc.SubmitChanges(); } return((from u in dc.User where u.Email == username select u.Password).First()); } }
public override bool ValidateUser(string username, string password) { using (OnlineVideosDataContext dc = new OnlineVideosDataContext()) { if (!dc.DatabaseExists()) { dc.CreateDatabase(); dc.SubmitChanges(); } var result = dc.User.Any(u => u.Email == username && u.Password == password); return(result); } }
public override bool IsUserInRole(string username, string roleName) { if (roleName == Roles.admin.ToString()) { using (OnlineVideosDataContext dc = new OnlineVideosDataContext()) { if (!dc.DatabaseExists()) { dc.CreateDatabase(); dc.SubmitChanges(); } return(dc.User.Any(u => u.Email == username && u.IsAdmin)); } } return(false); }
protected void btnDeleteSite_Click(object sender, EventArgs e) { using (OnlineVideosDataContext dc = new OnlineVideosDataContext()) { dc.Report.DeleteAllOnSubmit(dc.Report.Where(r => r.Site_FK == this.Request.Params["site"])); dc.Site.DeleteOnSubmit(dc.Site.FirstOrDefault(s => s.Name == this.Request.Params["site"])); dc.SubmitChanges(); try { System.IO.File.Delete(Server.MapPath("~/Icons/") + this.Request.Params["site"] + ".png"); } catch { } try { System.IO.File.Delete(Server.MapPath("~/Banners/") + this.Request.Params["site"] + ".png"); } catch { } Response.Redirect(ResolveUrl("~/SiteOverview.aspx")); } }
public bool SubmitReport(string siteName, string message, ReportType type, out string infoMessage) { NLog.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().Name).Info(Context.Request.UserHostName); try { using (OnlineVideosDataContext dc = new OnlineVideosDataContext()) { // does the site exsist? if (!dc.Site.Any(s => s.Name == siteName)) { infoMessage = "Site not found!"; return(false); } Site site = dc.Site.First(s => s.Name == siteName); Report report = new Report() { Date = DateTime.Now, Message = message, Type = type, Site = site }; if (type == ReportType.Broken && site.State == SiteState.Working) { site.State = SiteState.Reported; } else if (type == ReportType.ConfirmedBroken) { site.State = SiteState.Broken; } else if (type == ReportType.RejectedBroken || type == ReportType.Fixed) { site.State = SiteState.Working; } dc.Report.InsertOnSubmit(report); dc.SubmitChanges(); SendNewReportEmail(report); infoMessage = "Report successfully submitted!"; return(true); } } catch (Exception ex) { infoMessage = ex.Message; return(false); } }
public List <Dll> GetDllsOverview() { NLog.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().Name).Info(Context.Request.UserHostName); try { using (OnlineVideosDataContext dc = new OnlineVideosDataContext()) { if (!dc.DatabaseExists()) { dc.CreateDatabase(); dc.SubmitChanges(); } var s = from a in dc.Dll select new { Name = a.Name, LastUpdated = a.LastUpdated, Owner_FK = a.Owner_FK, MD5 = a.MD5 }; return((List <Dll>)s.ToList().ToNonAnonymousList(typeof(Dll))); } } catch { return(new List <Dll>()); } }
public List <Site> GetSitesOverview() { NLog.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().Name).Info(Context.Request.UserHostName); try { using (OnlineVideosDataContext dc = new OnlineVideosDataContext()) { if (!dc.DatabaseExists()) { dc.CreateDatabase(); dc.SubmitChanges(); } var s = from a in dc.Site select new { Description = a.Description, Language = a.Language, IsAdult = a.IsAdult, LastUpdated = a.LastUpdated, Name = a.Name, State = a.State, Owner_FK = a.Owner_FK, RequiredDll = a.RequiredDll }; return((List <Site>)s.ToList().ToNonAnonymousList(typeof(Site))); } } catch { return(new List <Site>()); } }
public List <Report> GetReports(string siteName) { NLog.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().Name).Info(Context.Request.UserHostName); try { using (OnlineVideosDataContext dc = new OnlineVideosDataContext()) { if (!dc.DatabaseExists()) { dc.CreateDatabase(); dc.SubmitChanges(); } var r = from a in dc.Report where a.Site.Name == siteName select new { Date = a.Date, Type = a.Type, Message = a.Message }; return((List <Report>)r.ToList().ToNonAnonymousList(typeof(Report))); } } catch { return(new List <Report>()); } }
public string GetSiteXml(string siteName) { NLog.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().Name).Info(Context.Request.UserHostName); try { using (OnlineVideosDataContext dc = new OnlineVideosDataContext()) { if (!dc.DatabaseExists()) { dc.CreateDatabase(); dc.SubmitChanges(); } if (dc.Site.Any(s => s.Name == siteName)) { Site site = dc.Site.First(s => s.Name == siteName); return(site.XML); } } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.ToString()); } return(""); }
protected void reports_RowCommand(object sender, GridViewCommandEventArgs e) { var row = (GridViewRow)((Control)e.CommandSource).Parent.Parent; string sitename = Request.Params["site"]; if (e.CommandName == "DeleteReport") { ReportType type = (ReportType)Enum.Parse(typeof(ReportType), (row.Cells[0].Controls[1] as Label).Text); DateTime date = DateTime.ParseExact((row.Cells[1].Controls[1] as Label).Text, "g", System.Threading.Thread.CurrentThread.CurrentCulture); string message = HttpUtility.HtmlDecode((row.Cells[2].Controls[1] as Label).Text); using (OnlineVideosDataContext dc = new OnlineVideosDataContext()) { var rep = dc.Report.FirstOrDefault(r => r.Message == message && (r.Date - date).Minutes <= 1 && r.Type == type && r.Site_FK == sitename); if (rep != null) { dc.Report.DeleteOnSubmit(rep); dc.SubmitChanges(); // now get last report for this site and check with last update to set the new site state Site site = dc.Site.First(s => s.Name == sitename); var latestReport = dc.Report.Where(r => r.Site_FK == sitename).OrderByDescending(r => r.Date).FirstOrDefault(); if (latestReport == null) { site.State = SiteState.Working; } else { if (site.LastUpdated > latestReport.Date) { site.State = SiteState.Working; } else { if (latestReport.Type == ReportType.Broken && site.State == SiteState.Working) { site.State = SiteState.Reported; } else if (latestReport.Type == ReportType.ConfirmedBroken) { site.State = SiteState.Broken; } else if (latestReport.Type == ReportType.RejectedBroken || latestReport.Type == ReportType.Fixed || latestReport.Type == ReportType.Suggestion) { site.State = SiteState.Working; } } } dc.SubmitChanges(); BindGrid(); } } } else if (e.CommandName == "AddReport") { ReportType type = (ReportType)Enum.Parse(typeof(ReportType), (row.FindControl("ddType") as DropDownList).SelectedValue); string message = (row.FindControl("tbxNewMessage") as TextBox).Text; if (!string.IsNullOrEmpty(message)) { using (OnlineVideosDataContext dc = new OnlineVideosDataContext()) { Report report = new Report() { Date = DateTime.Now, Message = message, Type = type, Site_FK = sitename }; dc.Report.InsertOnSubmit(report); // set new site state Site site = dc.Site.First(s => s.Name == sitename); switch (type) { case ReportType.Broken: if (site.State == SiteState.Working) { site.State = SiteState.Reported; } break; case ReportType.ConfirmedBroken: site.State = SiteState.Broken; break; case ReportType.RejectedBroken: case ReportType.Fixed: site.State = SiteState.Working; break; } dc.SubmitChanges(); BindGrid(); } } } }
public bool SubmitSite(string email, string password, string siteXml, byte[] icon, byte[] banner, string requiredDll, out string infoMessage) { DateTime updateTime = DateTime.Now.ToUniversalTime(); // use universal Time when setting the current TimeStamp to the Database NLog.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().Name).Info(Context.Request.UserHostName); // is the given site xml at least valid xml? XmlDocument xml = new XmlDocument(); string siteName = ""; string lang = ""; string desc = ""; bool isAdult = false; try { xml.LoadXml(siteXml); if (xml.SelectNodes("//Site").Count != 1) { infoMessage = "Exactly one <Site> node expected!"; return(false); } siteName = xml.SelectSingleNode("//Site/@name").Value; lang = xml.SelectSingleNode("//Site/@lang").Value; desc = xml.SelectSingleNode("//Site/Description").InnerText; XmlNode n = xml.SelectSingleNode("//Site/@agecheck"); if (n != null) { isAdult = bool.Parse(n.Value); } // write the current server time into the xml as lastUpdated, so comparing it later with the DB field will always work on any client // (the submitting client might have wrong time settings) XmlNode lastUpdatedNode = xml.SelectSingleNode("//Site/@lastUpdated"); if (lastUpdatedNode == null) { lastUpdatedNode = (xml.SelectSingleNode("//Site") as XmlElement).Attributes.Append(xml.CreateAttribute("lastUpdated")); } (lastUpdatedNode as XmlAttribute).Value = updateTime.ToString("o"); } catch { infoMessage = "Invalid xml for site!"; return(false); } try { using (OnlineVideosDataContext dc = new OnlineVideosDataContext()) { if (!dc.DatabaseExists()) { dc.CreateDatabase(); dc.SubmitChanges(); } // does the user exist? if (!dc.User.Any(u => u.Email == email)) { infoMessage = "Email not registered!"; return(false); } User user = dc.User.First(u => u.Email == email); // is the correct password given? if (user.Password != password) { infoMessage = "Wrong password!"; return(false); } // is the requiredDll available on the server? if (!string.IsNullOrEmpty(requiredDll)) { if (!dc.Dll.Any(d => d.Name == requiredDll)) { infoMessage = "Required Dll not found on Server!"; return(false); } } // does the site already exist? if (dc.Site.Any(s => s.Name == siteName)) { // need to update Site site = dc.Site.First(s => s.Name == siteName); if (site.Owner.Email == user.Email || user.IsAdmin) { site.Language = lang; site.Description = desc; site.IsAdult = isAdult; site.LastUpdated = updateTime; if (site.XML != siteXml) { site.XML = siteXml; } if (site.RequiredDll != requiredDll) { site.RequiredDll = requiredDll; } site.State = SiteState.Working; dc.SubmitChanges(); infoMessage = "Site successfully updated!"; infoMessage += SaveImages(siteName, icon, banner); return(true); } else { infoMessage = "Only the owner or an admin can update existing sites!"; return(false); } } else { // insert new site Site site = new Site() { Name = siteName, Language = lang, Description = desc, IsAdult = isAdult, LastUpdated = updateTime, XML = siteXml, RequiredDll = requiredDll, Owner = user, State = SiteState.Working }; dc.Site.InsertOnSubmit(site); dc.SubmitChanges(); infoMessage = "Site successfully added!"; infoMessage += SaveImages(siteName, icon, banner); return(true); } } } catch (Exception ex) { infoMessage = ex.Message; return(false); } }
public bool SubmitDll(string email, string password, string name, byte[] data, out string infoMessage) { NLog.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().Name).Info(Context.Request.UserHostName); try { using (OnlineVideosDataContext dc = new OnlineVideosDataContext()) { if (!dc.DatabaseExists()) { dc.CreateDatabase(); dc.SubmitChanges(); } // does the user exist? if (!dc.User.Any(u => u.Email == email)) { infoMessage = "Email not registered!"; return(false); } User user = dc.User.First(u => u.Email == email); // is the correct password given? if (user.Password != password) { infoMessage = "Wrong password!"; return(false); } // write the file and calc its MD5 hash System.IO.File.WriteAllBytes(Server.MapPath("~/Dlls/") + name + ".dll", data); string md5String = GetMD5Hash(data); // does the dll already exist? if (dc.Dll.Any(d => d.Name == name)) { // need to update Dll dll = dc.Dll.First(d => d.Name == name); if (dll.Owner.Email == user.Email || user.IsAdmin) { dll.MD5 = md5String; dll.LastUpdated = DateTime.Now; dc.SubmitChanges(); infoMessage = "Dll successfully updated!"; return(true); } else { infoMessage = "Only the owner or an admin can update existing dlls!"; return(false); } } else { // insert new dll Dll newDll = new Dll() { MD5 = md5String, LastUpdated = DateTime.Now, Name = name, Owner = user }; dc.Dll.InsertOnSubmit(newDll); dc.SubmitChanges(); infoMessage = "Dll successfully added!"; return(true); } } } catch (Exception ex) { infoMessage = ex.Message; return(false); } }