Esempio n. 1
0
        public async Task <PinSettingsListModel> ProcessRequestAsync(RequestorModel data)
        {
            if (data is null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            await _opcoVerifier.CheckIfOpCoHasPinServiceAsync(data.OpCoId);

            var config = _rulesConfiguratonStore.OpCoConfigurations[data.OpCoId];

            if (config is null)
            {
                throw new InvalidOperationException("No config details for requested opco");
            }

            var individual = new Dictionary <string, PinDetailsModel>();

            foreach (var item in config.PinTypes)
            {
                data.PinType = item.Value.Id;
                var pin = await _pinRepository.TryGetPinDetailsAsync(data);

                if (pin == null)
                {
                    continue;
                }
                var individualItem = new PinDetailsModel(item.Value, pin.PinSalt, pin.PinHash, pin.PinLocked);
                individual.Add(individualItem.Id.ToString(), individualItem);
            }

            return(await Task.FromResult(new PinSettingsListModel(individual)));
        }
Esempio n. 2
0
        public async Task <PinModel> TryGetPinDetailsAsync(RequestorModel requestor)
        {
            PinModel model = default;
            var      key   = _cacheKeyGenerator.GenerateKeyForPin(requestor.OpCoId, requestor.HouseholdId, requestor.ProfileId, requestor.PinType);

            var cache = _redisClient.Db0.Database.StringGet(key);

            if (cache.HasValue)
            {
                model = DeSerializePinModel(cache.ToString());
            }
            else
            {
                var loaded = await _dbContext.Pins.SingleOrDefaultAsync(x => x.OpcoId == requestor.OpCoId && x.HouseholdId == requestor.HouseholdId && x.ProfileId == requestor.ProfileId && x.PinType == requestor.PinType);

                if (loaded != null)
                {
                    model = new PinModel()
                    {
                        PinHash             = loaded.PinHash,
                        PinLocked           = loaded.PinLocked,
                        LockReason          = loaded.LockReason,
                        PinSalt             = loaded.PinSalt,
                        FailedAttemptsCount = 0,
                        LastFailedAttempt   = DateTime.MinValue
                    };
                    _redisClient.Db0.Database.StringSet(key, SerializePinModel(model));
                }
            }
            return(model);
        }
Esempio n. 3
0
        public async Task <PinModel> VerifyPinHashAsync(Domain.Processors.VerifyPinParameters data)
        {
            if (data is null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            if (data.Requestor is null)
            {
                throw new ArgumentNullException(nameof(data.Requestor));
            }
            _requestor = data.Requestor;

            await LoadPinModelAsync(data.Requestor);

            CheckIsPinLocked();
            CheckIsInGracePeriod();

            if ((data.PinHash.Length != _storedPinModel.PinHash.Length) || !data.PinHash.Equals(_storedPinModel.PinHash))
            {
                await UpdateFailedAttemptsInfoAsync();

                LogFailedVerification();
                throw new Exceptions.PinInvalidException(_storedPinModel.FailedAttemptsCount, GetGracePeriodForFailedCount(_storedPinModel.FailedAttemptsCount));
            }

            await RemoveFailedAttemptsInfoAsync();

            LogSuccessfulVerification();
            return(_storedPinModel);
        }
Esempio n. 4
0
        public void SaveRequestor(RequestorModel model)
        {
            var requestor = MapModelToEntity(model);

            _db.Requestors.Add(requestor);
            _db.SaveChangesAsync(); // ?
        }
Esempio n. 5
0
        private async Task LoadPinModelAsync(RequestorModel requestor)
        {
            _storedPinModel = await _pinDataStore.TryGetPinDetailsAsync(requestor);

            if (_storedPinModel is null)
            {
                throw new Exceptions.PinDoesntExistException();
            }
        }
Esempio n. 6
0
        public IHttpActionResult PostRequestor(RequestorModel requestor)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = new RequestorService();

            service.SaveRequestor(requestor);

            return(Ok());
        }
        public async Task ProcessRequestAsync(RequestorModel requestor, bool lockpin = true, string reason = null)
        {
            await _opcoVerifier.CheckIfOpCoHasPinServiceAsync(requestor.OpCoId);

            var pinModel = await _pinRepository.TryGetPinDetailsAsync(requestor);

            if (pinModel is null)
            {
                throw new PinPlatform.Domain.Exceptions.PinDoesntExistException();
            }

            pinModel.PinLocked  = lockpin;
            pinModel.LockReason = lockpin ? reason : String.Empty;

            await _pinRepository.CreateOrUpdatePinAsync(requestor, pinModel);
        }
Esempio n. 8
0
        public Requestor MapModelToEntity(RequestorModel model)
        {
            var requestor = new Requestor
            {
                Id                 = model.Id,
                RequestorName      = model.RequestorName,
                PatientName        = model.PatientName,
                CollectionCentreId = model.CollectionCentreId,
                ContactNumber      = model.ContactNumber,
                Quantity           = model.Quantity,
                BloodGroup         = model.BloodGroup,
                ExpectedDate       = model.ExpectedDate,
                DeliveredDate      = model.DeliveredDate,
                IsActive           = model.IsActive
            };

            return(requestor);
        }
Esempio n. 9
0
        public async Task DeletePinAsync(RequestorModel requestor)
        {
            if (!requestor.PinType.HasValue)
            {
                requestor.PinType = 0;
            }
            var key = _cacheKeyGenerator.GenerateKeyForPin(requestor.OpCoId, requestor.HouseholdId, requestor.ProfileId, requestor.PinType);
            await _redisClient.Db0.RemoveAsync(key);

            var dbitem = new Pins()
            {
                OpcoId      = requestor.OpCoId,
                HouseholdId = requestor.HouseholdId,
                ProfileId   = requestor.ProfileId,
                PinType     = requestor.PinType.Value
            };

            _dbContext.Remove(dbitem);
            await _dbContext.SaveChangesAsync();
        }
Esempio n. 10
0
        public async Task ProcessRequestAsync(RequestorModel requestor, string newPin)
        {
            await _opcoVerifier.CheckIfOpCoHasPinServiceAsync(requestor.OpCoId);

            var model = new PinChangeVerificationModel()
            {
                OpCoId  = requestor.OpCoId,
                PinType = requestor.PinType,
                NewPin  = newPin
            };
            await _pinChangeVerifier.CheckNewPinAgainstRulesAsync(model);

            var newpin   = _pinHashGenerator.GeneratePinHashWithNewSalt(newPin);
            var pinmodel = new PinModel()
            {
                PinLocked = false,
                PinHash   = newpin.Hash,
                PinSalt   = newpin.Salt
            };

            await _pinRepository.CreateOrUpdatePinAsync(requestor, pinmodel);
        }
Esempio n. 11
0
        public async Task CreateOrUpdatePinAsync(RequestorModel requestor, PinModel pin)
        {
            var isNew = false;

            if (!requestor.PinType.HasValue)
            {
                requestor.PinType = 0;
            }
            var found = await _dbContext.Pins.SingleOrDefaultAsync(x => x.HouseholdId == requestor.HouseholdId && x.ProfileId == x.ProfileId && x.PinType == requestor.PinType);

            if (found is null)
            {
                found = new Pins()
                {
                    OpcoId      = requestor.OpCoId,
                    HouseholdId = requestor.HouseholdId,
                    ProfileId   = requestor.ProfileId,
                    PinType     = requestor.PinType.Value
                };
                isNew = true;
            }
            found.PinHash    = pin.PinHash;
            found.PinLocked  = pin.PinLocked;
            found.PinSalt    = pin.PinSalt;
            found.LockReason = pin.LockReason;

            if (isNew)
            {
                await _dbContext.Pins.AddAsync(found);
            }

            await _dbContext.SaveChangesAsync();

            var key = _cacheKeyGenerator.GenerateKeyForPin(requestor.OpCoId, requestor.HouseholdId, requestor.ProfileId, requestor.PinType);

            _redisClient.Db0.Database.StringSet(key, SerializePinModel(pin));
        }
        public async Task ProcessRequestAsync(RequestorModel requestor)
        {
            await _opcoVerifier.CheckIfOpCoHasPinServiceAsync(requestor.OpCoId);

            await _pinRepository.DeletePinAsync(requestor);
        }
Esempio n. 13
0
 public async Task UpdatePinFailureInfoAsync(RequestorModel requestor, PinModel pin)
 {
     var key = _cacheKeyGenerator.GenerateKeyForPin(requestor.OpCoId, requestor.HouseholdId, requestor.ProfileId, requestor.PinType);
     await _redisClient.Db0.Database.StringSetAsync(key, SerializePinModel(pin));
 }
Esempio n. 14
0
        private List <FieldSearchModel> collectSearchTerms()
        {
            List <FieldSearchModel> list  = new List <FieldSearchModel>();
            FieldSearchModel        model = new FieldSearchModel();

            foreach (Control ctl in this.Controls)
            {
                string   ctlname  = ctl.Name;
                string[] tagArray = null;
                if (ctl.Tag != null)
                {
                    tagArray = ctl.Tag.ToString().Split('|');
                }
                if (ctl.Text != "")
                {
                    switch (ctl?.GetType().Name)
                    {
                    case "DateTimePicker":
                        DateTimePicker   dtp = ctl as DateTimePicker;
                        FieldSearchModel fsm = new FieldSearchModel();
                        if (dtp.Format != DateTimePickerFormat.Custom)
                        {
                            fsm.FieldName  = tagArray[1];
                            fsm.FieldValue = dtp.Text;
                            list.Add(fsm);
                        }

                        break;

                    case "TextBox":
                    case "RichTextBox":
                        fsm            = new FieldSearchModel();
                        fsm.FieldName  = tagArray[1];
                        fsm.FieldValue = ctl.Text;
                        list.Add(fsm);

                        break;

                    case "ListBox":
                        switch (ctl.Name)
                        {
                        case "lstFE":
                            ListBox listBox = ctl as ListBox;
                            foreach (FE_Model fe in listBox.SelectedItems)
                            {
                                fsm = new FieldSearchModel();
                                FE_Model fE_Model = fe as FE_Model;
                                fsm.FieldName  = "FE_ListXML";
                                fsm.FieldValue = fE_Model.ID.ToString();
                                list.Add(fsm);
                            }
                            break;

                        case "lstTopics":
                            //    ListBox listBoxTopics = ctl as ListBox;
                            //    foreach (ProductModel prod in listBoxTopics.SelectedItems)
                            //    {
                            //        fsm = new FieldSearchModel();
                            //        ProductModel productModel = prod as ProductModel;
                            //        fsm.FieldName = "ProductListXML";
                            //        fsm.FieldValue = prod.ID.ToString();
                            //        list.Add(fsm);


                            break;

                        default:
                            break;
                        }
                        break;

                    case "ComboBox":
                        switch (ctl.Name)
                        {
                        case "cboMSO":
                        {
                            MSO_Model mso    = cboMSO.SelectedItem as MSO_Model;
                            int       mso_ID = mso.ID;
                            fsm            = new FieldSearchModel();
                            fsm.FieldName  = "MSO_ID";
                            fsm.FieldValue = mso_ID.ToString();
                            list.Add(fsm);
                        }
                        break;

                        case "cboActivity":
                        {
                            ActivityModel activity    = cboActivity.SelectedItem as ActivityModel;
                            int           activity_ID = activity.ID;
                            fsm            = new FieldSearchModel();
                            fsm.FieldName  = "Activity_ID";
                            fsm.FieldValue = activity_ID.ToString();
                            list.Add(fsm);
                        }
                        break;

                        case "cboRequestor":
                        {
                            RequestorModel requestor    = cboRequestor.SelectedItem as RequestorModel;
                            int            requestor_ID = requestor.ID;
                            fsm            = new FieldSearchModel();
                            fsm.FieldName  = "Requestor";
                            fsm.FieldValue = requestor_ID.ToString();
                            list.Add(fsm);
                        }
                        break;

                        default:
                            break;
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            return(list);
        }