示例#1
0
        public void TestLocale_InvalidLanguageCodeNullCountryCode_ShouldReturnSameLanguageCodeLowerCase()
        {
            string languageCode = "XY";
            string countryCode  = null;

            string newLocale = TranslationUtils.Locale(languageCode, countryCode);

            Assert.AreEqual(newLocale, languageCode.ToLower(),
                            "Invalid language code returned. Expected was the input language code");
        }
示例#2
0
        public void TestLocale_NullLanguageCodeInvalidCountryCode_ShouldReturnSameCountryCodeUpperCase()
        {
            string languageCode = null;
            string countryCode  = "xy";

            string newLocale = TranslationUtils.Locale(languageCode, countryCode);

            Assert.AreEqual(newLocale, countryCode.ToUpper(),
                            "Invalid country code returned. Expected was the input country code");
        }
示例#3
0
        public GetProfileResponse GetCustomerProfileforHPIDTEST(UserAuthenticationInterchange UserAuthInterchange, TokenDetails sessionTokenDetails, bool RetainOldValues, APIMethods apiRetainOldValues)
        {
            GetProfileResponse response          = new GetProfileResponse();
            AccessCredentials  accessCredentials = new AccessCredentials();

            accessCredentials.AppVersion = "1.0.0.0";
            accessCredentials.CallerId   = "TESTLOGIN1.0.0.0";
            accessCredentials.LoginDate  = DateTime.UtcNow;
            response.Credentials         = accessCredentials;

            CustomerProfile customerProfile = new CustomerProfile();
            CustomerData    customerData    = new CustomerData()
            {
                Locale      = TranslationUtils.Locale(UserAuthInterchange.LanguageCode, UserAuthInterchange.CountryCode), ActiveHealth = true, Country = "US",
                CompanyName = "HP", DisplayName = "Ramdeo Angh", EmailAddress = "*****@*****.**",
                FirstName   = "Ramdeo", LastName = "Angh"
            };

            customerProfile.Country      = customerData.Country;
            customerProfile.CompanyName  = customerData.CompanyName;
            customerProfile.DisplayName  = customerData.DisplayName;
            customerProfile.EmailAddress = customerData.EmailAddress;
            customerProfile.ActiveHealth = customerData.ActiveHealth;
            customerProfile.Locale       = customerData.Locale;
            customerProfile.FirstName    = customerData.FirstName;
            customerProfile.LastName     = customerData.LastName;



            response.CustomerProfileObject = customerProfile;
            response.LoginDate             = DateTime.UtcNow;

            sessionTokenDetails                  = new TokenDetails();
            sessionTokenDetails.AccessToken      = (Guid.NewGuid().ToString());
            sessionTokenDetails.RefreshToken     = (Guid.NewGuid().ToString());
            sessionTokenDetails.RefreshTokenType = (int)TokenScopeType.userLogin;


            TokenDetails sessionToken = sessionTokenDetails;


            // try to get HPID profile with existing session token
            CustomerIds idS = new CustomerIds();

            idS.HPIDid = "INNOVATIONPORTAL12345!@#$%";

            return(GetCustomerProfileFromHPIDAndDatabase(response, UserAuthInterchange, sessionToken, idS, RetainOldValues, apiRetainOldValues));
        }
示例#4
0
        public EasCustomerProfile GetHPProfile(int UserID, string Token, string CallerId, string LanguageCode, string CountryCode, string SessionToken)
        {
            EasCustomerProfile profile = new EasCustomerProfile(UserID);

            GetProfileResponse profileResponse = new GetProfileResponse();

            GetHPProfile(ref profileResponse, UserID, Token, CallerId, LanguageCode, CountryCode, SessionToken, TokenScopeType.apiProfileGetCall);

            if (profileResponse.ErrorList.Count == 0 && profileResponse.CustomerProfileObject != null)
            {
                profile.CallerId     = CallerId;
                profile.TokenMD5     = SessionToken;
                profile.FirstName    = !string.IsNullOrEmpty(profileResponse?.CustomerProfileObject?.FirstName) ? profileResponse.CustomerProfileObject.FirstName : string.Empty;
                profile.LastName     = !string.IsNullOrEmpty(profileResponse?.CustomerProfileObject?.LastName) ? profileResponse.CustomerProfileObject.LastName : string.Empty;
                profile.EmailAddress = !string.IsNullOrEmpty(profileResponse?.CustomerProfileObject?.EmailAddress) ? profileResponse.CustomerProfileObject.EmailAddress : string.Empty;
                profile.CountryCode  = !string.IsNullOrEmpty(profileResponse?.CustomerProfileObject?.Country) ? profileResponse.CustomerProfileObject.Country : SettingRepository.Get <string>("EASDeafaultPurchaseCountryCode");
                profile.LanguageCode = !string.IsNullOrEmpty(profileResponse?.CustomerProfileObject?.Language) ? profileResponse.CustomerProfileObject.Language : "en";
                profile.Locale       = TranslationUtils.Locale(LanguageCode, CountryCode);
            }

            return(profile);
        }
示例#5
0
        private GetProfileResponse GetCustomerProfileFromHPIDAndDatabase(GetProfileResponse response, UserAuthenticationInterchange hppAuthInterchange, TokenDetails sessionToken, CustomerIds idS, bool RetainOldValues, APIMethods apiRetainOldValues)
        {
            User profile = null;
            List <RoleMapping> roleMappings = null;

            try
            {
                // check is done based on profile, customerId is also generated for a new profile
                bool IsNewCustomer = false;

                RequestFindOrInsertHPIDProfile requestFindOrInsertHPID = new RequestFindOrInsertHPIDProfile();
                requestFindOrInsertHPID.Locale =
                    string.IsNullOrEmpty(response?.CustomerProfileObject?.Locale)?TranslationUtils.Locale(hppAuthInterchange.LanguageCode, hppAuthInterchange.CountryCode):response?.CustomerProfileObject?.Locale;
                requestFindOrInsertHPID.HPIDprofileId      = idS.HPIDid;
                requestFindOrInsertHPID.HPPprofileId       = idS.HPPid;
                requestFindOrInsertHPID.tokenDetails       = sessionToken;
                requestFindOrInsertHPID.clientId           = hppAuthInterchange.ClientId;
                requestFindOrInsertHPID.apiRetainOldValues = apiRetainOldValues;
                requestFindOrInsertHPID.EmailAddrees       = response?.CustomerProfileObject?.EmailAddress;
                requestFindOrInsertHPID.CompanyName        = response?.CustomerProfileObject?.CompanyName;
                requestFindOrInsertHPID.ActiveHealth       = response.CustomerProfileObject.ActiveHealth;
                requestFindOrInsertHPID.FirstName          = response?.CustomerProfileObject?.FirstName;
                requestFindOrInsertHPID.LastName           = response.CustomerProfileObject.LastName;



                profile = userUtils.FindOrInsertHPIDProfile(response, requestFindOrInsertHPID, out IsNewCustomer);

                if (response.ErrorList.Count > 0)
                {
                    return(response);
                }

                if (profile.RoleMappings.Count == 0)
                {
                    roleMappings = roleUtils.InsertRoleMapping(response, profile.UserId);
                }
                else
                {
                    roleMappings = profile.RoleMappings.ToList();
                }


                hppAuthInterchange.UserId = Convert.ToInt32(profile.UserId);
                hppAuthInterchange.Token  = sessionToken.AccessToken;
                hppAuthInterchange.IsHPID = true;



                // Register profile & session token in database
                customerUtils.InsertOrUpdateHPPToken(response, (UserAuthentication)hppAuthInterchange, RetainOldValues);

                List <int>       roleids   = roleMappings.Select(r => r.RoleId).ToList();
                List <UserRoles> userRoles = new List <UserRoles>();

                RESTAPIGetRolesResponse rolesResponse = new RESTAPIGetRolesResponse();

                statusUtils.GetRoles(rolesResponse);

                if (rolesResponse.RolesList.Count != 0)
                {
                    var rolResponseList = rolesResponse.RolesList.Where(r => roleids.Contains(r.RoleId)).ToList();
                    foreach (var roles in rolResponseList)
                    {
                        userRoles.Add(new UserRoles()
                        {
                            Id = roles.RoleId, Name = roles.RoleName
                        });
                    }
                }


                response.Credentials = new AccessCredentials()
                {
                    UserID       = Convert.ToInt32(profile.UserId),
                    SessionToken = QueryUtils.GetMD5(sessionToken.AccessToken),
                    CallerId     = hppAuthInterchange.CallerId,
                    Token        = sessionToken.AccessToken,
                    Roles        = userRoles
                };

                response = GetProfileDataFromDatabase(response, profile);
                response.CustomerProfileObject.IsNewCustomer = IsNewCustomer;
                response.LoginDate = hppAuthInterchange.LoginDate;
            }
            catch (Exception ex)
            {
                response.ErrorList.Add(new Fault("GetCustomerProfileFailed", ex.Message));
            }

            return(response);
        }
示例#6
0
        public void Translation(HttpActionContext actionContext)
        {
            try
            {
                RESTAPIControllerBase baseController = actionContext.ControllerContext.Controller as RESTAPIControllerBase;

                //Return if no-rest api filter.
                if (baseController == null)
                {
                    return;
                }
                string CountryCode  = TranslationUtils.DefaultCountryCode;
                string LanguageCode = TranslationUtils.DefaultLanguageCode;

                if (baseController.CountryCode != null || baseController.LanguageCode != null)
                {
                    //Get CountryCode, LanguageCode
                    CountryCode  = baseController.CountryCode;
                    LanguageCode = baseController.LanguageCode;
                }

                //We only modify for non-test http method.
                if (actionContext.Request.Method != HttpMethod.Options)
                {
                    ObjectContent content  = actionContext?.Response?.Content as ObjectContent;
                    ResponseBase  response = content?.Value as ResponseBase;

                    //Check if response has any error
                    if (response != null && response.ErrorList.Count > 0)
                    {
                        //Get translation for fault item.
                        foreach (Fault item in response.ErrorList)
                        {
                            item.StatusText = string.Format($"ErrorCategory_{item.ErrorCategory.ToString()}", TranslationUtils.Locale(LanguageCode, CountryCode));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(string.Format($"ErrorCodeTranslationFilter | Error occured while localization of error code.\n{ex.ToString()}"));
            }
        }
        public static void ExecuteLogout(this AuthorizeAttribute authAttribute, HttpActionContext actionContext, ResponseBase r, Controllers.RESTAPIControllerBase Controller)
        {
            Fault f = new Fault(Responses.Faults.HPIDSessionTimeout, null);

            f.StatusText = string.Format($"ErrorCategory_{f.ErrorCategory.ToString()}", TranslationUtils.Locale(Controller.LanguageCode, Controller.CountryCode));
            r.ErrorList.Add(f);

            if (SettingRepository.Get <bool>("LogoutOnNonAuthorizedRequest", false))
            {
                ICustomerHPIDUtils customerHPIDUtils = DependencyInjector.Get <ICustomerHPIDUtils, CustomerHPIDUtils>();
                customerHPIDUtils.ExecuteLogout(r, Controller.UserID, Controller.SessionToken, Controller.CallerId);
            }
            actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.OK, r, GlobalConfiguration.Configuration);
        }