コード例 #1
0
        internal bool Login(string username, string password)
        {
            string passwordHash = utils.HashPassword(password);

            userName         = username;
            userPasswordHash = passwordHash;
            Damocles2Entities de = new Damocles2Entities();
            User user            = de.Users.Where(u => u.Username == username && u.UserPassword == passwordHash).FirstOrDefault();

            if (user == null)
            {
                return(false);
            }

            CurrentUser.UserId = user.Id;

            //TODO: This is not functioning correctly - simply want the User's current rank.
            UserRank ur = de.UserRanks.Where(usr => usr.UserId == user.Id).FirstOrDefault();

            user.IsOnline = true;
            UserRank      = ur.Rank.RankNameEnglish;

            UserJurisdiction uj = de.UserJurisdictions.Where(usrj => usrj.UserId == user.Id).FirstOrDefault();

            if (uj != null)
            {
                if (uj.Jurisidction.Country == uj.Jurisidction.State)
                {
                    UJurisdiction = uj.Jurisidction.Country;
                }
                else
                {
                    UJurisdiction = uj.Jurisidction.State.Trim() + " in " + uj.Jurisidction.Country.Trim();
                }
            }
            else
            {
                UJurisdiction = "Unknown";
            }


            var aus = de.UsersSessions.Where(auss => auss.id == user.Id);

            foreach (UsersSession userS in aus)
            {
                CurrentUser.SessionSecondsTotal += userS.SessionSeconds;
            }

            UsersSession us = new UsersSession();

            us.LoggedOnAt = DateTime.UtcNow;
            us.id         = user.Id;
            de.UsersSessions.Add(us);

            de.SaveChanges();
            return(true);
        }
コード例 #2
0
        internal void SaveMD5Hash(string fMd5)
        {
            Damocles2Entities de = new Damocles2Entities();
            Hash h = new Hash();

            h.CreatedOn = DateTime.UtcNow;
            h.HashType  = "MD5";
            h.HashValue = fMd5;
            h.id        = GetRecordId();
            h.UpdatedOn = DateTime.UtcNow;
            de.Hashes.Add(h);
            de.SaveChanges();
        }
コード例 #3
0
        internal void SaveSha256Hash(string fSha256)
        {
            Damocles2Entities de = new Damocles2Entities();
            Hash h = new Hash();

            h.CreatedOn = DateTime.UtcNow;
            h.HashType  = "SHA256";
            h.HashValue = fSha256;
            h.id        = GetRecordId();
            h.UpdatedOn = DateTime.UtcNow;
            de.Hashes.Add(h);
            de.SaveChanges();
        }
コード例 #4
0
        internal void LogOff()
        {
            Damocles2Entities de           = new Damocles2Entities();
            string            passwordHash = utils.HashPassword(CurrentUser.UserPassword);
            User u = de.Users.Where(usr => usr.Username == CurrentUser.Username && usr.UserPassword == passwordHash).FirstOrDefault();
            // UsersSession us = de.UsersSessions.Where(uss => uss.id == u.Id && uss.loggedOffAt == null)
            // v1.OrderByDescending(rec => rec.Id).FirstOrDefault();
            UsersSession us = de.UsersSessions.Where(uss => uss.id == u.Id && uss.loggedOffAt == null).OrderByDescending(ob => ob.LoggedOnAt).FirstOrDefault();

            us.loggedOffAt    = DateTime.UtcNow;
            us.SessionSeconds = CurrentUser.ThisSessionSeconds;
            u.IsOnline        = false;
            de.SaveChanges();
        }
コード例 #5
0
        // This is a 404 or some other error - do a check for a month to see if it returns
        // This can be done within Imogen as Background House keeping
        internal void SetLinkToGoneButNotForgotten(string url)
        {
            Damocles2Entities de = new Damocles2Entities();

            string pHash = hh.GetSHA512(CurrentUser.UserPassword);
            User   usr   = de.Users.Where(u => u.Username == CurrentUser.Username && u.UserPassword == pHash).FirstOrDefault();

            EUReported eu = de.EUReporteds.Where(l => l.LinkUrl == url).FirstOrDefault();

            if (!string.IsNullOrEmpty(CurrentInternalReport.TrueLinkUrl))
            {
                eu.TrueLinkUrl = CurrentInternalReport.TrueLinkUrl;
            }
            if (!string.IsNullOrEmpty(CurrentInternalReport.TrueLinkUrlHash))
            {
                eu.TrueLinkUrlHash = CurrentInternalReport.TrueLinkUrlHash;
            }
            eu.UpdatedOn = DateTime.UtcNow;

            GoneButNotForgottenLink gb = new GoneButNotForgottenLink();

            gb.CreatedOn     = DateTime.UtcNow;
            gb.Id            = eu.id;
            gb.LastCheckedOn = DateTime.UtcNow;
            gb.LinkUrlHash   = eu.LinkUrlHash;
            gb.ReportedBy    = usr.Id;

            //TODO: This won't work - we don't know which link is GoneButNotForgotten - the redirection link or the TrueLink.
            if (!string.IsNullOrEmpty(CurrentInternalReport.TrueLinkUrlHash))
            {
                eu.TrueLinkUrlHash = CurrentInternalReport.TrueLinkUrlHash;
            }


            de.GoneButNotForgottenLinks.Add(gb);
            try
            {
                de.SaveChanges();
            }
            catch (Exception)
            {
            }


            de.Dispose();
            gb  = null;
            eu  = null;
            usr = null;
        }
コード例 #6
0
 internal bool RegisterUser(string username, string password, string email, string displayName)
 {
     try
     {
         string            passwordHash = utils.HashPassword(password);
         Damocles2Entities de           = new Damocles2Entities();
         User u = new User();
         u.CreatedOn       = DateTime.UtcNow;
         u.UpdatedOn       = DateTime.UtcNow;
         u.Username        = username;
         u.UserPassword    = passwordHash;
         u.EmailAddress    = email;
         u.UserDisplayName = displayName;
         u.IsOnline        = false; // Just registered Not logged in yet!
         de.Users.Add(u);
         de.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         //TODO: Better logging than this is required.
         return(false);
     }
 }
コード例 #7
0
        internal void SetSrcToGoneButNotForgotten(string url)
        {
            Damocles2Entities de = new Damocles2Entities();
            User usr             = GetUser(de);

            EUReported eu = de.EUReporteds.Where(l => l.SrcUrl == url).FirstOrDefault();

            eu.UpdatedOn = DateTime.UtcNow;

            GoneButNotForgottenLink gb = new GoneButNotForgottenLink();

            gb.CreatedOn     = DateTime.UtcNow;
            gb.Id            = eu.id;
            gb.LastCheckedOn = DateTime.UtcNow;
            gb.SrcUrlHash    = eu.SrcUrlHash;
            gb.ReportedBy    = usr.Id;
            de.GoneButNotForgottenLinks.Add(gb);
            de.SaveChanges();

            de.Dispose();
            gb  = null;
            eu  = null;
            usr = null;
        }
コード例 #8
0
        internal void SetSrcToCriminal(string url)
        {
            Damocles2Entities de = new Damocles2Entities();

            User usr = GetUser(de);

            EUReported eu = de.EUReporteds.Where(l => l.SrcUrl == url).FirstOrDefault();


            // Create ProcessingResult table if it does not already exist!
            var pr = de.ProcessingResults.Where(prr => prr.id == eu.id).FirstOrDefault();

            bool Update = true;

            if (pr == null)
            {
                Update = false;
                pr     = new ProcessingResult();
            }

            pr.id = eu.id;
            var uju = de.UserJurisdictions.Where(uj => uj.UserId == usr.Id).FirstOrDefault();

            pr.JurisdictionId = uju.JurisdictionID;
            pr.CreatedOn      = DateTime.UtcNow;
            pr.UpdatedOn      = DateTime.UtcNow;
            pr.UserId         = usr.Id;

            // Only add records if they have not already been created (for just now)
            //if (pr.ASrcResultId == null)
            //{
            //    A aRecord = new A();
            //    aRecord.ResultCount = aRecord.ResultCount + 1;
            //    aRecord.UpdatedOn = DateTime.UtcNow;
            //    aRecord.CreatedOn = DateTime.UtcNow;
            //    aRecord.IsAllowed = true;
            //    de.A.Add(aRecord);
            //    pr.ASrcResultId = aRecord.pid;
            //}

            //if (pr.RSrcResultId == null)
            //{
            //    R rRecord = new R();
            //    rRecord.ResultCount = rRecord.ResultCount + 1;
            //    rRecord.UpdatedOn = DateTime.UtcNow;
            //    rRecord.CreatedOn = DateTime.UtcNow;
            //    rRecord.IsRestricted = true;
            //    de.R.Add(rRecord);
            //    pr.RSrcResultId = rRecord.pid;
            //}

            if (pr.CSrcResultId == null)
            {
                C cRecord = new C();
                cRecord.ResultCount = cRecord.ResultCount + 1;
                cRecord.UpdatedOn   = DateTime.UtcNow;
                cRecord.CreatedOn   = DateTime.UtcNow;
                cRecord.IsCriminal  = true;
                de.C.Add(cRecord);
                pr.CSrcResultId = cRecord.pid;
            }

            if (!Update)
            {
                de.ProcessingResults.Add(pr);
            }

            // Check to see if the LinkUrl is GoneButNotForgotten
            var gbnf = de.GoneButNotForgottenLinks.Where(gbn => gbn.LinkUrlHash == eu.LinkUrlHash).FirstOrDefault();

            if (gbnf != null)
            {
                eu.Processed = true;
            }
            else
            {
                // this record had already been created so we may have to mark EU as processed - check now
                if (pr.ALinkResultId != null || pr.RLinkResultId != null || pr.CLinkResultId != null)
                {
                    eu.Processed = true;
                }
            }

            eu.UpdatedOn = DateTime.UtcNow;
            de.SaveChanges();

            //TODO: Implement this
            // if eu.Processed == true then raise Event to tell frmMain to go to the next unprocessed Report
        }
コード例 #9
0
        internal static void SaveIndividualsBasicInformation(string Name, string Age, string Sex, string SpokenLanguage, string WrittenLanguage, string Nationality, string Ethnicity, Image image)
        {
            Utils.Utils       utils = new Utils.Utils();
            Damocles2Entities de    = new Damocles2Entities();
            FaceARC           farc  = new FaceARC();
            Face face = new Face();

            // Possible Return Values = X, A, R, C, String.Empty
            var pr = GetProcessingResultById(CurrentInternalReport.ReportNumber);

            if (pr != null)
            {
                if (pr.CSrcResultId != null)    // Theoretically the most common result
                {
                    farc.CId = pr.CSrcResultId;
                }

                if (pr.RSrcResultId != null)
                {
                    farc.RId = pr.RSrcResultId;
                }

                if (pr.ASrcResultId != null) // Theoretically the least common result
                {
                    farc.AId = pr.ASrcResultId;
                }

                farc.FaceId    = face.id;
                face.FaceData  = utils.BytesToString(utils.imageToByteArray(image));
                face.CreatedOn = DateTime.UtcNow;
                face.UpdatedOn = DateTime.UtcNow;
                face.CreatedBy = CurrentUser.UserId;
                if (!string.IsNullOrEmpty(Name))
                {
                    face.Name = Name;
                }
                if (!string.IsNullOrEmpty(Age))
                {
                    face.Age = Convert.ToInt32(Age);
                }
                if (!string.IsNullOrEmpty(Sex))
                {
                    face.Sex = Sex;
                }
                if (!string.IsNullOrEmpty(SpokenLanguage))
                {
                    face.SpokenLanguage = SpokenLanguage;
                }
                if (!string.IsNullOrEmpty(WrittenLanguage))
                {
                    face.WrittenLanguage = WrittenLanguage;
                }
                if (!string.IsNullOrEmpty(Nationality))
                {
                    face.Nationality = Nationality;
                }
                if (!string.IsNullOrEmpty(Ethnicity))
                {
                    face.Ethnicity = Ethnicity;
                }

                de.Faces.Add(face);
                de.FaceARCs.Add(farc);
                de.SaveChanges();
            }
            else
            {
                // Need to save the Profile results before trying to get them from ProcessingResults.
            }
        }
コード例 #10
0
        internal static void SaveCurrentReport()
        {
            bool update          = false;
            Damocles2Entities de = new Damocles2Entities(); //TODO: Maybe this should be a Static?
            CurrentReport     ce = de.CurrentReports.Where(cr => cr.ReportNumber == Reporting.CurrentInternalReport.ReportNumber).FirstOrDefault();

            if (ce == null) // Generate New Report
            {
                ce = new CurrentReport();
                ce.ReportStartedOn = DateTime.UtcNow;
            }
            else
            {
                update       = true;
                ce.UpdatedOn = DateTime.UtcNow;
            }

            if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.ImagePath))
            {
                ce.ImagePath = Reporting.CurrentInternalReport.ImagePath;
            }
            if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.LinkUrl))
            {
                ce.LinkUrl = Reporting.CurrentInternalReport.LinkUrl;
            }
            ce.LinkUrlARCXRating = (int)Reporting.CurrentInternalReport.LinkUrlARCXRating;
            if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.LinkUrlFilename))
            {
                ce.LinkUrlFilename = Reporting.CurrentInternalReport.LinkUrlFilename;
            }
            if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.LinkUrl))
            {
                ce.LinkUrl = Reporting.CurrentInternalReport.LinkUrl;
            }
            ce.LinkUrlARCXRating = (int)Reporting.CurrentInternalReport.LinkUrlARCXRating;
            if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.LinkUrlFilename))
            {
                ce.LinkUrlFilename = Reporting.CurrentInternalReport.LinkUrlFilename;
            }
            if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.LinkUrlHash))
            {
                ce.LinkUrlHash = Reporting.CurrentInternalReport.LinkUrlHash;
            }
            if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.PageUrl))
            {
                ce.PageUrl = Reporting.CurrentInternalReport.PageUrl;
            }
            if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.PageUrlFilename))
            {
                ce.PageUrlFilename = Reporting.CurrentInternalReport.PageUrlFilename;
            }
            if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.PageUrlHash))
            {
                ce.PageUrlHash = Reporting.CurrentInternalReport.PageUrlHash;
            }
            ce.ProcessingBy = Reporting.CurrentUser.UserId;
            ce.ReportedBy   = Reporting.CurrentInternalReport.ReportedBy;
            ce.ReportedOn   = Reporting.CurrentInternalReport.ReportedOn;
            if (Reporting.CurrentInternalReport.Completed)
            {
                ce.ReportEndedOn = DateTime.UtcNow;
            }
            ce.ReportNumber      = Reporting.CurrentInternalReport.ReportNumber;
            ce.ReportProcessed   = Reporting.CurrentInternalReport.Completed;
            ce.ReportSessionTime = Reporting.CurrentInternalReport.ReportSessionTime;
            if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.SrcUrl))
            {
                ce.SrcUrl = Reporting.CurrentInternalReport.SrcUrl;
            }
            ce.SrcUrlARCXRating = (int)Reporting.CurrentInternalReport.SrcUrlARCXRating;
            if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.SrcUrlFilename))
            {
                ce.SrcUrlFilename = Reporting.CurrentInternalReport.SrcUrlFilename;
            }
            if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.SrcUrlHash))
            {
                ce.SrcUrlHash = Reporting.CurrentInternalReport.SrcUrlHash;
            }
            if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.TrueLinkUrl))
            {
                ce.TrueLinkUrl = Reporting.CurrentInternalReport.TrueLinkUrl;
            }
            if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.TrueLinkUrlFilename))
            {
                ce.TrueLinkUrlFilename = Reporting.CurrentInternalReport.TrueLinkUrlFilename;
            }
            if (!string.IsNullOrEmpty(Reporting.CurrentInternalReport.TrueLinkUrlHash))
            {
                ce.TrueLinkUrlHash = Reporting.CurrentInternalReport.TrueLinkUrlHash;
            }

            if (!update)
            {
                de.CurrentReports.Add(ce);
            }

            de.SaveChanges(); //TODO: Probably should be using Asynchronous calls for all these
        }