public void GetFilterCookiesForUserIfNull(IRequestCookieCollection cookies, string username, bool isFromFilterForm, ref string selectedName, ref int?selectedDeliveryMethodId, ref int?selectedProductTypeId)
        {
            if (string.IsNullOrEmpty(selectedName))
            {
                if (!isFromFilterForm)
                {
                    cookies.TryGetValue(username + "supplierSelectedName", out selectedName);
                }
            }

            if (selectedProductTypeId == null || selectedProductTypeId == 0)
            {
                if (!isFromFilterForm)
                {
                    cookies.TryGetValue(username + "supplierSelectedProductType", out string selectedTypeIdStr);
                    selectedProductTypeId = string.IsNullOrEmpty(selectedTypeIdStr)
                        ? null
                        : (int?)int.Parse(selectedTypeIdStr);
                }
            }

            if (selectedDeliveryMethodId == null || selectedDeliveryMethodId == 0)
            {
                if (!isFromFilterForm)
                {
                    cookies.TryGetValue(username + "supplierSelectedDeliveryMethod", out string selectedDeliveryMethodIdStr);
                    selectedDeliveryMethodId = string.IsNullOrEmpty(selectedDeliveryMethodIdStr)
                        ? null
                        : (int?)int.Parse(selectedDeliveryMethodIdStr);
                }
            }
        }
Exemplo n.º 2
0
        public CommonResponse UpdateQuoteDetails(IConfiguration _configuration, string token, string QRFID, string remarks, string enquiryPipeline, bool IsApproveQuote, string Officer, IRequestCookieCollection objCookies, List <ProductAttributeDetails> SessionInfo)
        {
            QuoteSetReq objQuoteRequest = new QuoteSetReq();
            string      emailId         = "";

            objCookies.TryGetValue("EmailId", out emailId);
            emailId = string.IsNullOrEmpty(emailId) ? SessionInfo.Where(a => a.AttributeId == "EmailId").Select(b => b.Value).FirstOrDefault() : emailId;
            string PlacerUser = "";

            objCookies.TryGetValue("UserName", out PlacerUser);
            PlacerUser = string.IsNullOrEmpty(PlacerUser) ? SessionInfo.Where(a => a.AttributeId == "UserName").Select(b => b.Value).FirstOrDefault() : PlacerUser;
            string userId = "";

            objCookies.TryGetValue("VoyagerUser_Id", out userId);
            userId = string.IsNullOrEmpty(userId) ? SessionInfo.Where(a => a.AttributeId == "VoyagerUser_Id").Select(b => b.Value).FirstOrDefault() : userId;
            objQuoteRequest.QRFID           = QRFID;
            objQuoteRequest.Remarks         = remarks;
            objQuoteRequest.PlacerEmail     = emailId;
            objQuoteRequest.PlacerUser      = PlacerUser;
            objQuoteRequest.EnquiryPipeline = enquiryPipeline;
            objQuoteRequest.IsApproveQuote  = IsApproveQuote;
            objQuoteRequest.PlacerUserId    = userId;
            objQuoteRequest.CostingOfficer  = Officer;
            objQuoteRequest.VoyagerUserID   = objCookies["VoyagerUser_Id"] ?? SessionInfo.Where(x => x.AttributeId == "VoyagerUser_Id").Select(b => b.Value).FirstOrDefault();

            CommonResponse objQuoteResponse = coProviders.UpdateQuoteDetails(objQuoteRequest, token).Result;

            return(objQuoteResponse);
        }
Exemplo n.º 3
0
        public void GetFilterCookiesForUserIfNull(IRequestCookieCollection cookies, string username, bool isFromFilterForm, ref string selectedName, ref int?selectedMinOrderQuantity, ref int?selectedMaxOrderQuantity)
        {
            if (string.IsNullOrEmpty(selectedName))
            {
                if (!isFromFilterForm)
                {
                    cookies.TryGetValue(username + "customerSelectedName", out selectedName);
                }
            }

            if (selectedMinOrderQuantity == null)
            {
                if (!isFromFilterForm)
                {
                    cookies.TryGetValue(username + "customerSelectedMinQuantity", out string selectedMinQuantityStr);
                    selectedMinOrderQuantity = string.IsNullOrEmpty(selectedMinQuantityStr)
                        ? null
                        : (int?)int.Parse(selectedMinQuantityStr);
                }
            }

            if (selectedMaxOrderQuantity == null)
            {
                if (!isFromFilterForm)
                {
                    cookies.TryGetValue(username + "customerSelectedMaxQuantity", out string selectedMaxQuantityStr);
                    selectedMaxOrderQuantity = string.IsNullOrEmpty(selectedMaxQuantityStr)
                        ? null
                        : (int?)int.Parse(selectedMaxQuantityStr);
                }
            }
        }
Exemplo n.º 4
0
        public void GetFilterCookiesForUserIfNull(IRequestCookieCollection cookies, string username, bool isFromFilterForm, ref string selectedName, ref int?selectedMinPrice, ref int?selectedMaxPrice, ref int?selectedTypeId, ref int?selectedManufacturerId)
        {
            if (string.IsNullOrEmpty(selectedName))
            {
                if (!isFromFilterForm)
                {
                    cookies.TryGetValue(username + "productSelectedName", out selectedName);
                }
            }

            if (selectedMinPrice == null)
            {
                if (!isFromFilterForm)
                {
                    cookies.TryGetValue(username + "productSelectedMinPrice", out string selectedMinPriceStr);
                    selectedMinPrice = string.IsNullOrEmpty(selectedMinPriceStr)
                        ? null
                        : (int?)int.Parse(selectedMinPriceStr);
                }
            }

            if (selectedMaxPrice == null)
            {
                if (!isFromFilterForm)
                {
                    cookies.TryGetValue(username + "productSelectedMaxPrice", out string selectedMaxPriceStr);
                    selectedMaxPrice = string.IsNullOrEmpty(selectedMaxPriceStr)
                        ? null
                        : (int?)int.Parse(selectedMaxPriceStr);
                }
            }

            if (selectedTypeId == null || selectedTypeId == 0)
            {
                if (!isFromFilterForm)
                {
                    cookies.TryGetValue(username + "productSelectedType", out string selectedTypeIdStr);
                    selectedTypeId = string.IsNullOrEmpty(selectedTypeIdStr)
                        ? null
                        : (int?)int.Parse(selectedTypeIdStr);
                }
            }

            if (selectedManufacturerId == null || selectedManufacturerId == 0)
            {
                if (!isFromFilterForm)
                {
                    cookies.TryGetValue(username + "productSelectedManufacturer", out string selectedManufacturerIdStr);
                    selectedManufacturerId = string.IsNullOrEmpty(selectedManufacturerIdStr)
                        ? null
                        : (int?)int.Parse(selectedManufacturerIdStr);
                }
            }
        }
        public static UserData GetUserData(this IRequestCookieCollection cookieCollection, string key)
        {
            string resStr;

            cookieCollection.TryGetValue(key, out resStr);
            return(resStr == null ? default(UserData) : JsonSerializer.Deserialize <UserData>(resStr));
        }
Exemplo n.º 6
0
        public static bool Auth(IRequestCookieCollection Cookies, string RemoteIpAddress, out bool IsConfirm2FA)
        {
            IsConfirm2FA = false;
            if (Cookies.TryGetValue("authSession", out string authSession))
            {
                SqlToMode.SetMode(SqlMode.Read);
                using (var coreDB = Service.Get <CoreDB>())
                {
                    // Поиск сессии
                    if (coreDB.Auth_Sessions.FindItem(i => i.Session == authSession) is AuthSession item)
                    {
                        // Сессия не истекла
                        // IP-адрес совпадает
                        if (item.Expires > DateTime.Now && item.IP == RemoteIpAddress)
                        {
                            // Хеш пароля совпадает с текущем
                            if (item.HashPasswdToRoot == SHA256.Text(PasswdTo.Root + PasswdTo.salt))
                            {
                                IsConfirm2FA = item.Confirm2FA;
                                return(true);
                            }
                        }
                    }
                }
                SqlToMode.SetMode(SqlMode.ReadOrWrite);

                // Защита от перебора пароля по кукам
                LimitLogin.FailCookieAuthorization("authSession", authSession, RemoteIpAddress);
            }

            return(false);
        }
Exemplo n.º 7
0
        /// <inheritdoc />
        public async Task <string> CheckAuthorization(IRequestCookieCollection cookies, CancellationToken cancellationToken)
        {
            if (!cookies.TryGetValue(CookieName, out string cookieGuid))
            {
                return(null);
            }

            if (!Guid.TryParse(cookieGuid, out Guid guid))
            {
                return(null);
            }

            //cleanup
            var now        = DateTimeOffset.Now;
            var everything = await databaseContext.AccessTokenEntries.ToAsyncEnumerable().ToList().ConfigureAwait(false);

            var toRemove = everything.Where(x => x.Expiry < now);

            databaseContext.AccessTokenEntries.RemoveRange(toRemove);
            await databaseContext.Save(cancellationToken).ConfigureAwait(false);

            var entry = everything.Where(x => x.Id == guid && x.Expiry >= now).FirstOrDefault();

            if (entry == default(AccessTokenEntry))
            {
                return(null);
            }

            return(entry.AccessToken);
        }
Exemplo n.º 8
0
        internal static List <KeyValue> ToList(this IRequestCookieCollection obj)
        {
            if (obj == null)
            {
                return(null);
            }

            var list = new List <KeyValue>();

            foreach (var key in obj.Keys)
            {
                if (key != null)
                {
                    if (obj.TryGetValue(key, out string value))
                    {
                        list.Add(new KeyValue(key, value));
                    }
                    else
                    {
                        list.Add(new KeyValue(key, "__ERROR_READING_VALUE__"));
                    }
                }
            }

            return(list);
        }
Exemplo n.º 9
0
        internal static Dictionary <string, string> ToDictionary(this IRequestCookieCollection obj)
        {
            if (obj == null)
            {
                return(null);
            }

            var dic = new Dictionary <string, string>();

            foreach (var key in obj.Keys)
            {
                if (key != null)
                {
                    if (obj.TryGetValue(key, out string value))
                    {
                        dic.Add(key, value);
                    }
                    else
                    {
                        dic.Add(key, "__ERROR_READING_VALUE__");
                    }
                }
            }

            return(dic);
        }
Exemplo n.º 10
0
 public static string?Get(IRequestCookieCollection cookies, string key, string?defaultValue)
 {
     if (cookies.TryGetValue(key, out string cookieVal))
     {
         return(cookieVal);
     }
     return(defaultValue);
 }
 public void GetSortPagingCookiesForUserIfNull(IRequestCookieCollection cookies, string username, ref int?page, ref SortState?sortState)
 {
     if (page == null)
     {
         if (cookies.TryGetValue(username + "positionPage", out string pageStr))
         {
             page = int.Parse(pageStr);
         }
     }
     if (sortState == null)
     {
         if (cookies.TryGetValue(username + "positionSortState", out string sortStateStr))
         {
             sortState = (SortState)Enum.Parse(typeof(SortState), sortStateStr);
         }
     }
 }
Exemplo n.º 12
0
 public static CultureInfo GetDefaultLocalizationCookie(this IRequestCookieCollection cookieCollection)
 {
     if (cookieCollection.TryGetValue(CookieRequestCultureProvider.DefaultCookieName, out string requestCultureName))
     {
         string[] values = ParseLocalizationCookie(requestCultureName);
         return(new CultureInfo(values[LocalizationCurrentUICulture]));
     }
     return(CultureInfo.CurrentUICulture);
 }
        /// <summary>
        /// 获取Cookie
        /// </summary>
        /// <typeparam name="TObject"></typeparam>
        /// <param name="cookies"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static TObject GetCookie <TObject>(this IRequestCookieCollection cookies, string key)
        {
            TObject result = default;

            if (cookies.TryGetValue(key, out string json))
            {
                result = SerializeUtil.FromJson <TObject>(json);
            }
            return(result);
        }
Exemplo n.º 14
0
        public static string GetString(this IRequestCookieCollection cookie, string name)
        {
            var t = cookie.TryGetValue(name, out string value);

            if (t && !value.IsBlank())
            {
                return(Convert.FromBase64String(value).ByteToStr());
            }
            return("");
        }
Exemplo n.º 15
0
        public static T Get <T>(this IRequestCookieCollection request, string key) where T : class
        {
            T result = null;

            if (request.TryGetValue(key, out var obj))
            {
                result = JsonConvert.DeserializeObject <T>(obj);
            }
            return(result);
        }
Exemplo n.º 16
0
 public void GetFilterCookiesForUserIfNull(IRequestCookieCollection cookies, string username, bool isFromFilterForm, ref string selectedName)
 {
     if (string.IsNullOrEmpty(selectedName))
     {
         if (!isFromFilterForm)
         {
             cookies.TryGetValue(username + "employeeSelectedName", out selectedName);
         }
     }
 }
Exemplo n.º 17
0
        public static Task <Session?> GetSession(this IRequestCookieCollection cookies,
                                                 ApplicationDbContext database)
        {
            if (!cookies.TryGetValue(AppInfo.SessionCookieName, out string?session) || string.IsNullOrEmpty(session))
            {
                return(Task.FromResult <Session?>(null));
            }

            return(GetSession(session, database));
        }
Exemplo n.º 18
0
        /// <summary>
        ///   Loads a user from session cookie
        /// </summary>
        /// <param name="cookies">Cookies to read the session cookie from</param>
        /// <param name="database">Where to get users from</param>
        /// <param name="clientAddress">The address the cookies are from (used to track where session is used)</param>
        /// <returns>The user for the session cookie or null and the session that the user was retrieved from</returns>
        /// <exception cref="ArgumentException">If the cookie is malformed</exception>
        public static Task <(User?user, Session?session)> GetUserFromSession(this IRequestCookieCollection cookies,
                                                                             ApplicationDbContext database, IPAddress?clientAddress)
        {
            if (!cookies.TryGetValue(AppInfo.SessionCookieName, out string?session) || string.IsNullOrEmpty(session))
            {
                return(Task.FromResult <(User?, Session?)>((null, null)));
            }

            return(GetUserFromSession(session, database, true, clientAddress));
        }
Exemplo n.º 19
0
 private bool TryGetSessionState(IRequestCookieCollection cookie, out SessionState state)
 {
     state = null;
     if (!cookie.TryGetValue("session_id", out var sessionId) ||
         !cookie.TryGetValue("pass_hash", out var passHash) ||
         !cookie.TryGetValue("user_id", out var userId))
     {
         return(false);
     }
     try
     {
         state = this.authenticator.GetSessionAsync(sessionId, new CancellationToken()).Result;
     }
     catch (AuthenticationException)
     {
         return(false);
     }
     return(state.PasswordHash.Equals(passHash) &&
            state.UserId.Equals(new Guid(userId)));
 }
Exemplo n.º 20
0
 public void GetSortPagingCookiesForUserIfNull(IRequestCookieCollection cookies, string username, bool isFromFilter, ref int?page, ref ViewModels.Customers.SortViewModel.Sort?sortState)
 {
     if (!isFromFilter)
     {
         if (page == null)
         {
             if (cookies.TryGetValue(username + "customerPage", out string pageStr))
             {
                 page = int.Parse(pageStr);
             }
         }
         if (sortState == null)
         {
             if (cookies.TryGetValue(username + "customerSort", out string sortStateStr))
             {
                 sortState = (ViewModels.Customers.SortViewModel.Sort)Enum.Parse(typeof(ViewModels.Customers.SortViewModel.Sort), sortStateStr);
             }
         }
     }
 }
Exemplo n.º 21
0
        /// <summary>
        /// Save a cookie in the response
        /// </summary>
        /// <param name="me"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="lifeTimeDays"></param>
        public static void SetCookie(this HttpContext me, string key, string value, int lifeTimeDays)
        {
            string result = string.Empty;
            IRequestCookieCollection cookies = me.Request?.Cookies;

            if (cookies.TryGetValue(key, out string temp) == true)
            {
                me.DeleteCookie(key);
            }

            me.Response.CreateCookie(key, value, lifeTimeDays);
        }
Exemplo n.º 22
0
        private List <Detail> GetCookieOrderDetails()
        {
            var cookieCartLines = new List <Detail>();

            if (_cookieCollection.TryGetValue(CartCookieKey, out var cartCookieString))
            {
                cartCookieString ??= "[]";
                cookieCartLines = JsonConvert.DeserializeObject <List <Detail> >(cartCookieString);
            }

            return(cookieCartLines);
        }
        private IEnumerable <KeyValuePair <string, string> > GetCookies(IRequestCookieCollection cookies)
        {
            foreach (var cookieName in CookieNames)
            {
                if (!cookies.TryGetValue(cookieName, out var cookieValue))
                {
                    continue;
                }

                yield return(new KeyValuePair <string, string>(cookieName, cookieValue));
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Get a cookie from the request.
        /// </summary>
        /// <param name="me"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetCookie(this HttpContext me, string key)
        {
            string result = string.Empty;
            IRequestCookieCollection cookies = me.Request?.Cookies;

            if (cookies != null)
            {
                cookies.TryGetValue(key, out result);
            }

            return(result);
        }
Exemplo n.º 25
0
        public Task <ExpandoObject> GetCurrentLevel(IRequestCookieCollection cookies)
        {
            cookies.TryGetValue("gameUrl", out var url);

            url = url.ToLower();

            var gameId    = url.Split("gid=")[1];
            var domainUrl = url.Split("gamedetails")[0];

            var currentLevelUrl = $"{domainUrl}GameEngines/Encounter/Play/{gameId}?json=1";

            return(httpHelper.GetCurrentLevel(currentLevelUrl, cookies));
        }
Exemplo n.º 26
0
        private IEnumerable <KeyValuePair <string, string> > GetCookies(IRequestCookieCollection cookies)
        {
            var cookieNames = this.CookieNames;

            if (cookieNames != null)
            {
                foreach (var cookieName in cookieNames)
                {
                    if (cookies.TryGetValue(cookieName, out var cookieValue))
                    {
                        yield return(new KeyValuePair <string, string>(cookieName, cookieValue));
                    }
                }
            }
        }
Exemplo n.º 27
0
        public static bool TryGetValue <TypeOutput>(this IRequestCookieCollection cookie, string key, out TypeOutput @object)
        {
            bool result = cookie.TryGetValue(key, out string value);

            if (result)
            {
                @object = JsonSerializer.Deserialize <TypeOutput>(value);
            }
            else
            {
                @object = default;
            }

            return(result);
        }
Exemplo n.º 28
0
        public IActionResult QRFSummary(string filterByDay = null, string filterByServiceType = null)
        {
            try
            {
                string QRFID = Request.Query["QRFId"];
                QRFSummaryViewModel model = new QRFSummaryViewModel();
                model.QRFID = QRFID;
                model.MenuViewModel.QRFID    = QRFID;
                model.MenuViewModel.MenuName = "Summary";
                model.CurrentDate            = DateTime.Now.ToString("dd MMM yyyy");
                bool   GetStatus = false;
                string username  = "";
                IRequestCookieCollection objCookies = HttpContext.Request.Cookies;
                objCookies.TryGetValue("UserName", out username);
                username       = string.IsNullOrEmpty(username) ? ckUserName : username;
                model.UserName = username;
                #region Get Quote Info By QRFId
                NewQuoteViewModel modelQuote = new NewQuoteViewModel();
                modelQuote.QRFID = QRFID;
                SalesQuoteLibrary quoteLibrary = new SalesQuoteLibrary(_configuration);
                GetStatus = quoteLibrary.GetQRFAgentByQRFId(_configuration, token, ref modelQuote);
                if (GetStatus)
                {
                    model.TourInfoHeaderViewModel = modelQuote.TourInfoHeaderViewModel;
                }

                CompanyOfficerGetRes officerGetRes = new CompanyOfficerGetRes();
                CompanyOfficerGetReq officerGetReq = new CompanyOfficerGetReq();
                officerGetReq.CompanyId = ckUserCompanyId;
                officerGetReq.UserRole  = "Costing Officer";
                officerGetRes           = agentProviders.GetCompanyOfficers(officerGetReq, token).Result;

                model.OfficerList = officerGetRes.ContactDetails;
                var salespipelineres = agentProviders.GetAutomatedSalesPipelineRoles(new SettingsAutomatedGetReq {
                    CompanyId = ckUserCompanyId, QRFId = QRFID, UserRole = officerGetReq.UserRole
                }, token).Result;
                if (!string.IsNullOrEmpty(salespipelineres?.ResponseStatus?.Status))
                {
                    model.Officer = salespipelineres.UserEmailId;
                }
                #endregion
                return(View(model));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 29
0
        private bool TryGetParameterFromCookie(
            IRequestCookieCollection cookies,
            OpenApiParameter parameter,
            [NotNullWhen(true)] out object?result)
        {
            if (this.logger.IsEnabled(LogLevel.Debug))
            {
                this.logger.LogDebug(
                    "Trying to get parameter from cookies for parameter [{parameter}]",
                    parameter.Name);
            }

            if (cookies == null)
            {
                if (this.logger.IsEnabled(LogLevel.Debug))
                {
                    this.logger.LogDebug(
                        "Failed to get parameter from cookies for parameter [{parameter}], cookies are null",
                        parameter.Name);
                }

                result = null;
                return(false);
            }

            if (cookies.TryGetValue(parameter.Name, out string value))
            {
                if (this.logger.IsEnabled(LogLevel.Debug))
                {
                    this.logger.LogDebug(
                        "Got parameter from cookies for parameter [{parameter}]",
                        parameter.Name);
                }

                result = this.ConvertValue(parameter.Schema, value);
                return(true);
            }

            if (this.logger.IsEnabled(LogLevel.Debug))
            {
                this.logger.LogDebug(
                    "Failed to get parameter from cookies for parameter [{parameter}]",
                    parameter.Name);
            }

            result = null;
            return(false);
        }
Exemplo n.º 30
0
        public CookieMessageProvider(
            IRequestCookieCollection request,
            IResponseCookies response)
        {
            this.response = response;

            string value;

            if (request.TryGetValue(cookieKey, out value))
            {
                if (value != null)
                {
                    messages = JsonConvert.DeserializeObject(value, jsonSerializerSettings);
                }
            }
        }