Exemple #1
0
        public void Md5HashEncode_method_should_be_correct()
        {
            // Arrange
            var string1 = "THis is a string";
            var string2 = "This is a string";
            var string3 = "d6991/d5506f*d(d}d1]3489&f949$09@c24!d6c3";
            var string4 = "d6991/d5506f*d(d}d1]3489&f949$09@c24!d6c3";
            var string5 = "d6991/d5506f*d(d}d1]3489&f949$09@c24!D6c3";

            // Act
            var hash1 = StringUtility.Md5HashEncode(string1);
            var hash2 = StringUtility.Md5HashEncode(string2);
            var hash3 = StringUtility.Md5HashEncode(string3);
            var hash4 = StringUtility.Md5HashEncode(string4);
            var hash5 = StringUtility.Md5HashEncode(string5);

            // Assert
            Assert.AreNotEqual(hash1, hash2);
            Assert.AreEqual(hash3, hash4);
            Assert.AreNotEqual(hash4, hash5);
            Assert.AreEqual("a7655a40b64eddc4eceedd8f84a90fd0", hash1);
            Assert.AreEqual("41fb5b5ae4d57c5ee528adb00e5e8e74", hash2);
            Assert.AreEqual("6125427b4aaf41e9c2976acb7f81532c", hash3);
            Assert.AreEqual("6125427b4aaf41e9c2976acb7f81532c", hash4);
            Assert.AreEqual("0003d81d8a8e30b07bcf6580e36a9a84", hash5);
        }
Exemple #2
0
        public void VerifyMd5Hash_method_work()
        {
            // Arrange
            var input1 = "THis is a string";
            var input2 = "This is a string";
            var input3 = "d6991/d5506f*d(d}d1]3489&f949$09@c24!d6c3";
            var input4 = "d6991/d5506f*d(d}d1]3489&f949$09@c24!d6c3";
            var input5 = "d6991/d5506f*d(d}d1]3489&f949$09@c24!D6c3";

            // Act
            var hash1 = StringUtility.Md5HashEncode(input1);
            var hash2 = StringUtility.Md5HashEncode(input2);
            var hash3 = StringUtility.Md5HashEncode(input3);
            var hash4 = StringUtility.Md5HashEncode(input4);
            var hash5 = StringUtility.Md5HashEncode(input5);

            // Assert
            Assert.IsTrue(StringUtility.VerifyMd5Hash(input1, hash1));
            Assert.IsTrue(StringUtility.VerifyMd5Hash(input2, hash2));
            Assert.IsTrue(StringUtility.VerifyMd5Hash(input3, hash3));
            Assert.IsTrue(StringUtility.VerifyMd5Hash(input4, hash4));
            Assert.IsTrue(StringUtility.VerifyMd5Hash(input5, hash5));
        }
Exemple #3
0
        public bool HasAlreadyParticipated(string email)
        {
            var emailHash = StringUtility.Md5HashEncode(email.ToLower());

            return(_participationRepository.GetByEmailHash(emailHash) != null);
        }
        public async Task <IHttpActionResult> Participate([FromBody] ParticipationViewModel participate)
        {
            dynamic expando = new ExpandoObject();

            var apiResponse = new ApiResponse
            {
                Success = false,
                Message = "Bad Request",
                Data    = expando
            };

            try
            {
                if (participate == null)
                {
                    expando.Error = new List <string>()
                    {
                        "Body request data should be as documented"
                    };

                    apiResponse.Message = "Missing or unknown request body";
                    apiResponse.Data    = expando;

                    _logger.LogWarn("Participate validation Error", "Body request not found or unknown");
                    return(Content(HttpStatusCode.BadRequest, apiResponse));
                }

                if (!ModelState.IsValid)
                {
                    var allErrors = ModelState.Values.SelectMany(v => v.Errors);
                    var errorList = allErrors.Select(error => error.ErrorMessage);
                    expando.Error = errorList;

                    apiResponse.Message = "Validation error occured";
                    apiResponse.Data    = expando;

                    _logger.LogWarn("Participate validation Error", string.Join(", ", errorList));

                    return(Content(HttpStatusCode.BadRequest, apiResponse));
                }

                var dto = new ParticipationDto
                {
                    Id              = Guid.NewGuid(),
                    EmailHash       = StringUtility.Md5HashEncode(participate.Email.ToLower()),
                    Email           = participate.Email,
                    SiteId          = _siteService.GetSiteByCulture(participate.Culture)?.Id,
                    RetailerConsent = participate.RetailerConsent,
                    NewsletterOptin = participate.NewsletterOptin
                };

                var crmResponse = await _journeyService.ParticipateAsync(dto, participate.Culture);

                var site = _siteService.GetSiteByCulture(participate.Culture);

                expando.Description     = "Your participate has been taken into account.";
                expando.ConsumerId      = crmResponse.Item1 ? crmResponse.Item2 : string.Empty;
                expando.ParticipationId = dto.Id;

                apiResponse.Success = true;
                apiResponse.Message = crmResponse.Item1 ? "Participate successfull" :
                                      "Your participate has been considered but CRM sync has failed";
                apiResponse.Data = expando;

                _logger.LogTrace(apiResponse.Message, $"Ok: {dto.Id}");

                return(Ok(apiResponse));
            }
            catch (Exception e)
            {
                expando.Error = e.Message;

                apiResponse.Success = false;
                apiResponse.Message = $"Error occured in {e.Source}";
                apiResponse.Data    = expando;

                _logger.LogError(e.Message, e);

                return(Content(HttpStatusCode.InternalServerError, apiResponse));
            }
        }