Esempio n. 1
0
        private void ConfigureJwtAuthServer(IServiceCollection services)
        {
            services.AddScoped <IAccountService, AccountService>();
            services.AddScoped <IAuthorizationService, AuthorizationService>();

            services.AddScoped <JsonWebTokenHandler>();

            var tokenValidationParameters = new TokenValidationParameters
            {
                ValidateIssuer           = true,
                ValidateAudience         = true,
                ValidateLifetime         = true,
                ValidateIssuerSigningKey = true,
                ValidIssuer      = _configuration["jwt:issuer"],
                ValidAudience    = _configuration["jwt:audience"],
                IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["securityKey"])),
                ClockSkew        = TimeSpan.Zero,
            };

            services.AddAuthentication(c =>
            {
                c.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                c.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(options =>
            {
                _tokenValidationHelper = new TokenValidationHelper();
                options.Events         = new JwtBearerEvents
                {
                    OnTokenValidated = _tokenValidationHelper.ValidationSecurityStamp
                };
                options.TokenValidationParameters = tokenValidationParameters;
            });
        }
Esempio n. 2
0
        public async Task <IActionResult> GetPageFAQ([FromHeader(Name = "Grid-General-Token")] string Token, [FromRoute] string Pagename)
        {
            try
            {
                if (string.IsNullOrEmpty(Pagename))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = StatusMessages.DomainValidationError,
                        IsDomainValidationErrors = true
                    }));
                }

                TokenValidationHelper tokenValidationHelper = new TokenValidationHelper();
                if (!tokenValidationHelper.ValidateGenericToken(Token, _iconfiguration))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = Core.Extensions.EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed),
                        IsDomainValidationErrors = true
                    }));
                }

                FaqPageDataAccess _FaqPageDataAccess = new FaqPageDataAccess(_iconfiguration);

                List <FaqPages> faqresult = await _FaqPageDataAccess.GetPageFAQ(Pagename);

                string faqmessage;

                if (faqresult != null && faqresult.Count > 0)
                {
                    faqmessage = StatusMessages.SuccessMessage;
                }
                else
                {
                    faqmessage = "Faq not found";
                }


                return(Ok(new ServerResponse
                {
                    HasSucceeded = true,
                    Message = faqmessage,
                    Result = faqresult
                }));
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = StatusMessages.ServerError,
                    IsDomainValidationErrors = false
                }));
            }
        }
Esempio n. 3
0
 public CheckController(ApplicationContext applicationContext, UserManager <User> userManager, TokenValidationHelper helper, GenerateErrorHelper errorHelper)
 {
     _applicationContext = applicationContext;
     _userManager        = userManager;
     _helper             = helper;
     _errorHelper        = errorHelper;
 }
Esempio n. 4
0
 public CashboxesController(TokenValidationHelper helper, GenerateErrorHelper errorHelper, UserManager <User> userManager,
                            ApplicationContext applicationContext)
 {
     _validationHelper   = helper;
     _errorHelper        = errorHelper;
     _userManager        = userManager;
     _applicationContext = applicationContext;
 }
Esempio n. 5
0
 public Report(ApplicationContext applicationContext, UserManager <User> userManager,
               ILoggerFactory loggerFactory, TokenValidationHelper helper, GenerateErrorHelper errorHelper)
 {
     _applicationContext = applicationContext;
     _userManager        = userManager;
     _loggerFactory      = loggerFactory;
     _helper             = helper;
     _errorHelper        = errorHelper;
 }
Esempio n. 6
0
        public async Task <IActionResult> GetConfigByType([FromHeader(Name = "Grid-General-Token")] string Token, [FromRoute] string ConfigType)
        {
            try
            {
                if (string.IsNullOrEmpty(ConfigType))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = StatusMessages.DomainValidationError,
                        IsDomainValidationErrors = true
                    }));
                }

                TokenValidationHelper tokenValidationHelper = new TokenValidationHelper();
                if (!tokenValidationHelper.ValidateGenericToken(Token, _iconfiguration))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed),
                        IsDomainValidationErrors = true
                    }));
                }

                DatabaseResponse configResponse = await ConfigHelper.GetPubicValue(ConfigType, _iconfiguration);

                List <Dictionary <string, string> > configList = new List <Dictionary <string, string> >();

                if (configResponse != null && configResponse.ResponseCode == (int)DbReturnValue.RecordExists)
                {
                    configList = (List <Dictionary <string, string> >)configResponse.Results;
                }

                return(Ok(new ServerResponse
                {
                    HasSucceeded = true,
                    Message = configResponse.ResponseCode == (int)DbReturnValue.NotExists ? EnumExtensions.GetDescription(DbReturnValue.NotExists) : EnumExtensions.GetDescription(DbReturnValue.RecordExists),
                    Result = configList
                }));
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = StatusMessages.ServerError,
                    IsDomainValidationErrors = false
                }));
            }
        }
Esempio n. 7
0
        public async Task <IActionResult> ValidateRoadShowCode([FromHeader(Name = "Grid-General-Token")] string Token, [FromRoute] string rscode)
        {
            try
            {
                TokenValidationHelper tokenValidationHelper = new TokenValidationHelper();
                if (!tokenValidationHelper.ValidateGenericToken(Token, _iconfiguration))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = Core.Extensions.EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed),
                        IsDomainValidationErrors = true
                    }));
                }


                ValidationDataAccess _validateDataAccess = new ValidationDataAccess(_iconfiguration);
                DatabaseResponse     response            = await _validateDataAccess.ValidateUserCode(rscode);

                if (response.ResponseCode == (int)DbReturnValue.RecordExists)
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = true,
                        Message = StatusMessages.ValidMessage,
                        ReturnedObject = response.Results
                    }));
                }
                else
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = StatusMessages.InvalidMessage,
                        ReturnedObject = response.Results
                    }));
                }
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = StatusMessages.ServerError,
                    IsDomainValidationErrors = false
                }));
            }
        }
Esempio n. 8
0
        public IActionResult NRICTypeValidation([FromHeader(Name = "Grid-General-Token")] string Token, [FromBody] NRIC IDDetails)
        {
            string _warningmsg = "";

            try
            {
                TokenValidationHelper tokenValidationHelper = new TokenValidationHelper();
                if (!tokenValidationHelper.ValidateGenericToken(Token, _iconfiguration))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = Core.Extensions.EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed),
                        IsDomainValidationErrors = true
                    }));
                }

                EmailValidationHelper _helper = new EmailValidationHelper();
                if (_helper.NRICValidation(IDDetails.IDType, IDDetails.IDNumber, out _warningmsg))
                {
                    return(Ok(new ServerResponse
                    {
                        HasSucceeded = true,
                        Message = StatusMessages.ValidMessage
                    }));
                }
                else
                {
                    LogInfo.Warning("NRIC Validation: " + IDDetails.IDType + "_" + _warningmsg);
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = StatusMessages.InvalidMessage,
                        IsDomainValidationErrors = false
                    }));
                }
            }

            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = (_warningmsg == "" ? StatusMessages.ServerError : StatusMessages.InvalidMessage),
                    IsDomainValidationErrors = false
                }));
            }
        }
Esempio n. 9
0
        public async Task <IActionResult> BannerDetails([FromHeader(Name = "Grid-General-Token")] string Token, [FromBody] BannerDetailsRequest request)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = StatusMessages.DomainValidationError,
                        IsDomainValidationErrors = true
                    }));
                }

                TokenValidationHelper tokenValidationHelper = new TokenValidationHelper();
                if (!tokenValidationHelper.ValidateGenericToken(Token, _iconfiguration))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed),
                        IsDomainValidationErrors = true
                    }));
                }

                BannerDataAccess _bannerAccess = new BannerDataAccess(_iconfiguration);

                return(Ok(new ServerResponse
                {
                    HasSucceeded = true,
                    Message = StatusMessages.SuccessMessage,
                    Result = await _bannerAccess.GetBannerDetails(request)
                }));
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = StatusMessages.ServerError,
                    IsDomainValidationErrors = false
                }));
            }
        }
Esempio n. 10
0
        public async Task <IActionResult> GetGenericConfigValue([FromHeader(Name = "Grid-General-Token")] string Token, [FromRoute] string ConfigKey)
        {
            try
            {
                if (string.IsNullOrEmpty(ConfigKey))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = StatusMessages.DomainValidationError,
                        IsDomainValidationErrors = true
                    }));
                }
                TokenValidationHelper tokenValidationHelper = new TokenValidationHelper();
                if (!tokenValidationHelper.ValidateGenericToken(Token, _iconfiguration))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed),
                        IsDomainValidationErrors = true
                    }));
                }

                ConfigDataAccess _configAccess = new ConfigDataAccess(_iconfiguration);

                return(Ok(new ServerResponse
                {
                    HasSucceeded = true,
                    Message = StatusMessages.SuccessMessage,
                    Result = await _configAccess.GetConfigValue(ConfigKey)
                }));
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = StatusMessages.ServerError,
                    IsDomainValidationErrors = false
                }));
            }
        }
Esempio n. 11
0
        public async Task <IActionResult> GetAdminLoginAuthentication([FromHeader(Name = "Grid-General-Token")] string Token, [FromBody] AdminUserLoginRequest userdetails)
        {
            try
            {
                if ((string.IsNullOrEmpty(userdetails.Email)) || (string.IsNullOrEmpty(userdetails.Password)))
                {
                    LogInfo.Warning(StatusMessages.MissingRequiredFields);
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = StatusMessages.MissingRequiredFields,
                        IsDomainValidationErrors = true
                    }));
                }

                TokenValidationHelper tokenValidationHelper = new TokenValidationHelper();
                if (!tokenValidationHelper.ValidateGenericToken(Token, _iconfiguration))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed),
                        IsDomainValidationErrors = true
                    }));
                }

                AdminUsersDataAccess _AdminUsersDataAccess = new AdminUsersDataAccess(_iconfiguration);

                DatabaseResponse response = await _AdminUsersDataAccess.GetLoginAuthentication(userdetails);

                if (response.ResponseCode == ((int)DbReturnValue.EmailNotExists))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.EmailNotExists),
                        IsDomainValidationErrors = true
                    }));
                }
                else if (response.ResponseCode == ((int)DbReturnValue.PasswordIncorrect))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.PasswordIncorrect),
                        IsDomainValidationErrors = true
                    }));
                }

                else if (response.ResponseCode == ((int)DbReturnValue.AccountDeactivated))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.AccountDeactivated),
                        IsDomainValidationErrors = true
                    }));
                }

                else if (response.ResponseCode == ((int)DbReturnValue.AuthSuccess))
                {
                    //Authentication success

                    var adminuser = new AdminUsers();

                    adminuser = (AdminUsers)response.Results;

                    var tokenHandler = new JwtSecurityTokenHandler();

                    var key = Encoding.ASCII.GetBytes("stratagile grid adminuser signin jwt hashing secret");

                    DatabaseResponse configResponse = ConfigHelper.GetValueByKey(ConfigKeys.CustomerTokenExpiryInDays.ToString(), _iconfiguration);

                    int expiryDay = 0;

                    if (configResponse.ResponseCode == (int)DbReturnValue.RecordExists)
                    {
                        expiryDay = int.Parse(configResponse.Results.ToString());
                    }

                    var tokenDescriptor = new SecurityTokenDescriptor
                    {
                        Subject = new ClaimsIdentity(new Claim[]
                        {
                            new Claim(ClaimTypes.Name, adminuser.AdminUserID.ToString())
                        }),

                        Expires = DateTime.Now.AddDays(expiryDay), //  need to check with business needs

                        SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
                    };

                    var token = tokenHandler.CreateToken(tokenDescriptor);

                    var tokenString = tokenHandler.WriteToken(token);

                    DatabaseResponse tokenResponse = new DatabaseResponse();

                    tokenResponse = await _AdminUsersDataAccess.LogAdminUserToken(adminuser.AdminUserID, tokenString);

                    // return basic user info (without password) and token to store client side
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = true,
                        Message = EnumExtensions.GetDescription(DbReturnValue.AuthSuccess),
                        ReturnedObject = new LoggedInPrinciple
                        {
                            AdminUser = adminuser,
                            IsAuthenticated = true,
                            Token = tokenString
                        }
                    }
                              ));
                }

                else
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.ReasonUnknown),
                        IsDomainValidationErrors = true
                    }));
                }
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = StatusMessages.ServerError,
                    IsDomainValidationErrors = false
                }));
            }
        }
Esempio n. 12
0
        public async Task <IActionResult> Authenticate([FromHeader(Name = "Grid-General-Token")] string Token, [FromBody] LoginDto loginRequest)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    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 = Core.Extensions.EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed),
                        IsDomainValidationErrors = true
                    }));
                }

                AccountDataAccess _AccountAccess = new AccountDataAccess(_iconfiguration);

                DatabaseResponse response = await _AccountAccess.AuthenticateCustomer(loginRequest);

                if (response.ResponseCode == ((int)DbReturnValue.EmailNotExists))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.EmailNotExists),
                        IsDomainValidationErrors = true
                    }));
                }
                else if (response.ResponseCode == ((int)DbReturnValue.AccountIsLocked))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.AccountIsLocked),
                        IsDomainValidationErrors = true
                    }));
                }
                else if (response.ResponseCode == ((int)DbReturnValue.AccountDeactivated))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.AccountDeactivated),
                        IsDomainValidationErrors = true
                    }));
                }
                else if (response.ResponseCode == ((int)DbReturnValue.PasswordIncorrect))
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.PasswordIncorrect),
                        IsDomainValidationErrors = true
                    }));
                }

                else if (response.ResponseCode == ((int)DbReturnValue.AuthSuccess))
                {
                    //Authentication success

                    var customer = new Customer();

                    customer = (Customer)response.Results;

                    var tokenHandler = new JwtSecurityTokenHandler();

                    var key = Encoding.ASCII.GetBytes("stratagile grid customer signin jwt hashing secret");

                    DatabaseResponse configResponse = ConfigHelper.GetValueByKey(ConfigKeys.CustomerTokenExpiryInDays.ToString(), _iconfiguration);

                    int expiry = 0;

                    if (configResponse.ResponseCode == (int)DbReturnValue.RecordExists)
                    {
                        expiry = int.Parse(configResponse.Results.ToString());
                    }

                    var tokenDescriptor = new SecurityTokenDescriptor
                    {
                        Subject = new ClaimsIdentity(new Claim[]
                        {
                            new Claim(ClaimTypes.Name, customer.CustomerID.ToString())
                        }),

                        Expires = DateTime.Now.AddDays(expiry),

                        SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
                    };

                    var token = tokenHandler.CreateToken(tokenDescriptor);

                    var tokenString = tokenHandler.WriteToken(token);

                    DatabaseResponse tokenResponse = new DatabaseResponse();

                    tokenResponse = await _AccountAccess.LogCustomerToken(customer.CustomerID, tokenString);

                    // return basic user info (without password) and token to store client side
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = true,
                        Message = EnumExtensions.GetDescription(DbReturnValue.AuthSuccess),
                        ReturnedObject = new LoggedInPrinciple
                        {
                            Customer = customer,
                            IsAuthenticated = true,
                            Token = tokenString
                        }
                    }
                              ));
                }

                else
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.ReasonUnknown),
                        IsDomainValidationErrors = true
                    }));
                }
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = StatusMessages.ServerError,
                    IsDomainValidationErrors = false
                }));
            }
        }
Esempio n. 13
0
        public async Task <IActionResult> UpdateNRICIDDetails([FromHeader(Name = "Grid-General-Token")] string Token, [FromForm] UpdateOrderPersonalIDDetailsPublicRequest request)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Ok(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 = Core.Extensions.EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed),
                        IsDomainValidationErrors = true
                    }));
                }

                CommonDataAccess commonDataAccess = new CommonDataAccess(_iconfiguration);
                var tokenResult = await commonDataAccess.ValidateVerificationToken(request.RequestToken);

                if (tokenResult.ResponseCode != (int)DbReturnValue.RecordExists)
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.RequestTokenExpired),
                        IsDomainValidationErrors = false
                    }));
                }

                AccountDataAccess _AccountAccess = new AccountDataAccess(_iconfiguration);

                CommonDataAccess _commonDataAccess = new CommonDataAccess(_iconfiguration);

                DatabaseResponse customerResponse = await _commonDataAccess.GetCustomerIdFromOrderId(request.OrderID);

                if (customerResponse.ResponseCode == (int)DbReturnValue.RecordExists)
                {
                    IFormFile frontImage = request.IDImageFront;

                    IFormFile backImage = request.IDImageBack;

                    BSSAPIHelper bsshelper = new BSSAPIHelper();

                    MiscHelper configHelper = new MiscHelper();

                    OrderDetails customerOrderDetails = await _commonDataAccess.GetOrderDetails(request.OrderID);

                    NRICDetailsRequest personalDetails = new NRICDetailsRequest
                    {
                        OrderID            = request.OrderID,
                        IdentityCardNumber = customerOrderDetails.IdentityCardNumber,
                        IdentityCardType   = customerOrderDetails.IdentityCardType,
                        Nationality        = customerOrderDetails.Nationality,
                        NameInNRIC         = customerOrderDetails.Name,
                        DOB    = customerOrderDetails.DOB,
                        Expiry = customerOrderDetails.ExpiryDate,
                    };

                    //process file if uploaded - non null

                    if (frontImage != null && backImage != null)
                    {
                        DatabaseResponse awsConfigResponse = await _commonDataAccess.GetConfiguration(ConfiType.AWS.ToString());

                        if (awsConfigResponse != null && awsConfigResponse.ResponseCode == (int)DbReturnValue.RecordExists)
                        {
                            GridAWSS3Config awsConfig = configHelper.GetGridAwsConfig((List <Dictionary <string, string> >)awsConfigResponse.Results);

                            AmazonS3 s3Helper = new AmazonS3(awsConfig);

                            string fileNameFront = customerOrderDetails.IdentityCardNumber.Substring(1, customerOrderDetails.IdentityCardNumber.Length - 2) + "_Front_" + DateTime.Now.ToString("yyMMddhhmmss") + Path.GetExtension(frontImage.FileName); //Grid_IDNUMBER_yyyymmddhhmmss.extension

                            UploadResponse s3UploadResponse = await s3Helper.UploadFile(frontImage, fileNameFront);

                            if (s3UploadResponse.HasSucceed)
                            {
                                personalDetails.FrontImage = awsConfig.AWSEndPoint + s3UploadResponse.FileName;
                            }
                            else
                            {
                                LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.S3UploadFailed));
                            }

                            string fileNameBack = customerOrderDetails.IdentityCardNumber.Substring(1, customerOrderDetails.IdentityCardNumber.Length - 2) + "_Back_" + DateTime.Now.ToString("yyMMddhhmmss") + Path.GetExtension(frontImage.FileName); //Grid_IDNUMBER_yyyymmddhhmmss.extension

                            s3UploadResponse = await s3Helper.UploadFile(backImage, fileNameBack);

                            if (s3UploadResponse.HasSucceed)
                            {
                                personalDetails.BackImage = awsConfig.AWSEndPoint + s3UploadResponse.FileName;
                            }
                            else
                            {
                                LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.S3UploadFailed));
                            }
                        }
                        else
                        {
                            // unable to get aws config
                            LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.FailedToGetConfiguration));
                        }
                    }    //file

                    //update ID ReUpload details
                    DatabaseResponse updateNRICResponse = await _commonDataAccess.UpdateNRICDetails(null, 0, personalDetails);

                    if (updateNRICResponse.ResponseCode == (int)DbReturnValue.UpdateSuccess)
                    {
                        DatabaseResponse updateTokenStatus = await _commonDataAccess.UpdateTokenForVerificationRequests(request.OrderID);

                        // EmailResponse emailResponse =  (EmailResponse)updateNRICResponse.Results;

                        // string emailStatus=  await SendAdminEmailNotificationOnIDReUpload(emailResponse.Email, emailResponse.OrderNumber);

                        return(Ok(new OperationResponse
                        {
                            HasSucceeded = true,
                            Message = EnumExtensions.GetDescription(DbReturnValue.UpdateSuccess),
                            IsDomainValidationErrors = false
                        }));
                    }
                    else if (updateNRICResponse.ResponseCode == (int)DbReturnValue.UpdateSuccessSendEmail)
                    {
                        DatabaseResponse updateTokenStatus = await _commonDataAccess.UpdateTokenForVerificationRequests(request.OrderID);

                        //  EmailResponse emailResponse = (EmailResponse)updateNRICResponse.Results;

                        //  string emailStatus = await SendAdminEmailNotificationOnIDReUpload(emailResponse.Email, emailResponse.OrderNumber);

                        // LogInfo.Warning(EnumExtensions.GetDescription(DbReturnValue.UpdateSuccessSendEmail) + "for " + request.OrderID + "Order");

                        return(Ok(new OperationResponse
                        {
                            HasSucceeded = true,
                            Message = EnumExtensions.GetDescription(DbReturnValue.UpdateSuccessSendEmail),
                            IsDomainValidationErrors = false
                        }));
                    }

                    else if (updateNRICResponse.ResponseCode == (int)DbReturnValue.NotExists)
                    {
                        LogInfo.Warning(EnumExtensions.GetDescription(DbReturnValue.NotExists) + " " + EnumExtensions.GetDescription(CommonErrors.ImageAlreadyUploaded) + " Order" + request.OrderID);
                        return(Ok(new OperationResponse
                        {
                            HasSucceeded = false,
                            Message = EnumExtensions.GetDescription(CommonErrors.ImageAlreadyUploaded),
                            IsDomainValidationErrors = false
                        }));
                    }
                    else
                    {
                        LogInfo.Warning(EnumExtensions.GetDescription(DbReturnValue.UpdationFailed));
                        return(Ok(new OperationResponse
                        {
                            HasSucceeded = false,
                            Message = EnumExtensions.GetDescription(DbReturnValue.UpdationFailed),
                            IsDomainValidationErrors = false
                        }));
                    }
                }

                else
                {
                    // failed to locate customer
                    LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.FailedToGetCustomer));
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(CommonErrors.FailedToGetCustomer),
                        IsDomainValidationErrors = false
                    }));
                }
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = StatusMessages.ServerError,
                    IsDomainValidationErrors = false
                }));
            }
        }
Esempio n. 14
0
        public async Task <IActionResult> ResetPassword([FromHeader(Name = "Grid-General-Token")] string Token, [FromBody] ResetPassword passwordResetRequest)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Ok(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 = Core.Extensions.EnumExtensions.GetDescription(DbReturnValue.TokenAuthFailed),
                        IsDomainValidationErrors = true
                    }));
                }

                AccountDataAccess _accountDataAccess = new AccountDataAccess(_iconfiguration);
                if (!Regex.Match(new Base64Helper().base64Decode(passwordResetRequest.NewPassword), @"(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}").Success)
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = DbReturnValue.PasswordPolicyError.GetDescription(),
                        IsDomainValidationErrors = false
                    }));
                }
                DatabaseResponse response = await _accountDataAccess.ResetPassword(passwordResetRequest);

                if (response.ResponseCode == ((int)DbReturnValue.NotExists))
                { //102
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(CommonErrors.TokenNotExists),
                        IsDomainValidationErrors = true
                    }));
                }

                if (response.ResponseCode == ((int)DbReturnValue.UpdateSuccess))
                { //101
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = true,
                        Message = EnumExtensions.GetDescription(CommonErrors.PasswordResetSuccess),
                        IsDomainValidationErrors = false
                    }));
                }

                if (response.ResponseCode == ((int)DbReturnValue.UpdationFailed))
                {//106
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(CommonErrors.PasswordResetFailed),
                        IsDomainValidationErrors = true
                    }));
                }
                else
                {    //125
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.ResetPasswordTokenExpired),
                        IsDomainValidationErrors = false,
                    }));
                }
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = StatusMessages.ServerError,
                    IsDomainValidationErrors = false
                }));
            }
        }
Esempio n. 15
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
                }));
            }
        }