Ejemplo n.º 1
0
        public async Task <IActionResult> EmailValidation([FromHeader(Name = "Grid-Authorization-Token")] string token, [FromRoute] string emailid)
        {
            try
            {
                if (string.IsNullOrEmpty(token))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        IsDomainValidationErrors = true,
                        Message = EnumExtensions.GetDescription(CommonErrors.TokenEmpty)
                    }));
                }
                AdminUsersDataAccess _adminUsersDataAccess = new AdminUsersDataAccess(_iconfiguration);

                DatabaseResponse tokenAuthResponse = await _adminUsersDataAccess.AuthenticateAdminUserToken(token);

                if (tokenAuthResponse.ResponseCode == (int)DbReturnValue.AuthSuccess)
                {
                    if (!((AuthTokenResponse)tokenAuthResponse.Results).IsExpired)
                    {
                        if (!ModelState.IsValid)
                        {
                            LogInfo.Error(StatusMessages.DomainValidationError);
                            new OperationResponse
                            {
                                HasSucceeded             = false,
                                IsDomainValidationErrors = true,
                                Message = string.Join("; ", ModelState.Values
                                                      .SelectMany(x => x.Errors)
                                                      .Select(x => x.ErrorMessage))
                            };
                        }

                        DatabaseResponse configResponseEmail = ConfigHelper.GetValue("EmailValidate", _iconfiguration);

                        List <Dictionary <string, string> > _result = ((List <Dictionary <string, string> >)configResponseEmail.Results);

                        EmailValidationHelper emailhelper    = new EmailValidationHelper();
                        EmailConfig           objEmailConfig = new EmailConfig();
                        objEmailConfig.key         = _result.Single(x => x["key"] == "NeverbouceKey")["value"];
                        objEmailConfig.Email       = emailid;
                        objEmailConfig.EmailAPIUrl = _result.Single(x => x["key"] == "Emailurl")["value"];


                        string configResponse             = emailhelper.EmailValidation(objEmailConfig);
                        EmailValidationResponse _response = new EmailValidationResponse();
                        _response.Status = configResponse;
                        if (configResponse.ToLower().Trim() != "invalid")
                        {
                            _response.IsValid = true;
                            return(Ok(new ServerResponse
                            {
                                HasSucceeded = true,
                                Message = StatusMessages.ValidMessage,
                                Result = _response
                            }));
                        }
                        else
                        {
                            //Invalid email
                            _response.IsValid = false;

                            LogInfo.Error(EnumExtensions.GetDescription(CommonErrors.InvalidEmail));

                            return(Ok(new ServerResponse
                            {
                                HasSucceeded = true,
                                Message = StatusMessages.InvalidMessage,
                                Result = _response
                            }));
                        }
                    }

                    else
                    {
                        //Token expired

                        LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.ExpiredToken));

                        return(Ok(new OperationResponse
                        {
                            HasSucceeded = false,
                            Message = EnumExtensions.GetDescription(DbReturnValue.TokenExpired),
                            IsDomainValidationErrors = true
                        }));
                    }
                }
                else
                {
                    // token auth failure
                    LogInfo.Warning(EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed));

                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed),
                        IsDomainValidationErrors = false
                    }));
                }
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));
                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = StatusMessages.ServerError,
                    IsDomainValidationErrors = false
                }));
            }
        }
Ejemplo n.º 2
0
        public IActionResult EmailValidation([FromHeader(Name = "Grid-General-Token")] string Token, [FromRoute] string emailid)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    LogInfo.Error(StatusMessages.DomainValidationError);
                    new OperationResponse
                    {
                        HasSucceeded             = false,
                        IsDomainValidationErrors = true,
                        Message = string.Join("; ", ModelState.Values
                                              .SelectMany(x => x.Errors)
                                              .Select(x => x.ErrorMessage))
                    };
                }
                TokenValidationHelper tokenValidationHelper = new TokenValidationHelper();
                if (!tokenValidationHelper.ValidateGenericToken(Token, _iconfiguration))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed),
                        IsDomainValidationErrors = true
                    }));
                }
                DatabaseResponse configResponseEmail = ConfigHelper.GetValue("EmailValidate", _iconfiguration);

                List <Dictionary <string, string> > _result = ((List <Dictionary <string, string> >)configResponseEmail.Results);
                string email1 = emailid;
                if (_result.Single(x => x["key"] == "AllowPlusSignEmailAddress")["value"] == "1")
                {
                    //Remove the Plus sign part from email before sending to neverbounce
                    Regex emailregx = new Regex("(\\+)(.*?)(\\@)"); //Replace the part after the plus "+) sign
                    email1 = emailregx.Replace(emailid, "$3");      //$3 to putback the @symbol
                }

                EmailValidationHelper emailhelper    = new EmailValidationHelper();
                EmailConfig           objEmailConfig = new EmailConfig();
                objEmailConfig.key         = _result.Single(x => x["key"] == "NeverbouceKey")["value"];
                objEmailConfig.Email       = email1;
                objEmailConfig.EmailAPIUrl = _result.Single(x => x["key"] == "Emailurl")["value"];

                string configResponse             = emailhelper.EmailValidation(objEmailConfig);
                EmailValidationResponse _response = new EmailValidationResponse();
                _response.Status = configResponse;
                if (configResponse.ToLower().Trim() != "invalid")
                {
                    _response.IsValid = true;
                    return(Ok(new ServerResponse
                    {
                        HasSucceeded = true,
                        Message = StatusMessages.ValidMessage,
                        Result = _response
                    }));
                }
                else
                {
                    //Invalid email
                    _response.IsValid = false;

                    LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.InvalidEmail));

                    return(Ok(new ServerResponse
                    {
                        HasSucceeded = true,
                        Message = StatusMessages.InvalidMessage,
                        Result = _response
                    }));
                }
            }
            catch (Exception ex)
            {
                EmailValidationResponse _response = new EmailValidationResponse();
                _response.Status  = "api Error";
                _response.IsValid = true;
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));
                return(Ok(new ServerResponse
                {
                    HasSucceeded = true,
                    Message = StatusMessages.ValidMessage,
                    Result = _response
                }));
            }
        }