コード例 #1
0
        public void NewContact(HourlyTracerKey key, DateHour time)
        {
            Case matchingCase = null;

            // Adds the new case to the database.

            db.RunInTransaction(() => {
                var exists = db.Find <Contact>(c =>
                                               c.Key == key.Value &&
                                               c.Year == time.Year &&
                                               c.Month == time.Month &&
                                               c.Day == time.Day &&
                                               c.Hour == time.Hour
                                               ) != null;

                if (!exists)
                {
                    Logger.Info(
                        $"New contact: {key.ToHumanReadableString()} at {time}."
                        );

                    db.Insert(new Contact {
                        Key   = key.Value,
                        Year  = time.Year,
                        Month = time.Month,
                        Day   = time.Day,
                        Hour  = time.Hour
                    });

                    // Gets any matching know case

                    matchingCase = db.Find <Case>(ca =>
                                                  ca.Key == key.Value &&
                                                  ca.Year == time.Year &&
                                                  ca.Month == time.Month &&
                                                  ca.Day == time.Day
                                                  );
                }
            });

            // Classifies the newly added case

            if (matchingCase != null)
            {
                lock (Matches) {
                    if (matchingCase.Type == "positive")
                    {
                        Matches.Positives.Add(time);
                    }
                    else
                    {
                        Matches.Symptomatics.Add(time);
                    }
                }

                MatchesChange?.Invoke(this, Matches);
                CurrentInfectionStatusChange?.Invoke(
                    this, CurrentInfectionStatus);
            }
        }
コード例 #2
0
        public void AddUserRegister(User user, Profile profile, List <UserNotes> userNotes)
        {
            //verificar se já existe o usuário
            var userBD = _userAppService.GetUserByEmail(user.Email);

            if (userBD != null)
            {
                throw new Exception("Usuário existente.");
            }

            user.Password = Encryptor.GenerateHashMd5(user.Password);

            user.CreateDate = DateHour.GetDateTimeServer();
            _userAppService.Insert(user);

            profile.IdUser = user.IdUser;

            _profileAppService.Insert(profile);

            userNotes.All(c => { c.IdUser = user.IdUser; return(true); });
            userNotes.All(c => { c.Note = Encryptor.Encrypt(c.Note); return(true); });

            foreach (var note in userNotes)
            {
                _userNoteAppService.Insert(note);
            }
        }
コード例 #3
0
        public void ResetPassword(string hash, string newPassword)
        {
            //caso já tiver solicitado o password não gera novamente
            var userPasswordRecovery = GetUserPasswordRecoveryByHash(hash);

            if (userPasswordRecovery == null)
            {
                throw new Exception("Not Hash");
            }

            var userBD = _userAppService.GetUserByEmail(userPasswordRecovery.Email);

            if (userBD == null)
            {
                throw new Exception("User not find");
            }

            DateTime dateHour = DateHour.GetDateTimeServer();

            Update(new UserPasswordRecovery {
                UpdateDate = dateHour, Hash = hash
            });

            userBD.Password   = Encryptor.GenerateHashMd5(newPassword);
            userBD.UpdateDate = dateHour;

            _userAppService.Update(userBD);
        }
コード例 #4
0
        public HourlyTracerKey DerivateHourlyKey(DateHour date)
        {
            using (var hmac = new HMACSHA256(Value)) {
                var dateBytes = ASCIIEncoding.ASCII.GetBytes(date.ToString());
                var hash      = hmac.ComputeHash(dateBytes);

                // Truncates hourly key to fit in a BLE packet.
                var truncatedHash = new byte[HourlyTracerKey.Length];
                Array.Copy(hash, truncatedHash, HourlyTracerKey.Length);

                return(new HourlyTracerKey(truncatedHash));
            }
        }
コード例 #5
0
        public string UserGenerateHash(string email)
        {
            //caso já tiver solicitado o password não gera novamente
            var userPasswordRecovery = GetUserPasswordRecoveryByEmail(email);

            if (userPasswordRecovery != null)
            {
                return(userPasswordRecovery.Hash);
            }

            string hash = Guid.NewGuid().ToString().Replace("-", "");

            Insert(new UserPasswordRecovery {
                Email = email, CreateDate = DateHour.GetDateTimeServer(), Hash = hash
            });

            return(hash);
        }
コード例 #6
0
        /** Recomputes the match sets based on the current state of the contact
         * database. */
        protected void ComputeMatches()
        {
            var sqlMatches = db.Query <SQLiteMatch>(
                "select ca.type, co.year, co.month, co.day, co.hour " +
                "from contacts as co " +
                "inner join cases as ca " +
                "   on ca.key = co.key " +
                "   and ca.year = co.year " +
                "   and ca.month = co.month " +
                "   and ca.day = co.day " +
                "group by ca.type, co.year, co.month, co.day, co.hour;"
                );

            lock (Matches) {
                Matches.Positives.Clear();
                Matches.Symptomatics.Clear();

                foreach (var sqlMatch in sqlMatches)
                {
                    var time = new DateHour(sqlMatch.Year, sqlMatch.Month,
                                            sqlMatch.Day, sqlMatch.Hour);

                    if (sqlMatch.Type == "positive")
                    {
                        Matches.Positives.Add(time);
                    }
                    else
                    {
                        Matches.Symptomatics.Add(time);
                    }
                }
            }

            MatchesChange?.Invoke(this, Matches);
            CurrentInfectionStatusChange?.Invoke(this, CurrentInfectionStatus);
        }
コード例 #7
0
ファイル: User.cs プロジェクト: josue-acaz/purchase-api
        // Faz a validação dos campos do usuário
        public List <string> Validate(dynamic obj)
        {
            List <string> list_erros = new List <string>();
            Fluent        fluent     = new Fluent();
            DateHour      dateHelper = new DateHour();

            if (fluent.IsNull(obj.use_id))
            {
                list_erros.Add("O campo " + this.DisplayName("use_id") + " deve ser informado.");
            }
            if (fluent.IsEmpty(obj.use_id))
            {
                list_erros.Add("O campo " + this.DisplayName("use_id") + " deve ser informado.");
            }
            if (fluent.IsNull(obj.use_entity))
            {
                list_erros.Add("O campo " + this.DisplayName("use_entity") + " deve ser informado.");
            }
            if (fluent.IsEmpty(obj.use_entity))
            {
                list_erros.Add("O campo " + this.DisplayName("use_entity") + " deve ser informado.");
            }
            if (fluent.IsNull(obj.use_name))
            {
                list_erros.Add("O campo " + this.DisplayName("use_name") + " deve ser informado.");
            }
            if (fluent.IsEmpty(obj.use_name))
            {
                list_erros.Add("O campo " + this.DisplayName("use_name") + " deve ser informado.");
            }
            if (fluent.IsNull(obj.use_code))
            {
                list_erros.Add("O campo " + this.DisplayName("use_code") + " deve ser informado.");
            }
            if (fluent.IsNull(obj.use_email))
            {
                list_erros.Add("O campo " + this.DisplayName("use_email") + " deve ser informado.");
            }
            if (fluent.IsNull(obj.use_sector))
            {
                list_erros.Add("O campo " + this.DisplayName("use_sector") + " deve ser informado.");
            }
            if (fluent.IsNull(obj.use_function))
            {
                list_erros.Add("O campo " + this.DisplayName("use_function") + " deve ser informado.");
            }
            if (fluent.IsNull(obj.use_phone))
            {
                list_erros.Add("O campo " + this.DisplayName("use_phone") + " deve ser informado.");
            }
            if (fluent.IsNull(obj.use_password))
            {
                list_erros.Add("O campo " + this.DisplayName("use_password") + " deve ser informado.");
            }
            if (fluent.IsNull(obj.use_image))
            {
                list_erros.Add("O campo " + this.DisplayName("use_image") + " deve ser informado.");
            }
            if (fluent.IsNull(obj.use_active))
            {
                list_erros.Add("O campo " + this.DisplayName("use_active") + " deve ser informado.");
            }
            if (fluent.IsEmpty(obj.use_active))
            {
                list_erros.Add("O campo " + this.DisplayName("use_active") + " deve ser informado.");
            }
            if (fluent.IsNull(obj.use_excluded))
            {
                list_erros.Add("O campo " + this.DisplayName("use_excluded") + " deve ser informado.");
            }
            if (fluent.IsEmpty(obj.use_excluded))
            {
                list_erros.Add("O campo " + this.DisplayName("use_excluded") + " deve ser informado.");
            }

            if (fluent.HasMaxLen(obj.use_name, 40) == false)
            {
                list_erros.Add("O campo " + this.DisplayName("use_name") + "  deve ter, no máximo, 40 caracteres.");
            }
            if (fluent.HasMaxLen(obj.use_code, 30) == false)
            {
                list_erros.Add("O campo " + this.DisplayName("use_code") + "  deve ter, no máximo, 30 caracteres.");
            }
            if (fluent.HasMaxLen(obj.use_email, 100) == false)
            {
                list_erros.Add("O campo " + this.DisplayName("use_email") + "  deve ter, no máximo, 100 caracteres.");
            }
            if (fluent.HasMaxLen(obj.use_sector, 50) == false)
            {
                list_erros.Add("O campo " + this.DisplayName("use_sector") + "  deve ter, no máximo, 50 caracteres.");
            }
            if (fluent.HasMaxLen(obj.use_function, 50) == false)
            {
                list_erros.Add("O campo " + this.DisplayName("use_function") + "  deve ter, no máximo, 50 caracteres.");
            }
            if (fluent.HasMaxLen(obj.use_phone, 50) == false)
            {
                list_erros.Add("O campo " + this.DisplayName("use_phone") + "  deve ter, no máximo, 50 caracteres.");
            }
            if (fluent.HasMaxLen(obj.use_password, 40) == false)
            {
                list_erros.Add("O campo " + this.DisplayName("use_password") + "  deve ter, no máximo, 40 caracteres.");
            }
            if (fluent.HasMaxLen(obj.use_image, 2147483647) == false)
            {
                list_erros.Add("O campo " + this.DisplayName("use_image") + "  deve ter, no máximo, 2147483647 caracteres.");
            }
            return(list_erros);
        }