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); }
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 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(""); }
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); } }